Skip to content

Commit

Permalink
normalize python_versions on packages
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby authored and neersighted committed Jun 26, 2022
1 parent f6e8b58 commit cc8c659
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/poetry/core/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from poetry.core.packages.dependency_group import MAIN_GROUP
from poetry.core.packages.specification import PackageSpecification
from poetry.core.packages.utils.utils import create_nested_marker
from poetry.core.packages.utils.utils import get_python_constraint_from_marker
from poetry.core.semver.helpers import parse_constraint
from poetry.core.version.markers import parse_marker

Expand Down Expand Up @@ -255,10 +256,11 @@ def python_versions(self) -> str:
@python_versions.setter
def python_versions(self, value: str) -> None:
self._python_versions = value
self._python_constraint = parse_constraint(value)
constraint = parse_constraint(value)
self._python_marker = parse_marker(
create_nested_marker("python_version", self._python_constraint)
create_nested_marker("python_version", constraint)
)
self._python_constraint = get_python_constraint_from_marker(self._python_marker)

@property
def python_constraint(self) -> VersionConstraint:
Expand Down
11 changes: 11 additions & 0 deletions tests/packages/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,3 +527,14 @@ def test_package_pep592_yanked(

assert package.yanked == expected_yanked
assert package.yanked_reason == expected_yanked_reason


def test_python_versions_are_normalized() -> None:
package = Package("foo", "1.2.3")
package.python_versions = ">3.6,<=3.10"

assert (
str(package.python_marker)
== 'python_version > "3.6" and python_version <= "3.10"'
)
assert str(package.python_constraint) == ">=3.7,<3.11"

0 comments on commit cc8c659

Please sign in to comment.