mirror of https://github.com/pypa/pip
install report: use array instead of dict for install field
This commit is contained in:
parent
652963548e
commit
e41b13424e
|
@ -18,14 +18,17 @@ The report is a JSON object with the following properties:
|
|||
the corresponding version.
|
||||
|
||||
- `pip_version`: a string with the version of pip used to produce the report.
|
||||
- `install`: an object where the properties are the canonicalized names of the
|
||||
distribution packages (to be) installed and the values are of type
|
||||
`InstallationReportItem` (see below).
|
||||
|
||||
- `install`: an array of [InstallationReportItem](InstallationReportItem) representing
|
||||
the distribution packages (to be) installed.
|
||||
|
||||
- `environment`: an object describing the environment where the installation report was
|
||||
generated. See [PEP 508 environment
|
||||
markers](https://peps.python.org/pep-0508/#environment-markers) for more information.
|
||||
Values have a string type.
|
||||
|
||||
(InstallationReportItem)=
|
||||
|
||||
An `InstallationReportItem` is an object describing a (to be) installed distribution
|
||||
package with the following properties:
|
||||
|
||||
|
@ -75,8 +78,8 @@ will produce an output similar to this (metadata abriged for brevity):
|
|||
{
|
||||
"version": "0",
|
||||
"pip_version": "22.2",
|
||||
"install": {
|
||||
"pydantic": {
|
||||
"install": [
|
||||
{
|
||||
"download_info": {
|
||||
"url": "https://files.pythonhosted.org/packages/a4/0c/fbaa7319dcb5eecd3484686eb5a5c5702a6445adb566f01aee6de3369bc4/pydantic-1.9.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
|
||||
"archive_info": {
|
||||
|
@ -101,7 +104,7 @@ will produce an output similar to this (metadata abriged for brevity):
|
|||
]
|
||||
}
|
||||
},
|
||||
"packaging": {
|
||||
{
|
||||
"download_info": {
|
||||
"url": "https://github.com/pypa/packaging",
|
||||
"vcs_info": {
|
||||
|
@ -121,7 +124,7 @@ will produce an output similar to this (metadata abriged for brevity):
|
|||
"requires_python": ">=3.7"
|
||||
}
|
||||
},
|
||||
"pyparsing": {
|
||||
{
|
||||
"download_info": {
|
||||
"url": "https://files.pythonhosted.org/packages/6c/10/a7d0fa5baea8fe7b50f448ab742f26f52b80bfca85ac2be9d35cdd9a3246/pyparsing-3.0.9-py3-none-any.whl",
|
||||
"archive_info": {
|
||||
|
@ -140,7 +143,7 @@ will produce an output similar to this (metadata abriged for brevity):
|
|||
"requires_python": ">=3.6.8"
|
||||
}
|
||||
},
|
||||
"typing-extensions": {
|
||||
{
|
||||
"download_info": {
|
||||
"url": "https://files.pythonhosted.org/packages/75/e1/932e06004039dd670c9d5e1df0cd606bf46e29a28e65d5bb28e894ea29c9/typing_extensions-4.2.0-py3-none-any.whl",
|
||||
"archive_info": {
|
||||
|
@ -155,7 +158,7 @@ will produce an output similar to this (metadata abriged for brevity):
|
|||
"requires_python": ">=3.7"
|
||||
}
|
||||
}
|
||||
},
|
||||
],
|
||||
"environment": {
|
||||
"implementation_name": "cpython",
|
||||
"implementation_version": "3.10.5",
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
from typing import Any, Dict, Sequence
|
||||
|
||||
from pip._vendor.packaging.markers import default_environment
|
||||
from pip._vendor.packaging.utils import canonicalize_name
|
||||
|
||||
from pip import __version__
|
||||
from pip._internal.req.req_install import InstallRequirement
|
||||
|
@ -41,12 +40,9 @@ class InstallationReport:
|
|||
return {
|
||||
"version": "0",
|
||||
"pip_version": __version__,
|
||||
"install": {
|
||||
canonicalize_name(ireq.metadata["Name"]): self._install_req_to_dict(
|
||||
ireq
|
||||
)
|
||||
for ireq in self._install_requirements
|
||||
},
|
||||
"install": [
|
||||
self._install_req_to_dict(ireq) for ireq in self._install_requirements
|
||||
],
|
||||
# https://peps.python.org/pep-0508/#environment-markers
|
||||
# TODO: currently, the resolver uses the default environment to evaluate
|
||||
# environment markers, so that is what we report here. In the future, it
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
import json
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict
|
||||
|
||||
import pytest
|
||||
from packaging.utils import canonicalize_name
|
||||
|
||||
from ..lib import PipTestEnvironment, TestData
|
||||
|
||||
|
||||
def _install_dict(report: Dict[str, Any]) -> Dict[str, Any]:
|
||||
return {canonicalize_name(i["metadata"]["name"]): i for i in report["install"]}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("with_wheel")
|
||||
def test_install_report_basic(
|
||||
script: PipTestEnvironment, shared_data: TestData, tmp_path: Path
|
||||
|
@ -24,8 +30,7 @@ def test_install_report_basic(
|
|||
report = json.loads(report_path.read_text())
|
||||
assert "install" in report
|
||||
assert len(report["install"]) == 1
|
||||
assert "simplewheel" in report["install"]
|
||||
simplewheel_report = report["install"]["simplewheel"]
|
||||
simplewheel_report = _install_dict(report)["simplewheel"]
|
||||
assert simplewheel_report["metadata"]["name"] == "simplewheel"
|
||||
assert simplewheel_report["requested"] is True
|
||||
assert simplewheel_report["is_direct"] is False
|
||||
|
@ -56,8 +61,8 @@ def test_install_report_dep(
|
|||
)
|
||||
report = json.loads(report_path.read_text())
|
||||
assert len(report["install"]) == 2
|
||||
assert report["install"]["require-simple"]["requested"] is True
|
||||
assert report["install"]["simple"]["requested"] is False
|
||||
assert _install_dict(report)["require-simple"]["requested"] is True
|
||||
assert _install_dict(report)["simple"]["requested"] is False
|
||||
|
||||
|
||||
@pytest.mark.network
|
||||
|
@ -74,9 +79,10 @@ def test_install_report_index(script: PipTestEnvironment, tmp_path: Path) -> Non
|
|||
)
|
||||
report = json.loads(report_path.read_text())
|
||||
assert len(report["install"]) == 2
|
||||
assert report["install"]["paste"]["requested"] is True
|
||||
assert report["install"]["python-openid"]["requested"] is False
|
||||
paste_report = report["install"]["paste"]
|
||||
install_dict = _install_dict(report)
|
||||
assert install_dict["paste"]["requested"] is True
|
||||
assert install_dict["python-openid"]["requested"] is False
|
||||
paste_report = install_dict["paste"]
|
||||
assert paste_report["download_info"]["url"].startswith(
|
||||
"https://files.pythonhosted.org/"
|
||||
)
|
||||
|
@ -108,7 +114,7 @@ def test_install_report_vcs_and_wheel_cache(
|
|||
)
|
||||
report = json.loads(report_path.read_text())
|
||||
assert len(report["install"]) == 1
|
||||
pip_test_package_report = report["install"]["pip-test-package"]
|
||||
pip_test_package_report = report["install"][0]
|
||||
assert pip_test_package_report["is_direct"] is True
|
||||
assert pip_test_package_report["requested"] is True
|
||||
assert (
|
||||
|
@ -136,7 +142,7 @@ def test_install_report_vcs_and_wheel_cache(
|
|||
assert "Using cached pip_test_package" in result.stdout
|
||||
report = json.loads(report_path.read_text())
|
||||
assert len(report["install"]) == 1
|
||||
pip_test_package_report = report["install"]["pip-test-package"]
|
||||
pip_test_package_report = report["install"][0]
|
||||
assert pip_test_package_report["is_direct"] is True
|
||||
assert pip_test_package_report["requested"] is True
|
||||
assert (
|
||||
|
@ -168,7 +174,7 @@ def test_install_report_vcs_editable(
|
|||
)
|
||||
report = json.loads(report_path.read_text())
|
||||
assert len(report["install"]) == 1
|
||||
pip_test_package_report = report["install"]["pip-test-package"]
|
||||
pip_test_package_report = report["install"][0]
|
||||
assert pip_test_package_report["is_direct"] is True
|
||||
assert pip_test_package_report["download_info"]["url"].startswith("file://")
|
||||
assert pip_test_package_report["download_info"]["url"].endswith(
|
||||
|
|
Loading…
Reference in New Issue