Skip to content

Commit

Permalink
dependency: always add space before semicolon when building PEP 508 s…
Browse files Browse the repository at this point in the history
…trings because it's required sometimes and was missing for directory dependencies
  • Loading branch information
radoering committed Oct 28, 2022
1 parent 653c7ae commit 780ead3
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 18 deletions.
7 changes: 2 additions & 5 deletions src/poetry/core/packages/dependency.py
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
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
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
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
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
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
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

0 comments on commit 780ead3

Please sign in to comment.