Skip to content

Commit

Permalink
commenting
Browse files Browse the repository at this point in the history
Also handle a single digit of precision more carefully at the boundary.
  • Loading branch information
dimbleby committed Jun 1, 2022
1 parent a571fa5 commit 664bd51
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
27 changes: 26 additions & 1 deletion src/poetry/core/packages/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,33 @@ def normalize_python_version_markers(disjunction: list[list[tuple[str, str]]]) -
if "*" not in version:
version += ".*"
elif op in ("<=", ">"):
# Make adjustments on encountering versions with less than full
# precision.
#
# Per PEP-508:
# python_version <-> '.'.join(platform.python_version_tuple()[:2])
#
# So for two digits of precision we make the following adjustments:
# - `python_version > "x.y"` requires version >= x.(y+1).anything
# - `python_version <= "x.y"` requires version < x.(y+1).anything
#
# Treatment when we see a single digit of precision is less clear: is
# that even a legitimate marker?
#
# Experiment suggests that pip behaviour is essentially to make a
# lexicographical comparison, for example `python_version > "3"` is
# satisfied by version 3.anything, whereas `python_version <= "3"` is
# satisfied only by version 2.anything.
#
# We achieve the above by fiddling with the operator and version in the
# marker.
parsed_version = Version.parse(version)
if parsed_version.precision == 2:
if parsed_version.precision == 1:
if op == "<=":
op = "<"
elif op == ">":
op = ">="
elif parsed_version.precision == 2:
if op == "<=":
op = "<"
version = parsed_version.next_minor().text
Expand Down
4 changes: 2 additions & 2 deletions tests/packages/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,10 @@ def test_dependency_from_pep_508_should_not_produce_empty_constraints_for_correc

assert dep.name == "pytest-mypy"
assert str(dep.constraint) == "*"
assert dep.python_versions == "<3.11 >3"
assert dep.python_versions == "<3.11 >=3"
assert dep.python_constraint.allows(Version.parse("3.6"))
assert dep.python_constraint.allows(Version.parse("3.10.4"))
assert not dep.python_constraint.allows(Version.parse("3"))
assert dep.python_constraint.allows(Version.parse("3"))
assert dep.python_constraint.allows(Version.parse("3.0.1"))
assert (
str(dep.marker)
Expand Down
4 changes: 2 additions & 2 deletions tests/packages/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def test_convert_markers(
('python_version != "3.6.* "', "!=3.6.*"),
# <, <=, >, >= precision 1
('python_version < "3"', "<3"),
('python_version <= "3"', "<=3"),
('python_version > "3"', ">3"),
('python_version <= "3"', "<3"),
('python_version > "3"', ">=3"),
('python_version >= "3"', ">=3"),
# <, <=, >, >= precision 2
('python_version < "3.6"', "<3.6"),
Expand Down

0 comments on commit 664bd51

Please sign in to comment.