Skip to content

Commit 32bd232

Browse files
committed
Fixing platform_release pep440
1 parent 8d16421 commit 32bd232

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

src/poetry/core/constraints/generic/constraint.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,34 @@
1414
OperatorType = Callable[[object, object], Any]
1515

1616

17+
def contains(a: object, b: object, /) -> bool:
18+
return operator.contains(a, b) # type: ignore[arg-type]
19+
20+
21+
def not_contains(a: object, b: object, /) -> bool:
22+
return not contains(a, b)
23+
24+
1725
class Constraint(BaseConstraint):
1826
OP_EQ = operator.eq
1927
OP_NE = operator.ne
28+
OP_IN = contains
29+
OP_NC = not_contains
2030

2131
_trans_op_str: ClassVar[dict[str, OperatorType]] = {
2232
"=": OP_EQ,
2333
"==": OP_EQ,
2434
"!=": OP_NE,
35+
"in": OP_IN,
36+
"not in": OP_NC,
2537
}
2638

27-
_trans_op_int: ClassVar[dict[OperatorType, str]] = {OP_EQ: "==", OP_NE: "!="}
39+
_trans_op_int: ClassVar[dict[OperatorType, str]] = {
40+
OP_EQ: "==",
41+
OP_NE: "!=",
42+
OP_IN: "in",
43+
OP_NC: "not in",
44+
}
2845

2946
def __init__(self, value: str, operator: str = "==") -> None:
3047
if operator == "=":
@@ -64,6 +81,9 @@ def allows(self, other: BaseConstraint) -> bool:
6481
):
6582
return self._value != other.value
6683

84+
if self._operator in {"in", "not in"} and other.operator == "==":
85+
return bool(self._trans_op_str[self._operator](other.value, self._value))
86+
6787
return False
6888

6989
def allows_all(self, other: BaseConstraint) -> bool:

src/poetry/core/version/markers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,13 @@ def __hash__(self) -> int:
451451
def __str__(self) -> str:
452452
return f'{self._name} {self._operator} "{self._value}"'
453453

454+
def validate(self, environment: dict[str, Any] | None) -> bool:
455+
if self._operator in {"in", "not in"} and isinstance(
456+
self._constraint, Constraint
457+
):
458+
self._constraint = Constraint(self.value, self._operator)
459+
return super().validate(environment)
460+
454461

455462
class AtomicMultiMarker(SingleMarkerLike[MultiConstraint]):
456463
def __init__(self, name: str, constraint: MultiConstraint) -> None:

tests/version/test_markers.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ def test_parse_marker(marker: str) -> None:
109109
"platform_machine",
110110
"!=aarch64, !=loongarch64",
111111
),
112+
(
113+
'"tegra" in platform_machine',
114+
"platform_machine",
115+
"tegra",
116+
),
112117
],
113118
)
114119
def test_parse_single_marker(
@@ -882,6 +887,14 @@ def test_multi_marker_removes_duplicates() -> None:
882887
@pytest.mark.parametrize(
883888
("marker_string", "environment", "expected"),
884889
[
890+
('"tegra" in platform_machine', {"platform_machine": "5.10.120-tegra"}, True),
891+
('"tegra" in platform_machine', {"platform_machine": "5.10.120"}, False),
892+
(
893+
'"tegra" not in platform_machine',
894+
{"platform_machine": "5.10.120-tegra"},
895+
False,
896+
),
897+
('"tegra" not in platform_machine', {"platform_machine": "5.10.120"}, True),
885898
(f"os_name == '{os.name}'", None, True),
886899
("os_name == 'foo'", {"os_name": "foo"}, True),
887900
("os_name == 'foo'", {"os_name": "bar"}, False),

0 commit comments

Comments
 (0)