Skip to content

Commit

Permalink
deprecate python_marker instead of removing it and only calculate it …
Browse files Browse the repository at this point in the history
…on demand
  • Loading branch information
radoering committed Oct 5, 2024
1 parent 8723c0b commit e1b8759
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/poetry/core/packages/package.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import re
import warnings

from typing import TYPE_CHECKING
from typing import ClassVar
Expand Down Expand Up @@ -273,6 +274,21 @@ def python_versions(self, value: str) -> None:
def python_constraint(self) -> VersionConstraint:
return self._python_constraint

@property
def python_marker(self) -> BaseMarker:
from poetry.core.packages.utils.utils import create_nested_marker
from poetry.core.version.markers import parse_marker

warnings.warn(
"`python_marker` is deprecated and will be removed in a future release.",
DeprecationWarning,
stacklevel=2,
)

return parse_marker(
create_nested_marker("python_version", self._python_constraint)
)

@property
def license(self) -> License | None:
return self._license
Expand Down
12 changes: 12 additions & 0 deletions tests/packages/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,18 @@ def test_package_pep592_yanked(
assert package.yanked_reason == expected_yanked_reason


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

with pytest.warns(DeprecationWarning):
assert (
str(package.python_marker)
== 'python_full_version > "3.6.0" and python_full_version <= "3.10.0"'
)
assert str(package.python_constraint) == ">3.6,<=3.10"


def test_cannot_update_package_version() -> None:
package = Package("foo", "1.2.3")
with pytest.raises(AttributeError):
Expand Down

0 comments on commit e1b8759

Please sign in to comment.