Skip to content

Commit

Permalink
Fix an error when handling single digit Python markers
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater authored and abn committed Apr 3, 2021
1 parent f5c6b64 commit 8d5e5c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
17 changes: 0 additions & 17 deletions poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ def create_from_pep_508(
path is specified, this is used as the base directory if the identified dependency is
of file or directory type.
"""
from poetry.core.semver.version import Version
from poetry.core.utils.patterns import wheel_file_re
from poetry.core.vcs.git import ParsedUrl
from poetry.core.version.requirements import Requirement
Expand Down Expand Up @@ -546,22 +545,6 @@ def create_from_pep_508(
op = ""
elif op == "!=":
version += ".*"
elif op in ("<=", ">"):
parsed_version = Version.parse(version)
if parsed_version.precision == 1:
if op == "<=":
op = "<"
version = parsed_version.next_major().text
elif op == ">":
op = ">="
version = parsed_version.next_major().text
elif parsed_version.precision == 2:
if op == "<=":
op = "<"
version = parsed_version.next_minor().text
elif op == ">":
op = ">="
version = parsed_version.next_minor().text
elif op in ("in", "not in"):
versions = []
for v in re.split("[ ,]+", version):
Expand Down
18 changes: 18 additions & 0 deletions tests/packages/test_main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from poetry.core.packages.dependency import Dependency
from poetry.core.semver.version import Version


def test_dependency_from_pep_508():
Expand Down Expand Up @@ -254,3 +255,20 @@ 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_should_not_produce_empty_constraints_for_correct_markers():
name = 'pytest-mypy; python_implementation != "PyPy" and 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 >3"
assert dep.python_constraint.allows(Version.parse("3.6"))
assert dep.python_constraint.allows(Version.parse("3.10"))
assert not dep.python_constraint.allows(Version.parse("3"))
assert dep.python_constraint.allows(Version.parse("3.0.1"))
assert (
str(dep.marker)
== 'platform_python_implementation != "PyPy" and python_version <= "3.10" and python_version > "3"'
)

0 comments on commit 8d5e5c5

Please sign in to comment.