Skip to content

Commit 40b8e96

Browse files
committed
Fix PEP 508 representation of dependency w/o extras
1 parent b0d9086 commit 40b8e96

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

poetry/core/packages/dependency.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ def to_pep_508(self, with_extras=True): # type: (bool) -> str
224224
if not with_extras:
225225
marker = marker.without_extras()
226226

227-
if not marker.is_empty():
227+
# we re-check for any marker here since the without extra marker might
228+
# return an any marker again
229+
if not marker.is_empty() and not marker.is_any():
228230
markers.append(str(marker))
229231

230232
has_extras = "extra" in convert_markers(marker)

tests/packages/test_dependency.py

+15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from poetry.core.packages import Dependency
44
from poetry.core.packages import Package
5+
from poetry.core.packages import dependency_from_pep_508
56

67

78
def test_accepts():
@@ -88,6 +89,10 @@ def test_to_pep_508_in_extras():
8889
result = dependency.to_pep_508()
8990
assert result == 'Django (>=1.23,<2.0); extra == "foo"'
9091

92+
result = dependency.to_pep_508(with_extras=False)
93+
print(dependency.marker)
94+
assert result == "Django (>=1.23,<2.0)"
95+
9196
dependency.in_extras.append("bar")
9297

9398
result = dependency.to_pep_508()
@@ -106,6 +111,16 @@ def test_to_pep_508_in_extras():
106111
)
107112

108113

114+
def test_to_pep_508_in_extras_parsed():
115+
dependency = dependency_from_pep_508('foo[bar] (>=1.23,<2.0) ; extra == "baz"')
116+
117+
result = dependency.to_pep_508()
118+
assert result == 'foo[bar] (>=1.23,<2.0); extra == "baz"'
119+
120+
result = dependency.to_pep_508(with_extras=False)
121+
assert result == "foo[bar] (>=1.23,<2.0)"
122+
123+
109124
def test_to_pep_508_with_single_version_excluded():
110125
dependency = Dependency("foo", "!=1.2.3")
111126

0 commit comments

Comments
 (0)