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

Prerequisites for supporting yanked releases (PEP 592) #400

Merged
merged 2 commits into from
Jun 15, 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
13 changes: 13 additions & 0 deletions src/poetry/core/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -117,6 +118,8 @@ def __init__(

self.develop = develop

self._yanked = yanked

@property
def name(self) -> str:
return self._name
Expand Down Expand Up @@ -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()

Expand Down
17 changes: 17 additions & 0 deletions src/poetry/core/packages/utils/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
Expand All @@ -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
Expand All @@ -44,6 +50,7 @@ def __init__(
)

self._metadata = metadata
self._yanked = yanked

def __str__(self) -> str:
if self.requires_python:
Expand Down Expand Up @@ -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 ""
25 changes: 25 additions & 0 deletions tests/packages/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 25 additions & 0 deletions tests/packages/utils/test_utils_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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