diff --git a/news/C0DAB099-D9CB-438B-9091-146533DD4741.trivial.rst b/news/C0DAB099-D9CB-438B-9091-146533DD4741.trivial.rst new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/pip/_internal/operations/prepare.py b/src/pip/_internal/operations/prepare.py index 80723fffe47..c6e0e6b5ef5 100644 --- a/src/pip/_internal/operations/prepare.py +++ b/src/pip/_internal/operations/prepare.py @@ -269,6 +269,16 @@ def _log_preparing_link(self, req: InstallRequirement) -> None: message = "Collecting %s" information = str(req.req or req) + # If we used req.req, inject requirement source if available (this + # would already be included if we used req directly) + if req.req and req.comes_from: + if isinstance(req.comes_from, str): + comes_from: Optional[str] = req.comes_from + else: + comes_from = req.comes_from.from_path() + if comes_from: + information += f" (from {comes_from})" + if (message, information) != self._previous_requirement_header: self._previous_requirement_header = (message, information) logger.info(message, information) diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py index 3bf2579ed4b..97cfc3dbb6a 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -2243,3 +2243,54 @@ def test_install_logs_pip_version_in_debug( result = script.pip("install", "-v", fake_package) pattern = "Using pip .* from .*" assert_re_match(pattern, result.stdout) + + +def test_install_pip_prints_req_chain_local(script: PipTestEnvironment) -> None: + """ + Test installing a local package with a dependency and check that the + dependency chain is reported. + """ + + req_path = script.scratch_path.joinpath("requirements.txt") + req_path.write_text("base==0.1.0") + + create_basic_wheel_for_package( + script, + "base", + "0.1.0", + depends=["dep"], + ) + dep_path = create_basic_wheel_for_package( + script, + "dep", + "0.1.0", + ) + + result = script.pip( + "install", + "--no-cache-dir", + "--no-index", + "--find-links", + script.scratch_path, + "-r", + req_path, + ) + assert f"Processing ./{os.path.basename(dep_path)} (from base==0.1.0->-r {req_path} (line 1))" in result.stdout + + +@pytest.mark.network +def test_install_pip_prints_req_chain_pypi(script: PipTestEnvironment) -> None: + """ + Test installing a package with a dependency from PyPI and check that the + dependency chain is reported. + """ + req_path = script.scratch_path.joinpath("requirements.txt") + req_path.write_text("Paste[openid]==1.7.5.1") + + result = script.pip( + "install", + "-r", + req_path, + ) + + assert f"Collecting python-openid (from Paste[openid]==1.7.5.1->-r {req_path} (line 1))" in result.stdout