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

Add is_yanked to installation report #12224

Merged
merged 5 commits into from
Sep 5, 2023
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
5 changes: 5 additions & 0 deletions docs/html/reference/installation-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ package with the following properties:
URL reference. `false` if the requirements was provided as a name and version
specifier.

- `is_yanked`: `true` if the requirement was yanked from the index, but was still
selected by pip conform to [PEP 592](https://peps.python.org/pep-0592/#installers).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
selected by pip conform to [PEP 592](https://peps.python.org/pep-0592/#installers).
selected by pip in comformance with [PEP 592](https://peps.python.org/pep-0592/#installers).

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im no native, but looks like 'conform to' and 'conform with' are both fine

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all four seem to occur, conform to seems most common on ngrams

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not native either :)


- `download_info`: Information about the artifact (to be) downloaded for installation,
using the [direct URL data
structure](https://packaging.python.org/en/latest/specifications/direct-url-data-structure/).
Expand Down Expand Up @@ -106,6 +109,7 @@ will produce an output similar to this (metadata abriged for brevity):
}
},
"is_direct": false,
"is_yanked": false,
"requested": true,
"metadata": {
"name": "pydantic",
Expand Down Expand Up @@ -133,6 +137,7 @@ will produce an output similar to this (metadata abriged for brevity):
}
},
"is_direct": true,
"is_yanked": false,
"requested": true,
"metadata": {
"name": "packaging",
Expand Down
1 change: 1 addition & 0 deletions news/12224.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``is_yanked`` boolean entry to the installation report (``--report``) to indicate whether the requirement was yanked from the index, but was still selected by pip conform to PEP 592.
3 changes: 3 additions & 0 deletions src/pip/_internal/models/installation_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def _install_req_to_dict(cls, ireq: InstallRequirement) -> Dict[str, Any]:
# includes editable requirements), and false if the requirement was
# downloaded from a PEP 503 index or --find-links.
"is_direct": ireq.is_direct,
# is_yanked is true if the requirement was yanked from the index, but
# was still selected by pip to conform to PEP 592.
"is_yanked": ireq.link.is_yanked if ireq.link else False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know in which circumstances ireq.link can be None ?

Perhaps we should output "is_yanked": None in that case, to express that we don't know if it's yanked or not, rather the False which asserts it is not yanked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when ireq.link is None, it's not coming from a pypi index. since the notion of yanking only applies to pypi indices, I think returning False here is safe. but please correct me if I'm wrong @pfmoore

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when ireq.link is None, it's not coming from a pypi index

If that's the reason of ireq.link is None, then it's fine to return is_yanked=False in such case, indeed.

# requested is true if the requirement was specified by the user (aka
# top level requirement), and false if it was installed as a dependency of a
# requirement. https://peps.python.org/pep-0376/#requested
Expand Down
53 changes: 53 additions & 0 deletions tests/functional/test_install_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,59 @@ def test_install_report_dep(
assert _install_dict(report)["simple"]["requested"] is False


def test_yanked_version(
script: PipTestEnvironment, data: TestData, tmp_path: Path
) -> None:
"""
Test is_yanked is True when explicitly requesting a yanked package.
Yanked files are always ignored, unless they are the only file that
matches a version specifier that "pins" to an exact version (PEP 592).
"""
report_path = tmp_path / "report.json"
script.pip(
"install",
"simple==3.0",
"--index-url",
data.index_url("yanked"),
"--dry-run",
"--report",
str(report_path),
allow_stderr_warning=True,
)
report = json.loads(report_path.read_text())
simple_report = _install_dict(report)["simple"]
assert simple_report["requested"] is True
assert simple_report["is_direct"] is False
assert simple_report["is_yanked"] is True
assert simple_report["metadata"]["version"] == "3.0"


def test_skipped_yanked_version(
script: PipTestEnvironment, data: TestData, tmp_path: Path
) -> None:
"""
Test is_yanked is False when not explicitly requesting a yanked package.
Yanked files are always ignored, unless they are the only file that
matches a version specifier that "pins" to an exact version (PEP 592).
"""
report_path = tmp_path / "report.json"
script.pip(
"install",
"simple",
"--index-url",
data.index_url("yanked"),
"--dry-run",
"--report",
str(report_path),
)
report = json.loads(report_path.read_text())
simple_report = _install_dict(report)["simple"]
assert simple_report["requested"] is True
assert simple_report["is_direct"] is False
assert simple_report["is_yanked"] is False
assert simple_report["metadata"]["version"] == "2.0"


@pytest.mark.network
def test_install_report_index(script: PipTestEnvironment, tmp_path: Path) -> None:
"""Test report for sdist obtained from index."""
Expand Down