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 an error when handling single digit Python markers #155

Merged
merged 1 commit into from
Apr 3, 2021
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
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"'
)