Skip to content

Commit a2f1ab8

Browse files
authored
Merge pull request #189 from python-poetry/1.0-fix-evaluation-of-in-markers
[1.0] Fix the evaluation of `in/not in` markers
2 parents 992f86f + f69efc6 commit a2f1ab8

6 files changed

Lines changed: 67 additions & 3 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Install and set up Poetry
2424
run: |
2525
curl -fsS -o get-poetry.py https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py
26-
python get-poetry.py --preview -y
26+
python get-poetry.py -y
2727
- name: Build distributions
2828
run: |
2929
source $HOME/.poetry/env

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
shell: bash
4242
run: |
4343
curl -fsS -o get-poetry.py https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py
44-
python get-poetry.py --preview -y
44+
python get-poetry.py -y
4545
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
4646
4747
- name: Configure poetry

poetry/core/packages/constraints/base_constraint.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77

88
class BaseConstraint(object):
9+
def allows(self, other): # type: ("ConstraintTypes") -> bool
10+
raise NotImplementedError
11+
912
def allows_all(self, other): # type: ("ConstraintTypes") -> bool
1013
raise NotImplementedError()
1114

poetry/core/packages/constraints/empty_constraint.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ def matches(self, _): # type: ("ConstraintTypes") -> bool
1717
def is_empty(self): # type: () -> bool
1818
return True
1919

20+
def allows(self, other): # type: ("ConstraintTypes") -> bool
21+
return False
22+
2023
def allows_all(self, other): # type: ("ConstraintTypes") -> bool
2124
return True
2225

poetry/core/version/markers.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,17 @@ def __init__(
225225
else:
226226
self._constraint = self._parser(self._constraint_string)
227227
else:
228-
self._constraint = self._parser(self._constraint_string)
228+
# if we have a in/not in operator we split the constraint
229+
# into a union/multi-constraint of single constraint
230+
constraint_string = self._constraint_string
231+
if self._operator in {"in", "not in"}:
232+
op, glue = ("==", " || ") if self._operator == "in" else ("!=", ", ")
233+
values = re.split("[ ,]+", self._value)
234+
constraint_string = glue.join(
235+
("{} {}".format(op, value) for value in values)
236+
)
237+
238+
self._constraint = self._parser(constraint_string)
229239

230240
@property
231241
def name(self): # type: () -> str

tests/version/test_markers.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,34 @@ def test_single_marker():
3636
assert m.constraint_string == "not in 2.7, 3.0, 3.1"
3737
assert str(m.constraint) == "<2.7.0 || >=2.8.0,<3.0.0 || >=3.2.0"
3838

39+
m = parse_marker(
40+
"platform_machine in 'x86_64 X86_64 aarch64 AARCH64 ppc64le PPC64LE amd64 AMD64 win32 WIN32'"
41+
)
42+
43+
assert isinstance(m, SingleMarker)
44+
assert m.name == "platform_machine"
45+
assert (
46+
m.constraint_string
47+
== "in x86_64 X86_64 aarch64 AARCH64 ppc64le PPC64LE amd64 AMD64 win32 WIN32"
48+
)
49+
assert str(m.constraint) == (
50+
"x86_64 || X86_64 || aarch64 || AARCH64 || ppc64le || PPC64LE || amd64 || AMD64 || win32 || WIN32"
51+
)
52+
53+
m = parse_marker(
54+
"platform_machine not in 'x86_64 X86_64 aarch64 AARCH64 ppc64le PPC64LE amd64 AMD64 win32 WIN32'"
55+
)
56+
57+
assert isinstance(m, SingleMarker)
58+
assert m.name == "platform_machine"
59+
assert (
60+
m.constraint_string
61+
== "not in x86_64 X86_64 aarch64 AARCH64 ppc64le PPC64LE amd64 AMD64 win32 WIN32"
62+
)
63+
assert str(m.constraint) == (
64+
"!=x86_64, !=X86_64, !=aarch64, !=AARCH64, !=ppc64le, !=PPC64LE, !=amd64, !=AMD64, !=win32, !=WIN32"
65+
)
66+
3967

4068
def test_single_marker_intersect():
4169
m = parse_marker('sys_platform == "darwin"')
@@ -476,6 +504,26 @@ def test_multi_marker_removes_duplicates():
476504
{"python_version": "2.7"},
477505
False,
478506
),
507+
(
508+
"platform_machine in 'x86_64 X86_64 aarch64 AARCH64 ppc64le PPC64LE amd64 AMD64 win32 WIN32'",
509+
{"platform_machine": "foo"},
510+
False,
511+
),
512+
(
513+
"platform_machine in 'x86_64 X86_64 aarch64 AARCH64 ppc64le PPC64LE amd64 AMD64 win32 WIN32'",
514+
{"platform_machine": "x86_64"},
515+
True,
516+
),
517+
(
518+
"platform_machine not in 'x86_64 X86_64 aarch64 AARCH64 ppc64le PPC64LE amd64 AMD64 win32 WIN32'",
519+
{"platform_machine": "foo"},
520+
True,
521+
),
522+
(
523+
"platform_machine not in 'x86_64 X86_64 aarch64 AARCH64 ppc64le PPC64LE amd64 AMD64 win32 WIN32'",
524+
{"platform_machine": "x86_64"},
525+
False,
526+
),
479527
],
480528
)
481529
def test_validate(marker_string, environment, expected):

0 commit comments

Comments
 (0)