Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

markers: fix get_python_constraint_by_marker() for multi markers and marker unions without python_version #546

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 2 additions & 29 deletions src/poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,22 +489,7 @@ def exclude(self, marker_name: str) -> BaseMarker:
return self.of(*new_markers)

def only(self, *marker_names: str) -> BaseMarker:
new_markers = []

for m in self._markers:
if isinstance(m, SingleMarker) and m.name not in marker_names:
# The marker is not relevant since it's not one we want
continue

marker = m.only(*marker_names)

if not marker.is_empty():
new_markers.append(marker)

if not new_markers:
return EmptyMarker()

return self.of(*new_markers)
return self.of(*(m.only(*marker_names) for m in self._markers))

def invert(self) -> BaseMarker:
markers = [marker.invert() for marker in self._markers]
Expand Down Expand Up @@ -635,19 +620,7 @@ def exclude(self, marker_name: str) -> BaseMarker:
return self.of(*new_markers)

def only(self, *marker_names: str) -> BaseMarker:
new_markers = []

for m in self._markers:
if isinstance(m, SingleMarker) and m.name not in marker_names:
# The marker is not relevant since it's not one we want
continue

marker = m.only(*marker_names)

if not marker.is_empty():
new_markers.append(marker)

return self.of(*new_markers)
return self.of(*(m.only(*marker_names) for m in self._markers))

def invert(self) -> BaseMarker:
markers = [marker.invert() for marker in self._markers]
Expand Down
2 changes: 2 additions & 0 deletions tests/packages/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ def test_create_nested_marker_version_constraint(
),
# no python_version
('sys_platform == "linux"', "*"),
('sys_platform != "linux" and sys_platform != "win32"', "*"),
('sys_platform == "linux" or sys_platform == "win32"', "*"),
# no relevant python_version
('python_version >= "3.9" or sys_platform == "linux"', "*"),
# relevant python_version
Expand Down
29 changes: 16 additions & 13 deletions tests/version/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,9 @@ def test_exclude(marker: str, excluded: str, expected: str) -> None:
["python_version"],
'python_version >= "3.6"',
),
('python_version >= "3.6" and extra == "foo"', ["sys_platform"], ""),
('python_version >= "3.6" or extra == "foo"', ["sys_platform"], ""),
('python_version >= "3.6" or extra == "foo"', ["python_version"], ""),
(
'python_version >= "3.6" and (extra == "foo" or extra == "bar")',
["extra"],
Expand All @@ -1028,31 +1031,31 @@ def test_exclude(marker: str, excluded: str, expected: str) -> None:
' implementation_name == "pypy"'
),
["implementation_name"],
'implementation_name == "pypy"',
"",
),
(
(
'python_version >= "3.6" and extra == "foo" or implementation_name =='
' "pypy" and extra == "bar"'
'python_version >= "3.6" and (extra == "foo" or extra == "bar") or'
' implementation_name == "pypy"'
),
["implementation_name"],
'implementation_name == "pypy"',
["implementation_name", "extra"],
'extra == "foo" or extra == "bar" or implementation_name == "pypy"',
),
(
(
'python_version >= "3.6" or extra == "foo" and implementation_name =='
' "pypy" or extra == "bar"'
'python_version >= "3.6" and (extra == "foo" or extra == "bar") or'
' implementation_name == "pypy"'
),
["implementation_name"],
'implementation_name == "pypy"',
["implementation_name", "python_version"],
'python_version >= "3.6" or implementation_name == "pypy"',
),
(
(
'python_version >= "3.6" or extra == "foo" and implementation_name =='
' "pypy" or extra == "bar"'
'python_version >= "3.6" and extra == "foo" or implementation_name =='
' "pypy" and extra == "bar"'
),
["implementation_name", "python_version"],
'python_version >= "3.6" or implementation_name == "pypy"',
["implementation_name", "extra"],
'extra == "foo" or implementation_name == "pypy" and extra == "bar"',
),
],
)
Expand Down