Skip to content

Commit 45dcad4

Browse files
authored
dependency: always add space before semicolon when building PEP 508 requirement strings (#510)
it's sometimes required, always allowed and was missing for directory dependencies
1 parent 41b6367 commit 45dcad4

File tree

7 files changed

+26
-18
lines changed

7 files changed

+26
-18
lines changed

src/poetry/core/packages/dependency.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,11 @@ def to_pep_508(self, with_extras: bool = True) -> str:
316316
)
317317

318318
if markers:
319-
if self.is_vcs() or self.is_url() or self.is_file():
320-
requirement += " "
321-
322319
if len(markers) > 1:
323320
marker_str = " and ".join(f"({m})" for m in markers)
324-
requirement += f"; {marker_str}"
325321
else:
326-
requirement += f"; {markers[0]}"
322+
marker_str = markers[0]
323+
requirement += f" ; {marker_str}"
327324

328325
return requirement
329326

tests/masonry/builders/test_builder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_get_metadata_content() -> None:
114114
"cachy[msgpack] (>=0.2.0,<0.3.0)",
115115
"cleo (>=0.6,<0.7)",
116116
(
117-
'pendulum (>=1.4,<2.0); (python_version ~= "2.7" and sys_platform =='
117+
'pendulum (>=1.4,<2.0) ; (python_version ~= "2.7" and sys_platform =='
118118
' "win32" or python_version in "3.4 3.5") and (extra == "time")'
119119
),
120120
]

tests/masonry/builders/test_complete.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def test_complete() -> None:
282282
Provides-Extra: time
283283
Requires-Dist: cachy[msgpack] (>=0.2.0,<0.3.0)
284284
Requires-Dist: cleo (>=0.6,<0.7)
285-
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")
285+
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")
286286
Project-URL: Documentation, https://python-poetry.org/docs
287287
Project-URL: Issue Tracker, https://github.com/python-poetry/poetry/issues
288288
Project-URL: Repository, https://github.com/python-poetry/poetry
@@ -407,7 +407,7 @@ def test_complete_no_vcs() -> None:
407407
Provides-Extra: time
408408
Requires-Dist: cachy[msgpack] (>=0.2.0,<0.3.0)
409409
Requires-Dist: cleo (>=0.6,<0.7)
410-
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")
410+
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")
411411
Project-URL: Documentation, https://python-poetry.org/docs
412412
Project-URL: Issue Tracker, https://github.com/python-poetry/poetry/issues
413413
Project-URL: Repository, https://github.com/python-poetry/poetry

tests/masonry/builders/test_sdist.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ def test_make_pkg_info_multi_constraints_dependency() -> None:
207207

208208
requires = parsed.get_all("Requires-Dist")
209209
assert requires == [
210-
'pendulum (>=1.5,<2.0); python_version < "3.4"',
211-
'pendulum (>=2.0,<3.0); python_version >= "3.4" and python_version < "4.0"',
210+
'pendulum (>=1.5,<2.0) ; python_version < "3.4"',
211+
'pendulum (>=2.0,<3.0) ; python_version >= "3.4" and python_version < "4.0"',
212212
]
213213

214214

tests/masonry/test_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def test_prepare_metadata_for_build_wheel() -> None:
171171
Provides-Extra: time
172172
Requires-Dist: cachy[msgpack] (>=0.2.0,<0.3.0)
173173
Requires-Dist: cleo (>=0.6,<0.7)
174-
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")
174+
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")
175175
Project-URL: Documentation, https://python-poetry.org/docs
176176
Project-URL: Issue Tracker, https://github.com/python-poetry/poetry/issues
177177
Project-URL: Repository, https://github.com/python-poetry/poetry

tests/packages/test_dependency.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_to_pep_508() -> None:
3838
result = dependency.to_pep_508()
3939
assert (
4040
result
41-
== "Django (>=1.23,<2.0); "
41+
== "Django (>=1.23,<2.0) ; "
4242
'python_version >= "2.7" and python_version < "2.8" '
4343
'or python_version >= "3.6" and python_version < "4.0"'
4444
)
@@ -56,22 +56,22 @@ def test_to_pep_508_in_extras() -> None:
5656
dependency.in_extras.append(canonicalize_name("foo"))
5757

5858
result = dependency.to_pep_508()
59-
assert result == 'Django (>=1.23,<2.0); extra == "foo"'
59+
assert result == 'Django (>=1.23,<2.0) ; extra == "foo"'
6060

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

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

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

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

7171
result = dependency.to_pep_508()
7272
assert (
7373
result
74-
== "Django (>=1.23,<2.0); "
74+
== "Django (>=1.23,<2.0) ; "
7575
"("
7676
'python_version >= "2.7" and python_version < "2.8" '
7777
'or python_version >= "3.6" and python_version < "4.0"'
@@ -82,7 +82,7 @@ def test_to_pep_508_in_extras() -> None:
8282
result = dependency.to_pep_508(with_extras=False)
8383
assert (
8484
result
85-
== "Django (>=1.23,<2.0); "
85+
== "Django (>=1.23,<2.0) ; "
8686
'python_version >= "2.7" and python_version < "2.8" '
8787
'or python_version >= "3.6" and python_version < "4.0"'
8888
)
@@ -94,7 +94,7 @@ def test_to_pep_508_in_extras_parsed() -> None:
9494
)
9595

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

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

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

135135
assert dependency.to_pep_508() == expected
136136
assert str(dependency.marker) == marker

tests/packages/test_directory_dependency.py

+11
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ def test_directory_dependency_pep_508_extras() -> None:
8181
_test_directory_dependency_pep_508("demo", path, requirement, expected)
8282

8383

84+
def test_directory_dependency_pep_508_with_marker() -> None:
85+
path = (
86+
Path(__file__).parent.parent
87+
/ "fixtures"
88+
/ "project_with_multi_constraints_dependency"
89+
)
90+
requirement = f'demo @ file://{path.as_posix()} ; sys_platform == "linux"'
91+
expected = f'demo @ {path.as_uri()} ; sys_platform == "linux"'
92+
_test_directory_dependency_pep_508("demo", path, requirement, expected)
93+
94+
8495
@pytest.mark.parametrize(
8596
"name,path,extras,constraint,expected",
8697
[

0 commit comments

Comments
 (0)