From ebc103bb173b726fc5c2cc40744bf0c54d6ccc14 Mon Sep 17 00:00:00 2001 From: Guillaume Seguin Date: Mon, 6 Jun 2022 11:39:20 -0700 Subject: [PATCH] Display dependency chain on each Collecting line This tremendously helps understand why a package is being fetched and can help investigate and fix dependency resolver backtracking issues when incoherent constraints/package sets are provided or when new versions of a package trigger a completely different backtracking strategy, leading to very hard to debug situations. --- news/C0DAB099-D9CB-438B-9091-146533DD4741.trivial.rst | 0 src/pip/_internal/operations/prepare.py | 9 +++++++++ 2 files changed, 9 insertions(+) create mode 100644 news/C0DAB099-D9CB-438B-9091-146533DD4741.trivial.rst 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..8ffae49e8b4 100644 --- a/src/pip/_internal/operations/prepare.py +++ b/src/pip/_internal/operations/prepare.py @@ -268,6 +268,15 @@ def _log_preparing_link(self, req: InstallRequirement) -> None: else: 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)