Skip to content

Commit

Permalink
exporter: prepend file for local dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
maxispeicher committed Oct 7, 2020
1 parent 746d741 commit 6fbe88d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
18 changes: 11 additions & 7 deletions poetry/utils/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,27 @@ def _export_requirements_txt(
line += "-e "

requirement = dependency.to_pep_508(with_extras=False)
is_direct_reference = (
dependency.is_vcs()
or dependency.is_url()
or dependency.is_file()
or dependency.is_directory()
is_direct_local_reference = (
dependency.is_file() or dependency.is_directory()
)
is_direct_remote_reference = dependency.is_vcs() or dependency.is_url()

if is_direct_reference:
if is_direct_remote_reference:
line = requirement
elif is_direct_local_reference:
line = requirement.replace("@ ", "@ file://")
else:
line = "{}=={}".format(package.name, package.version)
if ";" in requirement:
markers = requirement.split(";", 1)[1].strip()
if markers:
line += "; {}".format(markers)

if not is_direct_reference and package.source_url:
if (
not is_direct_remote_reference
and not is_direct_local_reference
and package.source_url
):
indexes.add(package.source_url)

if package.files and with_hashes:
Expand Down
8 changes: 4 additions & 4 deletions tests/utils/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ def test_exporter_can_export_requirements_txt_with_directory_packages(
content = f.read()

expected = """\
foo @ {}/tests/fixtures/sample_project
foo @ file://{}/tests/fixtures/sample_project
""".format(
working_directory.as_posix()
)
Expand Down Expand Up @@ -627,7 +627,7 @@ def test_exporter_can_export_requirements_txt_with_directory_packages_and_marker
content = f.read()

expected = """\
foo @ {}/tests/fixtures/sample_project; python_version < "3.7"
foo @ file://{}/tests/fixtures/sample_project; python_version < "3.7"
""".format(
working_directory.as_posix()
)
Expand Down Expand Up @@ -671,7 +671,7 @@ def test_exporter_can_export_requirements_txt_with_file_packages(
content = f.read()

expected = """\
foo @ {}/tests/fixtures/distributions/demo-0.1.0.tar.gz
foo @ file://{}/tests/fixtures/distributions/demo-0.1.0.tar.gz
""".format(
working_directory.as_uri()
)
Expand Down Expand Up @@ -716,7 +716,7 @@ def test_exporter_can_export_requirements_txt_with_file_packages_and_markers(
content = f.read()

expected = """\
foo @ {}/tests/fixtures/distributions/demo-0.1.0.tar.gz; python_version < "3.7"
foo @ file://{}/tests/fixtures/distributions/demo-0.1.0.tar.gz; python_version < "3.7"
""".format(
working_directory.as_uri()
)
Expand Down

0 comments on commit 6fbe88d

Please sign in to comment.