Skip to content

Commit 74133f8

Browse files
authored
Merge pull request #11947 from sbidoul/direct-url-extras-report-sbi
Report requested_extras for direct URLs
2 parents 55f1251 + 5bfccfd commit 74133f8

File tree

3 files changed

+98
-1
lines changed

3 files changed

+98
-1
lines changed

news/11946.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Correctly report ``requested_extras`` in the installation report when extras are
2+
specified for a local directory installation.

src/pip/_internal/resolution/resolvelib/candidates.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,15 @@ def make_install_req_from_link(
7171
)
7272
ireq.original_link = template.original_link
7373
ireq.link = link
74+
ireq.extras = template.extras
7475
return ireq
7576

7677

7778
def make_install_req_from_editable(
7879
link: Link, template: InstallRequirement
7980
) -> InstallRequirement:
8081
assert template.editable, "template not editable"
81-
return install_req_from_editable(
82+
ireq = install_req_from_editable(
8283
link.url,
8384
user_supplied=template.user_supplied,
8485
comes_from=template.comes_from,
@@ -90,6 +91,8 @@ def make_install_req_from_editable(
9091
hash_options=template.hash_options,
9192
config_settings=template.config_settings,
9293
)
94+
ireq.extras = template.extras
95+
return ireq
9396

9497

9598
def _make_install_req_from_dist(

tests/functional/test_install_report.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import textwrap
23
from pathlib import Path
34
from typing import Any, Dict
45

@@ -178,6 +179,97 @@ def test_install_report_vcs_editable(
178179
assert pip_test_package_report["download_info"]["dir_info"]["editable"] is True
179180

180181

182+
@pytest.mark.network
183+
def test_install_report_local_path_with_extras(
184+
script: PipTestEnvironment, tmp_path: Path, shared_data: TestData
185+
) -> None:
186+
"""Test report remote editable."""
187+
project_path = tmp_path / "pkga"
188+
project_path.mkdir()
189+
project_path.joinpath("pyproject.toml").write_text(
190+
textwrap.dedent(
191+
"""\
192+
[project]
193+
name = "pkga"
194+
version = "1.0"
195+
196+
[project.optional-dependencies]
197+
test = ["simple"]
198+
"""
199+
)
200+
)
201+
report_path = tmp_path / "report.json"
202+
script.pip(
203+
"install",
204+
"--dry-run",
205+
"--no-build-isolation",
206+
"--no-index",
207+
"--find-links",
208+
str(shared_data.root / "packages/"),
209+
"--report",
210+
str(report_path),
211+
str(project_path) + "[test]",
212+
)
213+
report = json.loads(report_path.read_text())
214+
assert len(report["install"]) == 2
215+
pkga_report = report["install"][0]
216+
assert pkga_report["metadata"]["name"] == "pkga"
217+
assert pkga_report["is_direct"] is True
218+
assert pkga_report["requested"] is True
219+
assert pkga_report["requested_extras"] == ["test"]
220+
simple_report = report["install"][1]
221+
assert simple_report["metadata"]["name"] == "simple"
222+
assert simple_report["is_direct"] is False
223+
assert simple_report["requested"] is False
224+
assert "requested_extras" not in simple_report
225+
226+
227+
@pytest.mark.network
228+
def test_install_report_editable_local_path_with_extras(
229+
script: PipTestEnvironment, tmp_path: Path, shared_data: TestData
230+
) -> None:
231+
"""Test report remote editable."""
232+
project_path = tmp_path / "pkga"
233+
project_path.mkdir()
234+
project_path.joinpath("pyproject.toml").write_text(
235+
textwrap.dedent(
236+
"""\
237+
[project]
238+
name = "pkga"
239+
version = "1.0"
240+
241+
[project.optional-dependencies]
242+
test = ["simple"]
243+
"""
244+
)
245+
)
246+
report_path = tmp_path / "report.json"
247+
script.pip(
248+
"install",
249+
"--dry-run",
250+
"--no-build-isolation",
251+
"--no-index",
252+
"--find-links",
253+
str(shared_data.root / "packages/"),
254+
"--report",
255+
str(report_path),
256+
"--editable",
257+
str(project_path) + "[test]",
258+
)
259+
report = json.loads(report_path.read_text())
260+
assert len(report["install"]) == 2
261+
pkga_report = report["install"][0]
262+
assert pkga_report["metadata"]["name"] == "pkga"
263+
assert pkga_report["is_direct"] is True
264+
assert pkga_report["requested"] is True
265+
assert pkga_report["requested_extras"] == ["test"]
266+
simple_report = report["install"][1]
267+
assert simple_report["metadata"]["name"] == "simple"
268+
assert simple_report["is_direct"] is False
269+
assert simple_report["requested"] is False
270+
assert "requested_extras" not in simple_report
271+
272+
181273
def test_install_report_to_stdout(
182274
script: PipTestEnvironment, shared_data: TestData
183275
) -> None:

0 commit comments

Comments
 (0)