From 943261cc852ad0741ce1827f3a9fb2ad4e3a9d23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Mon, 13 Jun 2022 17:10:25 +0200 Subject: [PATCH 1/2] link: support for yanked files according to PEP 592 --- src/poetry/core/packages/utils/link.py | 17 +++++++++++++++++ tests/packages/utils/test_utils_link.py | 25 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/poetry/core/packages/utils/link.py b/src/poetry/core/packages/utils/link.py index 8cbda0fd6..c6d8277d2 100644 --- a/src/poetry/core/packages/utils/link.py +++ b/src/poetry/core/packages/utils/link.py @@ -14,6 +14,7 @@ def __init__( url: str, requires_python: str | None = None, metadata: str | bool | None = None, + yanked: str | bool = False, ) -> None: """ Object representing a parsed link from https://pypi.python.org/simple/* @@ -29,6 +30,11 @@ def __init__( of the Core Metadata file. This may be specified by a data-dist-info-metadata attribute in the HTML link tag, as described in PEP 658. + yanked: + False, if the data-yanked attribute is not present. + A string, if the data-yanked attribute has a string value. + True, if the data-yanked attribute is present but has no value. + According to PEP 592. """ # url can be a UNC windows share @@ -44,6 +50,7 @@ def __init__( ) self._metadata = metadata + self._yanked = yanked def __str__(self) -> str: if self.requires_python: @@ -213,3 +220,13 @@ def is_artifact(self) -> bool: return False return True + + @property + def yanked(self) -> bool: + return isinstance(self._yanked, str) or bool(self._yanked) + + @property + def yanked_reason(self) -> str: + if isinstance(self._yanked, str): + return self._yanked + return "" diff --git a/tests/packages/utils/test_utils_link.py b/tests/packages/utils/test_utils_link.py index d31ce2440..b49587545 100644 --- a/tests/packages/utils/test_utils_link.py +++ b/tests/packages/utils/test_utils_link.py @@ -118,3 +118,28 @@ def test_package_link_pep653_non_hash_metadata_value( assert not link.metadata_hash assert not link.metadata_hash_name + + +def test_package_link_pep592_default_not_yanked() -> None: + link = make_url(ext="whl") + + assert not link.yanked + assert link.yanked_reason == "" + + +@pytest.mark.parametrize( + ("yanked", "expected_yanked", "expected_yanked_reason"), + [ + (True, True, ""), + (False, False, ""), + ("the reason", True, "the reason"), + ("", True, ""), + ], +) +def test_package_link_pep592_yanked( + yanked: str | bool, expected_yanked: bool, expected_yanked_reason: str +) -> None: + link = Link("https://example.org", yanked=yanked) + + assert link.yanked == expected_yanked + assert link.yanked_reason == expected_yanked_reason From b82c3db86c508a90bbec8e0f3d659faf24fb44fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Mon, 13 Jun 2022 17:11:02 +0200 Subject: [PATCH 2/2] package: support for yanked releases according to PEP 592 --- src/poetry/core/packages/package.py | 13 +++++++++++++ tests/packages/test_package.py | 25 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/poetry/core/packages/package.py b/src/poetry/core/packages/package.py index 0d396a015..62819e611 100644 --- a/src/poetry/core/packages/package.py +++ b/src/poetry/core/packages/package.py @@ -59,6 +59,7 @@ def __init__( source_subdirectory: str | None = None, features: Iterable[str] | None = None, develop: bool = False, + yanked: str | bool = False, ) -> None: """ Creates a new in memory package. @@ -117,6 +118,8 @@ def __init__( self.develop = develop + self._yanked = yanked + @property def name(self) -> str: return self._name @@ -368,6 +371,16 @@ def readme(self, path: Path) -> None: ) self.readmes = (path,) + @property + def yanked(self) -> bool: + return isinstance(self._yanked, str) or bool(self._yanked) + + @property + def yanked_reason(self) -> str: + if isinstance(self._yanked, str): + return self._yanked + return "" + def is_prerelease(self) -> bool: return self._version.is_unstable() diff --git a/tests/packages/test_package.py b/tests/packages/test_package.py index d12fc25e4..b9d956caf 100644 --- a/tests/packages/test_package.py +++ b/tests/packages/test_package.py @@ -502,3 +502,28 @@ def test_package_satisfies( package: Package, dependency: Dependency, ignore_source_type: bool, result: bool ) -> None: assert package.satisfies(dependency, ignore_source_type) == result + + +def test_package_pep592_default_not_yanked() -> None: + package = Package("foo", "1.0") + + assert not package.yanked + assert package.yanked_reason == "" + + +@pytest.mark.parametrize( + ("yanked", "expected_yanked", "expected_yanked_reason"), + [ + (True, True, ""), + (False, False, ""), + ("the reason", True, "the reason"), + ("", True, ""), + ], +) +def test_package_pep592_yanked( + yanked: str | bool, expected_yanked: bool, expected_yanked_reason: str +) -> None: + package = Package("foo", "1.0", yanked=yanked) + + assert package.yanked == expected_yanked + assert package.yanked_reason == expected_yanked_reason