Skip to content

Commit e41b134

Browse files
committed
install report: use array instead of dict for install field
1 parent 6529635 commit e41b134

File tree

3 files changed

+31
-26
lines changed

3 files changed

+31
-26
lines changed

docs/html/reference/installation-report.md

+12-9
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ The report is a JSON object with the following properties:
1818
the corresponding version.
1919

2020
- `pip_version`: a string with the version of pip used to produce the report.
21-
- `install`: an object where the properties are the canonicalized names of the
22-
distribution packages (to be) installed and the values are of type
23-
`InstallationReportItem` (see below).
21+
22+
- `install`: an array of [InstallationReportItem](InstallationReportItem) representing
23+
the distribution packages (to be) installed.
24+
2425
- `environment`: an object describing the environment where the installation report was
2526
generated. See [PEP 508 environment
2627
markers](https://peps.python.org/pep-0508/#environment-markers) for more information.
2728
Values have a string type.
2829

30+
(InstallationReportItem)=
31+
2932
An `InstallationReportItem` is an object describing a (to be) installed distribution
3033
package with the following properties:
3134

@@ -75,8 +78,8 @@ will produce an output similar to this (metadata abriged for brevity):
7578
{
7679
"version": "0",
7780
"pip_version": "22.2",
78-
"install": {
79-
"pydantic": {
81+
"install": [
82+
{
8083
"download_info": {
8184
"url": "https://files.pythonhosted.org/packages/a4/0c/fbaa7319dcb5eecd3484686eb5a5c5702a6445adb566f01aee6de3369bc4/pydantic-1.9.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
8285
"archive_info": {
@@ -101,7 +104,7 @@ will produce an output similar to this (metadata abriged for brevity):
101104
]
102105
}
103106
},
104-
"packaging": {
107+
{
105108
"download_info": {
106109
"url": "https://github.com/pypa/packaging",
107110
"vcs_info": {
@@ -121,7 +124,7 @@ will produce an output similar to this (metadata abriged for brevity):
121124
"requires_python": ">=3.7"
122125
}
123126
},
124-
"pyparsing": {
127+
{
125128
"download_info": {
126129
"url": "https://files.pythonhosted.org/packages/6c/10/a7d0fa5baea8fe7b50f448ab742f26f52b80bfca85ac2be9d35cdd9a3246/pyparsing-3.0.9-py3-none-any.whl",
127130
"archive_info": {
@@ -140,7 +143,7 @@ will produce an output similar to this (metadata abriged for brevity):
140143
"requires_python": ">=3.6.8"
141144
}
142145
},
143-
"typing-extensions": {
146+
{
144147
"download_info": {
145148
"url": "https://files.pythonhosted.org/packages/75/e1/932e06004039dd670c9d5e1df0cd606bf46e29a28e65d5bb28e894ea29c9/typing_extensions-4.2.0-py3-none-any.whl",
146149
"archive_info": {
@@ -155,7 +158,7 @@ will produce an output similar to this (metadata abriged for brevity):
155158
"requires_python": ">=3.7"
156159
}
157160
}
158-
},
161+
],
159162
"environment": {
160163
"implementation_name": "cpython",
161164
"implementation_version": "3.10.5",

src/pip/_internal/models/installation_report.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from typing import Any, Dict, Sequence
22

33
from pip._vendor.packaging.markers import default_environment
4-
from pip._vendor.packaging.utils import canonicalize_name
54

65
from pip import __version__
76
from pip._internal.req.req_install import InstallRequirement
@@ -41,12 +40,9 @@ def to_dict(self) -> Dict[str, Any]:
4140
return {
4241
"version": "0",
4342
"pip_version": __version__,
44-
"install": {
45-
canonicalize_name(ireq.metadata["Name"]): self._install_req_to_dict(
46-
ireq
47-
)
48-
for ireq in self._install_requirements
49-
},
43+
"install": [
44+
self._install_req_to_dict(ireq) for ireq in self._install_requirements
45+
],
5046
# https://peps.python.org/pep-0508/#environment-markers
5147
# TODO: currently, the resolver uses the default environment to evaluate
5248
# environment markers, so that is what we report here. In the future, it

tests/functional/test_install_report.py

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import json
22
from pathlib import Path
3+
from typing import Any, Dict
34

45
import pytest
6+
from packaging.utils import canonicalize_name
57

68
from ..lib import PipTestEnvironment, TestData
79

810

11+
def _install_dict(report: Dict[str, Any]) -> Dict[str, Any]:
12+
return {canonicalize_name(i["metadata"]["name"]): i for i in report["install"]}
13+
14+
915
@pytest.mark.usefixtures("with_wheel")
1016
def test_install_report_basic(
1117
script: PipTestEnvironment, shared_data: TestData, tmp_path: Path
@@ -24,8 +30,7 @@ def test_install_report_basic(
2430
report = json.loads(report_path.read_text())
2531
assert "install" in report
2632
assert len(report["install"]) == 1
27-
assert "simplewheel" in report["install"]
28-
simplewheel_report = report["install"]["simplewheel"]
33+
simplewheel_report = _install_dict(report)["simplewheel"]
2934
assert simplewheel_report["metadata"]["name"] == "simplewheel"
3035
assert simplewheel_report["requested"] is True
3136
assert simplewheel_report["is_direct"] is False
@@ -56,8 +61,8 @@ def test_install_report_dep(
5661
)
5762
report = json.loads(report_path.read_text())
5863
assert len(report["install"]) == 2
59-
assert report["install"]["require-simple"]["requested"] is True
60-
assert report["install"]["simple"]["requested"] is False
64+
assert _install_dict(report)["require-simple"]["requested"] is True
65+
assert _install_dict(report)["simple"]["requested"] is False
6166

6267

6368
@pytest.mark.network
@@ -74,9 +79,10 @@ def test_install_report_index(script: PipTestEnvironment, tmp_path: Path) -> Non
7479
)
7580
report = json.loads(report_path.read_text())
7681
assert len(report["install"]) == 2
77-
assert report["install"]["paste"]["requested"] is True
78-
assert report["install"]["python-openid"]["requested"] is False
79-
paste_report = report["install"]["paste"]
82+
install_dict = _install_dict(report)
83+
assert install_dict["paste"]["requested"] is True
84+
assert install_dict["python-openid"]["requested"] is False
85+
paste_report = install_dict["paste"]
8086
assert paste_report["download_info"]["url"].startswith(
8187
"https://files.pythonhosted.org/"
8288
)
@@ -108,7 +114,7 @@ def test_install_report_vcs_and_wheel_cache(
108114
)
109115
report = json.loads(report_path.read_text())
110116
assert len(report["install"]) == 1
111-
pip_test_package_report = report["install"]["pip-test-package"]
117+
pip_test_package_report = report["install"][0]
112118
assert pip_test_package_report["is_direct"] is True
113119
assert pip_test_package_report["requested"] is True
114120
assert (
@@ -136,7 +142,7 @@ def test_install_report_vcs_and_wheel_cache(
136142
assert "Using cached pip_test_package" in result.stdout
137143
report = json.loads(report_path.read_text())
138144
assert len(report["install"]) == 1
139-
pip_test_package_report = report["install"]["pip-test-package"]
145+
pip_test_package_report = report["install"][0]
140146
assert pip_test_package_report["is_direct"] is True
141147
assert pip_test_package_report["requested"] is True
142148
assert (
@@ -168,7 +174,7 @@ def test_install_report_vcs_editable(
168174
)
169175
report = json.loads(report_path.read_text())
170176
assert len(report["install"]) == 1
171-
pip_test_package_report = report["install"]["pip-test-package"]
177+
pip_test_package_report = report["install"][0]
172178
assert pip_test_package_report["is_direct"] is True
173179
assert pip_test_package_report["download_info"]["url"].startswith("file://")
174180
assert pip_test_package_report["download_info"]["url"].endswith(

0 commit comments

Comments
 (0)