Skip to content

Commit

Permalink
Resolve invalid python version constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
rusty committed Apr 2, 2021
1 parent 8996496 commit 5167dd4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def to_pep_508(self, with_extras: bool = True) -> str:
def _create_nested_marker(
self, name: str, constraint: Union["BaseConstraint", "VersionTypes"]
) -> str:
from poetry.core.semver.empty_constraint import EmptyConstraint
from poetry.core.semver.version import Version
from poetry.core.semver.version_union import VersionUnion

Expand Down Expand Up @@ -318,6 +319,8 @@ def _create_nested_marker(
name = "python_full_version"

marker = '{} == "{}"'.format(name, constraint.text)
elif isinstance(constraint, EmptyConstraint):
marker = ""
else:
if constraint.min is not None:
min_name = name
Expand Down
9 changes: 9 additions & 0 deletions tests/packages/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,12 @@ def test_dependency_from_pep_508_with_python_full_version_pep440_compatible_rele
assert dep.name == "pathlib2"
assert str(dep.constraint) == "*"
assert dep.python_versions == "~=3.4 || <3"


def test_dependency_from_pep_508_with_invalid_python_version_constraint():
name = 'pytest-mypy ; python_version < "3.10" and python_version > "3"'
dep = Dependency.create_from_pep_508(name)

assert dep.name == "pytest-mypy"
assert str(dep.constraint) == "*"
assert dep.python_versions == "<3.10 >=4"

0 comments on commit 5167dd4

Please sign in to comment.