Skip to content

Commit 8d5e5c5

Browse files
sdispaterabn
authored andcommitted
Fix an error when handling single digit Python markers
1 parent f5c6b64 commit 8d5e5c5

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

poetry/core/packages/dependency.py

-17
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ def create_from_pep_508(
409409
path is specified, this is used as the base directory if the identified dependency is
410410
of file or directory type.
411411
"""
412-
from poetry.core.semver.version import Version
413412
from poetry.core.utils.patterns import wheel_file_re
414413
from poetry.core.vcs.git import ParsedUrl
415414
from poetry.core.version.requirements import Requirement
@@ -546,22 +545,6 @@ def create_from_pep_508(
546545
op = ""
547546
elif op == "!=":
548547
version += ".*"
549-
elif op in ("<=", ">"):
550-
parsed_version = Version.parse(version)
551-
if parsed_version.precision == 1:
552-
if op == "<=":
553-
op = "<"
554-
version = parsed_version.next_major().text
555-
elif op == ">":
556-
op = ">="
557-
version = parsed_version.next_major().text
558-
elif parsed_version.precision == 2:
559-
if op == "<=":
560-
op = "<"
561-
version = parsed_version.next_minor().text
562-
elif op == ">":
563-
op = ">="
564-
version = parsed_version.next_minor().text
565548
elif op in ("in", "not in"):
566549
versions = []
567550
for v in re.split("[ ,]+", version):

tests/packages/test_main.py

+18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from poetry.core.packages.dependency import Dependency
2+
from poetry.core.semver.version import Version
23

34

45
def test_dependency_from_pep_508():
@@ -254,3 +255,20 @@ def test_dependency_from_pep_508_with_python_full_version_pep440_compatible_rele
254255
assert dep.name == "pathlib2"
255256
assert str(dep.constraint) == "*"
256257
assert dep.python_versions == "~=3.4 || <3"
258+
259+
260+
def test_dependency_from_pep_508_should_not_produce_empty_constraints_for_correct_markers():
261+
name = 'pytest-mypy; python_implementation != "PyPy" and python_version <= "3.10" and python_version > "3"'
262+
dep = Dependency.create_from_pep_508(name)
263+
264+
assert dep.name == "pytest-mypy"
265+
assert str(dep.constraint) == "*"
266+
assert dep.python_versions == "<=3.10 >3"
267+
assert dep.python_constraint.allows(Version.parse("3.6"))
268+
assert dep.python_constraint.allows(Version.parse("3.10"))
269+
assert not dep.python_constraint.allows(Version.parse("3"))
270+
assert dep.python_constraint.allows(Version.parse("3.0.1"))
271+
assert (
272+
str(dep.marker)
273+
== 'platform_python_implementation != "PyPy" and python_version <= "3.10" and python_version > "3"'
274+
)

0 commit comments

Comments
 (0)