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

space before semicolon in PEP 508 requirements #510

Merged
merged 1 commit into from
Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,11 @@ def to_pep_508(self, with_extras: bool = True) -> str:
)

if markers:
if self.is_vcs() or self.is_url() or self.is_file():
requirement += " "

if len(markers) > 1:
marker_str = " and ".join(f"({m})" for m in markers)
requirement += f"; {marker_str}"
else:
requirement += f"; {markers[0]}"
marker_str = markers[0]
requirement += f" ; {marker_str}"

return requirement

Expand Down
2 changes: 1 addition & 1 deletion tests/masonry/builders/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_get_metadata_content() -> None:
"cachy[msgpack] (>=0.2.0,<0.3.0)",
"cleo (>=0.6,<0.7)",
(
'pendulum (>=1.4,<2.0); (python_version ~= "2.7" and sys_platform =='
'pendulum (>=1.4,<2.0) ; (python_version ~= "2.7" and sys_platform =='
' "win32" or python_version in "3.4 3.5") and (extra == "time")'
),
]
Expand Down
4 changes: 2 additions & 2 deletions tests/masonry/builders/test_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def test_complete() -> None:
Provides-Extra: time
Requires-Dist: cachy[msgpack] (>=0.2.0,<0.3.0)
Requires-Dist: cleo (>=0.6,<0.7)
Requires-Dist: pendulum (>=1.4,<2.0); (python_version ~= "2.7" and sys_platform == "win32" or python_version in "3.4 3.5") and (extra == "time")
Requires-Dist: pendulum (>=1.4,<2.0) ; (python_version ~= "2.7" and sys_platform == "win32" or python_version in "3.4 3.5") and (extra == "time")
Project-URL: Documentation, https://python-poetry.org/docs
Project-URL: Issue Tracker, https://github.com/python-poetry/poetry/issues
Project-URL: Repository, https://github.com/python-poetry/poetry
Expand Down Expand Up @@ -407,7 +407,7 @@ def test_complete_no_vcs() -> None:
Provides-Extra: time
Requires-Dist: cachy[msgpack] (>=0.2.0,<0.3.0)
Requires-Dist: cleo (>=0.6,<0.7)
Requires-Dist: pendulum (>=1.4,<2.0); (python_version ~= "2.7" and sys_platform == "win32" or python_version in "3.4 3.5") and (extra == "time")
Requires-Dist: pendulum (>=1.4,<2.0) ; (python_version ~= "2.7" and sys_platform == "win32" or python_version in "3.4 3.5") and (extra == "time")
Project-URL: Documentation, https://python-poetry.org/docs
Project-URL: Issue Tracker, https://github.com/python-poetry/poetry/issues
Project-URL: Repository, https://github.com/python-poetry/poetry
Expand Down
4 changes: 2 additions & 2 deletions tests/masonry/builders/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ def test_make_pkg_info_multi_constraints_dependency() -> None:

requires = parsed.get_all("Requires-Dist")
assert requires == [
'pendulum (>=1.5,<2.0); python_version < "3.4"',
'pendulum (>=2.0,<3.0); python_version >= "3.4" and python_version < "4.0"',
'pendulum (>=1.5,<2.0) ; python_version < "3.4"',
'pendulum (>=2.0,<3.0) ; python_version >= "3.4" and python_version < "4.0"',
]


Expand Down
2 changes: 1 addition & 1 deletion tests/masonry/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def test_prepare_metadata_for_build_wheel() -> None:
Provides-Extra: time
Requires-Dist: cachy[msgpack] (>=0.2.0,<0.3.0)
Requires-Dist: cleo (>=0.6,<0.7)
Requires-Dist: pendulum (>=1.4,<2.0); (python_version ~= "2.7" and sys_platform == "win32" or python_version in "3.4 3.5") and (extra == "time")
Requires-Dist: pendulum (>=1.4,<2.0) ; (python_version ~= "2.7" and sys_platform == "win32" or python_version in "3.4 3.5") and (extra == "time")
Project-URL: Documentation, https://python-poetry.org/docs
Project-URL: Issue Tracker, https://github.com/python-poetry/poetry/issues
Project-URL: Repository, https://github.com/python-poetry/poetry
Expand Down
14 changes: 7 additions & 7 deletions tests/packages/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_to_pep_508() -> None:
result = dependency.to_pep_508()
assert (
result
== "Django (>=1.23,<2.0); "
== "Django (>=1.23,<2.0) ; "
'python_version >= "2.7" and python_version < "2.8" '
'or python_version >= "3.6" and python_version < "4.0"'
)
Expand All @@ -56,22 +56,22 @@ def test_to_pep_508_in_extras() -> None:
dependency.in_extras.append(canonicalize_name("foo"))

result = dependency.to_pep_508()
assert result == 'Django (>=1.23,<2.0); extra == "foo"'
assert result == 'Django (>=1.23,<2.0) ; extra == "foo"'

result = dependency.to_pep_508(with_extras=False)
assert result == "Django (>=1.23,<2.0)"

dependency.in_extras.append(canonicalize_name("bar"))

result = dependency.to_pep_508()
assert result == 'Django (>=1.23,<2.0); extra == "foo" or extra == "bar"'
assert result == 'Django (>=1.23,<2.0) ; extra == "foo" or extra == "bar"'

dependency.python_versions = "~2.7 || ^3.6"

result = dependency.to_pep_508()
assert (
result
== "Django (>=1.23,<2.0); "
== "Django (>=1.23,<2.0) ; "
"("
'python_version >= "2.7" and python_version < "2.8" '
'or python_version >= "3.6" and python_version < "4.0"'
Expand All @@ -82,7 +82,7 @@ def test_to_pep_508_in_extras() -> None:
result = dependency.to_pep_508(with_extras=False)
assert (
result
== "Django (>=1.23,<2.0); "
== "Django (>=1.23,<2.0) ; "
'python_version >= "2.7" and python_version < "2.8" '
'or python_version >= "3.6" and python_version < "4.0"'
)
Expand All @@ -94,7 +94,7 @@ def test_to_pep_508_in_extras_parsed() -> None:
)

result = dependency.to_pep_508()
assert result == 'foo[bar,baz] (>=1.23,<2.0); extra == "baz"'
assert result == 'foo[bar,baz] (>=1.23,<2.0) ; extra == "baz"'

result = dependency.to_pep_508(with_extras=False)
assert result == "foo[bar,baz] (>=1.23,<2.0)"
Expand Down Expand Up @@ -130,7 +130,7 @@ def test_to_pep_508_with_patch_python_version(
dependency = Dependency("Django", "^1.23")
dependency.python_versions = python_versions

expected = f"Django (>=1.23,<2.0); {marker}"
expected = f"Django (>=1.23,<2.0) ; {marker}"

assert dependency.to_pep_508() == expected
assert str(dependency.marker) == marker
Expand Down
11 changes: 11 additions & 0 deletions tests/packages/test_directory_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ def test_directory_dependency_pep_508_extras() -> None:
_test_directory_dependency_pep_508("demo", path, requirement, expected)


def test_directory_dependency_pep_508_with_marker() -> None:
path = (
Path(__file__).parent.parent
/ "fixtures"
/ "project_with_multi_constraints_dependency"
)
requirement = f'demo @ file://{path.as_posix()} ; sys_platform == "linux"'
expected = f'demo @ {path.as_uri()} ; sys_platform == "linux"'
_test_directory_dependency_pep_508("demo", path, requirement, expected)


@pytest.mark.parametrize(
"name,path,extras,constraint,expected",
[
Expand Down