Skip to content

Commit

Permalink
Fix PEP 508 representation of dependency w/o extras
Browse files Browse the repository at this point in the history
  • Loading branch information
abn authored and finswimmer committed Oct 17, 2020
1 parent b0d9086 commit fa52260
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ def to_pep_508(self, with_extras=True): # type: (bool) -> str
if not with_extras:
marker = marker.without_extras()

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

has_extras = "extra" in convert_markers(marker)
Expand Down
21 changes: 21 additions & 0 deletions tests/packages/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from poetry.core.packages import Dependency
from poetry.core.packages import Package
from poetry.core.packages import dependency_from_pep_508


def test_accepts():
Expand Down Expand Up @@ -88,6 +89,9 @@ def test_to_pep_508_in_extras():
result = dependency.to_pep_508()
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("bar")

result = dependency.to_pep_508()
Expand All @@ -105,6 +109,23 @@ def test_to_pep_508_in_extras():
'and (extra == "foo" or extra == "bar")'
)

result = dependency.to_pep_508(with_extras=False)
assert result == (
"Django (>=1.23,<2.0); "
'python_version >= "2.7" and python_version < "2.8" '
'or python_version >= "3.6" and python_version < "4.0"'
)


def test_to_pep_508_in_extras_parsed():
dependency = dependency_from_pep_508('foo[bar] (>=1.23,<2.0) ; extra == "baz"')

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

result = dependency.to_pep_508(with_extras=False)
assert result == "foo[bar] (>=1.23,<2.0)"


def test_to_pep_508_with_single_version_excluded():
dependency = Dependency("foo", "!=1.2.3")
Expand Down

0 comments on commit fa52260

Please sign in to comment.