Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export: fix directory dependencies #3120

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions poetry/utils/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,16 @@ def _export_requirements_txt(
or dependency.is_directory()
)

if is_direct_reference:
line = requirement
else:
line = "{}=={}".format(package.name, package.version)
if not is_direct_reference:
line += "{}=={}".format(package.name, package.version)
if ";" in requirement:
markers = requirement.split(";", 1)[1].strip()
if markers:
line += "; {}".format(markers)
elif dependency.is_directory(): # pip doesn't support ` @ ` for directories
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think this should be done, because directory dependencies can be PEP 517 dependencies, which means -e will fail.

Copy link
Author

@mrcljx mrcljx Oct 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow. Having a line foo @ some/path in requirements.txt will break pip install with ERROR: Invalid requirement: 'foo @ some/path'? Should the exporter accept a new PEP508 format option besides requirements.txt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what is being discussed in #3121 is a more complete solution. But yes, the comments in #3118 are more current.

Should this be closed in favour of that?

line += requirement.split(" @ ", 1)[1].strip()
else:
line += requirement

if not is_direct_reference and package.source_url:
indexes.add(package.source_url)
Expand Down
10 changes: 5 additions & 5 deletions tests/console/commands/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _export_requirements(tester, poetry):
assert poetry.locker.lock.exists()

expected = """\
foo==1.0.0
-e foo==1.0.0
"""

assert expected == content
Expand All @@ -93,23 +93,23 @@ def test_export_fails_on_invalid_format(tester, do_lock):
def test_export_prints_to_stdout_by_default(tester, do_lock):
tester.execute("--format requirements.txt")
expected = """\
foo==1.0.0
-e foo==1.0.0
"""
assert expected == tester.io.fetch_output()


def test_export_uses_requirements_txt_format_by_default(tester, do_lock):
tester.execute()
expected = """\
foo==1.0.0
-e foo==1.0.0
"""
assert expected == tester.io.fetch_output()


