From 934e220c1295e9a4e0d6f3a73a45351c00a6c2ef Mon Sep 17 00:00:00 2001 From: Maximilian Speicher Date: Wed, 7 Oct 2020 22:32:17 +0200 Subject: [PATCH] exporter: use URIs for local dependencies --- poetry/utils/exporter.py | 5 ++++- tests/utils/test_exporter.py | 12 ++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/poetry/utils/exporter.py b/poetry/utils/exporter.py index fda3b10f7b5..8f1ff8a273d 100644 --- a/poetry/utils/exporter.py +++ b/poetry/utils/exporter.py @@ -95,9 +95,12 @@ def _export_requirements_txt( if is_direct_remote_reference: line = requirement elif is_direct_local_reference: - line = requirement.replace("@ ", "@ file://") + dependency_uri = Path(dependency.source_url).resolve().as_uri() + line = "{} @ {}".format(dependency.name, dependency_uri) else: line = "{}=={}".format(package.name, package.version) + + if not is_direct_remote_reference: if ";" in requirement: markers = requirement.split(";", 1)[1].strip() if markers: diff --git a/tests/utils/test_exporter.py b/tests/utils/test_exporter.py index 7f99ecb7190..1ba91697420 100644 --- a/tests/utils/test_exporter.py +++ b/tests/utils/test_exporter.py @@ -582,9 +582,9 @@ def test_exporter_can_export_requirements_txt_with_directory_packages( content = f.read() expected = """\ -foo @ file://{}/tests/fixtures/sample_project +foo @ {}/tests/fixtures/sample_project """.format( - working_directory.as_posix() + working_directory.as_uri() ) assert expected == content @@ -627,9 +627,9 @@ def test_exporter_can_export_requirements_txt_with_directory_packages_and_marker content = f.read() expected = """\ -foo @ file://{}/tests/fixtures/sample_project; python_version < "3.7" +foo @ {}/tests/fixtures/sample_project; python_version < "3.7" """.format( - working_directory.as_posix() + working_directory.as_uri() ) assert expected == content @@ -671,7 +671,7 @@ def test_exporter_can_export_requirements_txt_with_file_packages( content = f.read() expected = """\ -foo @ file://{}/tests/fixtures/distributions/demo-0.1.0.tar.gz +foo @ {}/tests/fixtures/distributions/demo-0.1.0.tar.gz """.format( working_directory.as_uri() ) @@ -716,7 +716,7 @@ def test_exporter_can_export_requirements_txt_with_file_packages_and_markers( content = f.read() expected = """\ -foo @ file://{}/tests/fixtures/distributions/demo-0.1.0.tar.gz; python_version < "3.7" +foo @ {}/tests/fixtures/distributions/demo-0.1.0.tar.gz; python_version < "3.7" """.format( working_directory.as_uri() )