Skip to content

Commit 6827712

Browse files
committed
String cmp
1 parent ed0d372 commit 6827712

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

src/poetry/core/version/markers.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,10 @@ class SingleMarker(SingleMarkerLike[Union[BaseConstraint, VersionConstraint]]):
322322
}
323323

324324
def __init__(
325-
self, name: str, constraint: str | BaseConstraint | VersionConstraint
325+
self,
326+
name: str,
327+
constraint: str | BaseConstraint | VersionConstraint,
328+
str_cmp: bool = False,
326329
) -> None:
327330
from poetry.core.constraints.generic import (
328331
parse_constraint as parse_generic_constraint,
@@ -345,7 +348,9 @@ def __init__(
345348
self._value = m.group(2)
346349
parser = parse_generic_constraint
347350

348-
if name in self._VERSION_LIKE_MARKER_NAME:
351+
if name in self._VERSION_LIKE_MARKER_NAME and not (
352+
name == "platform_release" and str_cmp
353+
):
349354
parser = parse_marker_version_constraint
350355

351356
if self._operator in {"in", "not in"}:
@@ -901,11 +906,12 @@ def _compact_markers(
901906

902907
elif token.data == f"{tree_prefix}item":
903908
name, op, value = token.children
904-
if value.type == f"{tree_prefix}MARKER_NAME":
909+
str_cmp = value.type == f"{tree_prefix}MARKER_NAME"
910+
if str_cmp:
905911
name, value = value, name
906912

907913
value = value[1:-1]
908-
sub_marker = SingleMarker(str(name), f"{op}{value}")
914+
sub_marker = SingleMarker(str(name), f"{op}{value}", str_cmp=str_cmp)
909915
groups[-1].append(sub_marker)
910916

911917
elif token.data == f"{tree_prefix}BOOL_OP" and token.children[0] == "or":

tests/version/test_markers.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -916,19 +916,24 @@ def test_multi_marker_removes_duplicates() -> None:
916916
("sys.platform == 'win32'", {"sys_platform": "linux2"}, False),
917917
("platform.version in 'Ubuntu'", {"platform_version": "#39"}, False),
918918
("platform.machine=='x86_64'", {"platform_machine": "x86_64"}, True),
919-
('"tegra" in platform_machine', {"platform_machine": "5.10.120-tegra"}, True),
920-
('"tegra" in platform_machine', {"platform_machine": "5.10.120"}, False),
919+
('"tegra" in platform_release', {"platform_release": "5.10.120-tegra"}, True),
920+
('"tegra" in platform_release', {"platform_release": "5.10.120"}, False),
921921
(
922-
'"tegra" not in platform_machine',
923-
{"platform_machine": "5.10.120-tegra"},
922+
'"tegra" not in platform_release',
923+
{"platform_release": "5.10.120-tegra"},
924924
False,
925925
),
926-
('"tegra" not in platform_machine', {"platform_machine": "5.10.120"}, True),
926+
('"tegra" not in platform_release', {"platform_release": "5.10.120"}, True),
927927
(
928928
"platform_release != '4.9.253-tegra'",
929929
{"platform_release": "4.9.254-tegra"},
930930
True,
931931
),
932+
(
933+
"platform_release >= '6.6.0+rpt-rpi-v8'",
934+
{"platform_release": "6.6.20+rpt-rpi-v8"},
935+
True,
936+
),
932937
(
933938
"platform_release < '5.10.123-tegra' and platform_release >= '4.9.254-tegra'",
934939
{"platform_release": "4.9.254-tegra"},

0 commit comments

Comments
 (0)