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

Fix PEP 508 representation of dependency w/o extras #102

Merged
merged 1 commit into from
Oct 17, 2020
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
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