def test_export_includes_extras_by_flag(tester, do_lock):
tester.execute("--format requirements.txt --extras feature_bar")
expected = """\
bar==1.1.0
foo==1.0.0
-e bar==1.1.0
-e foo==1.0.0
"""
assert expected == tester.io.fetch_output()
66 changes: 33 additions & 33 deletions tests/utils/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def test_exporter_can_export_requirements_txt_with_standard_packages(
content = f.read()

expected = """\
bar==4.5.6
foo==1.2.3
-e bar==4.5.6
-e foo==1.2.3
"""

assert expected == content
Expand Down Expand Up @@ -162,9 +162,9 @@ def test_exporter_can_export_requirements_txt_with_standard_packages_and_markers
content = f.read()

expected = """\
bar==4.5.6
baz==7.8.9; sys_platform == "win32"
foo==1.2.3; python_version < "3.7"
-e bar==4.5.6
-e baz==7.8.9; sys_platform == "win32"
-e foo==1.2.3; python_version < "3.7"
"""

assert expected == content
Expand Down Expand Up @@ -208,9 +208,9 @@ def test_exporter_can_export_requirements_txt_with_standard_packages_and_hashes(
content = f.read()

expected = """\
bar==4.5.6 \\
-e bar==4.5.6 \\
--hash=sha256:67890
foo==1.2.3 \\
-e foo==1.2.3 \\
--hash=sha256:12345
"""

Expand Down Expand Up @@ -257,8 +257,8 @@ def test_exporter_can_export_requirements_txt_with_standard_packages_and_hashes_
content = f.read()

expected = """\
bar==4.5.6
foo==1.2.3
-e bar==4.5.6
-e foo==1.2.3
"""

assert expected == content
Expand Down Expand Up @@ -302,7 +302,7 @@ def test_exporter_exports_requirements_txt_without_dev_packages_by_default(
content = f.read()

expected = """\
foo==1.2.3 \\
-e foo==1.2.3 \\
--hash=sha256:12345
"""

Expand Down Expand Up @@ -347,9 +347,9 @@ def test_exporter_exports_requirements_txt_with_dev_packages_if_opted_in(
content = f.read()

expected = """\
bar==4.5.6 \\
-e bar==4.5.6 \\
--hash=sha256:67890
foo==1.2.3 \\
-e foo==1.2.3 \\
--hash=sha256:12345
"""

Expand Down Expand Up @@ -392,7 +392,7 @@ def test_exporter_exports_requirements_txt_without_optional_packages(tmp_dir, po
content = f.read()

expected = """\
foo==1.2.3 \\
-e foo==1.2.3 \\
--hash=sha256:12345
"""

Expand Down Expand Up @@ -452,11 +452,11 @@ def test_exporter_exports_requirements_txt_with_optional_packages_if_opted_in(
content = f.read()

expected = """\
bar==4.5.6 \\
-e bar==4.5.6 \\
--hash=sha256:67890
foo==1.2.3 \\
-e foo==1.2.3 \\
--hash=sha256:12345
spam==0.1.0 \\
-e spam==0.1.0 \\
--hash=sha256:abcde
"""

Expand Down Expand Up @@ -497,7 +497,7 @@ def test_exporter_can_export_requirements_txt_with_git_packages(tmp_dir, poetry)
content = f.read()

expected = """\
foo @ git+https://github.com/foo/foo.git@123456
-e foo @ git+https://github.com/foo/foo.git@123456
"""

assert expected == content
Expand Down Expand Up @@ -540,7 +540,7 @@ def test_exporter_can_export_requirements_txt_with_git_packages_and_markers(
content = f.read()

expected = """\
foo @ git+https://github.com/foo/foo.git@123456 ; python_version < "3.7"
-e foo @ git+https://github.com/foo/foo.git@123456 ; python_version < "3.7"
"""

assert expected == content
Expand Down 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
-e {}/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"
-e {}/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
-e foo @ {}/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"
-e foo @ {}/tests/fixtures/distributions/demo-0.1.0.tar.gz; python_version < "3.7"
""".format(
working_directory.as_uri()
)
Expand Down Expand Up @@ -770,9 +770,9 @@ def test_exporter_exports_requirements_txt_with_legacy_packages(tmp_dir, poetry)
expected = """\
--extra-index-url https://example.com/simple

bar==4.5.6 \\
-e bar==4.5.6 \\
--hash=sha256:67890
foo==1.2.3 \\
-e foo==1.2.3 \\
--hash=sha256:12345
"""

Expand All @@ -782,8 +782,8 @@ def test_exporter_exports_requirements_txt_with_legacy_packages(tmp_dir, poetry)
@pytest.mark.parametrize(
("dev", "expected"),
[
(True, ["bar==1.2.2", "baz==1.2.3", "foo==1.2.1"]),
(False, ["bar==1.2.2", "foo==1.2.1"]),
(True, ["-e bar==1.2.2", "-e baz==1.2.3", "-e foo==1.2.1"]),
(False, ["-e bar==1.2.2", "-e foo==1.2.1"]),
],
)
def test_exporter_exports_requirements_txt_with_dev_extras(
Expand Down Expand Up @@ -908,11 +908,11 @@ def test_exporter_exports_requirements_txt_with_legacy_packages_and_duplicate_so
--extra-index-url https://example.com/simple
--extra-index-url https://foobaz.com/simple

bar==4.5.6 \\
-e bar==4.5.6 \\
--hash=sha256:67890
baz==7.8.9 \\
-e baz==7.8.9 \\
--hash=sha256:24680
foo==1.2.3 \\
-e foo==1.2.3 \\
--hash=sha256:12345
"""

Expand Down Expand Up @@ -979,9 +979,9 @@ def test_exporter_exports_requirements_txt_with_legacy_packages_and_credentials(
expected = """\
--extra-index-url https://foo:bar@example.com/simple

bar==4.5.6 \\
-e bar==4.5.6 \\
--hash=sha256:67890
foo==1.2.3 \\
-e foo==1.2.3 \\
--hash=sha256:12345
"""

Expand Down Expand Up @@ -1022,8 +1022,8 @@ def test_exporter_exports_requirements_txt_to_standard_output(tmp_dir, poetry, c

out, err = capsys.readouterr()
expected = """\
bar==4.5.6
foo==1.2.3
-e bar==4.5.6
-e foo==1.2.3
"""

assert out == expected