Skip to content

Commit 61e85bf

Browse files
authored
Merge pull request #11169 from iXce/display_collection_comes_from
Display dependency chain on each Collecting line
2 parents 5e20a7b + c546c99 commit 61e85bf

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

news/11169.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Display dependency chain on each Collecting/Processing log line.

src/pip/_internal/operations/prepare.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,16 @@ def _log_preparing_link(self, req: InstallRequirement) -> None:
270270
message = "Collecting %s"
271271
information = str(req.req or req)
272272

273+
# If we used req.req, inject requirement source if available (this
274+
# would already be included if we used req directly)
275+
if req.req and req.comes_from:
276+
if isinstance(req.comes_from, str):
277+
comes_from: Optional[str] = req.comes_from
278+
else:
279+
comes_from = req.comes_from.from_path()
280+
if comes_from:
281+
information += f" (from {comes_from})"
282+
273283
if (message, information) != self._previous_requirement_header:
274284
self._previous_requirement_header = (message, information)
275285
logger.info(message, information)

tests/functional/test_install.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,3 +2393,61 @@ def find_distributions(self, context=None):
23932393
result = script.pip("install", "example")
23942394

23952395
assert "Requirement already satisfied: example in <memory>" in result.stdout
2396+
2397+
2398+
def test_install_pip_prints_req_chain_local(script: PipTestEnvironment) -> None:
2399+
"""
2400+
Test installing a local package with a dependency and check that the
2401+
dependency chain is reported.
2402+
"""
2403+
2404+
req_path = script.scratch_path.joinpath("requirements.txt")
2405+
req_path.write_text("base==0.1.0")
2406+
2407+
create_basic_wheel_for_package(
2408+
script,
2409+
"base",
2410+
"0.1.0",
2411+
depends=["dep"],
2412+
)
2413+
dep_path = create_basic_wheel_for_package(
2414+
script,
2415+
"dep",
2416+
"0.1.0",
2417+
)
2418+
2419+
result = script.pip(
2420+
"install",
2421+
"--no-cache-dir",
2422+
"--no-index",
2423+
"--find-links",
2424+
script.scratch_path,
2425+
"-r",
2426+
req_path,
2427+
)
2428+
assert_re_match(
2429+
rf"Processing .*{re.escape(os.path.basename(dep_path))} "
2430+
rf"\(from base==0.1.0->-r {re.escape(str(req_path))} \(line 1\)\)",
2431+
result.stdout,
2432+
)
2433+
2434+
2435+
@pytest.mark.network
2436+
def test_install_pip_prints_req_chain_pypi(script: PipTestEnvironment) -> None:
2437+
"""
2438+
Test installing a package with a dependency from PyPI and check that the
2439+
dependency chain is reported.
2440+
"""
2441+
req_path = script.scratch_path.joinpath("requirements.txt")
2442+
req_path.write_text("Paste[openid]==1.7.5.1")
2443+
2444+
result = script.pip(
2445+
"install",
2446+
"-r",
2447+
req_path,
2448+
)
2449+
2450+
assert (
2451+
f"Collecting python-openid "
2452+
f"(from Paste[openid]==1.7.5.1->-r {req_path} (line 1))" in result.stdout
2453+
)

0 commit comments

Comments
 (0)