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

normalize python_versions on packages #407

Merged
merged 1 commit into from
Jun 26, 2022
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
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"