Skip to content

Commit

Permalink
rearrangement to appease sonarcloud
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed Jun 1, 2022
1 parent 664bd51 commit fcb9446
Showing 1 changed file with 38 additions and 41 deletions.
79 changes: 38 additions & 41 deletions src/poetry/core/packages/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,52 +309,49 @@ def get_python_constraint_from_marker(


def normalize_python_version_markers(disjunction: list[list[tuple[str, str]]]) -> str:
# We 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.
ors = []
for or_ in disjunction:
ands = []
for op, version in or_:
# Expand python version
if op == "==":
if "*" not in version:
version = "~" + version
op = ""
elif op == "!=":
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.
if op == "==" and "*" not in version:
version = "~" + version
op = ""

elif op == "!=" and "*" not in version:
version += ".*"

elif op == "<=":
parsed_version = Version.parse(version)
if parsed_version.precision < 3:
op = "<"

if parsed_version.precision == 2:
version = parsed_version.next_minor().text

elif op == ">":
parsed_version = Version.parse(version)
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
elif op == ">":
op = ">="
version = parsed_version.next_minor().text
if parsed_version.precision < 3:
op = ">="

if parsed_version.precision == 2:
version = parsed_version.next_minor().text

elif op in ("in", "not in"):
versions = []
for v in re.split("[ ,]+", version):
Expand Down

0 comments on commit fcb9446

Please sign in to comment.