Skip to content
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
12 changes: 9 additions & 3 deletions src/poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from poetry.core.constraints.generic import UnionConstraint
from poetry.core.constraints.generic.parser import STR_CMP_CONSTRAINT
from poetry.core.constraints.version import VersionConstraint
from poetry.core.constraints.version import VersionRange
from poetry.core.constraints.version import VersionUnion
from poetry.core.constraints.version.exceptions import ParseConstraintError
from poetry.core.version.grammars import GRAMMAR_PEP_508_MARKERS
Expand Down Expand Up @@ -446,10 +447,15 @@ def reduce_by_python_constraint(
self, python_constraint: VersionConstraint
) -> BaseMarker:
if self.name in PYTHON_VERSION_MARKERS:
from poetry.core.packages.utils.utils import (
get_python_constraint_from_marker,
)

assert isinstance(self._constraint, VersionConstraint)
if self._constraint.allows_all(python_constraint):
constraint = get_python_constraint_from_marker(self)
if constraint.allows_all(python_constraint):
return AnyMarker()
elif not self._constraint.allows_any(python_constraint):
elif not constraint.allows_any(python_constraint):
return EmptyMarker()

return self
Expand Down Expand Up @@ -931,7 +937,7 @@ def reduce_by_python_constraint(
from poetry.core.packages.utils.utils import get_python_constraint_from_marker

markers: Iterable[BaseMarker] = self._markers
if isinstance(python_constraint, VersionUnion):
if isinstance(python_constraint, (VersionRange, VersionUnion)):
python_only_markers = []
other_markers = []
for m in self._markers:
Expand Down
17 changes: 16 additions & 1 deletion tests/version/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,12 @@ def test_only(marker: str, only: list[str], expected: str) -> None:
("<empty>", "~3.8", "<empty>"),
('sys_platform == "linux"', "~3.8", 'sys_platform == "linux"'),
('python_version >= "3.8"', "~3.8", ""),
('python_version > "3.8"', "~3.8", 'python_version > "3.8"'),
('python_version == "3.8"', ">=3.8.7,<3.9.0", ""),
('python_version == "3.8" or python_version >= "3.9"', ">=3.8.0,<4.0.0", ""),
('python_version == "3.8" or python_version >= "3.9"', ">=3.8.7,<4.0.0", ""),
('python_version > "3.7"', "~3.8", ""),
('python_version > "3.8"', "~3.8", "<empty>"),
('python_version >= "3.8"', "~3.8", ""),
('python_version >= "3.9"', "~3.8", "<empty>"),
('python_full_version >= "3.8.0"', "~3.8", ""),
('python_full_version >= "3.8.1"', "~3.8", 'python_full_version >= "3.8.1"'),
Expand Down Expand Up @@ -1503,6 +1508,16 @@ def test_only(marker: str, only: list[str], expected: str) -> None:
"~3.7 || ~3.9",
'sys_platform == "linux" or sys_platform == "win32"',
),
(
'python_version == "3.8" or sys_platform == "linux" or python_version >= "3.9"',
">=3.8.0,<4.0.0",
'sys_platform == "linux"',
),
(
'python_version == "3.8" or sys_platform == "linux" or python_version >= "3.9"',
">=3.8.7,<4.0.0",
'sys_platform == "linux"',
),
],
)
def test_reduce_by_python_constraint(
Expand Down
Loading