diff --git a/poetry/core/packages/dependency.py b/poetry/core/packages/dependency.py index c648a4b6a..1ffe0450b 100644 --- a/poetry/core/packages/dependency.py +++ b/poetry/core/packages/dependency.py @@ -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) diff --git a/tests/packages/test_dependency.py b/tests/packages/test_dependency.py index b903c6fbf..8591e72f5 100644 --- a/tests/packages/test_dependency.py +++ b/tests/packages/test_dependency.py @@ -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(): @@ -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() @@ -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")