From 142e002f088698becff7ea9b2482fcb12ea626ca Mon Sep 17 00:00:00 2001 From: Damian Date: Sat, 9 Oct 2021 00:47:49 -0400 Subject: [PATCH] # This is a combination of 14 commits.tree 962cf1d58cffa4bd5102aa4cc6c1adaedb8c3cc0 parent 02b4f864896ae60b342d317f7bfe5c0ad25b348b author Damian 1633754869 -0400 committer Damian 1633754892 -0400 # This is a combination of 13 commits. # This is the 1st commit message: Return a better error message if a `file:` URL is not found (#10263) Co-authored-by: Tzu-ping Chung Co-authored-by: Pradyun Gedam # This is the commit message #2: Prefer failure causes when backtracking # This is the commit message #3: This fix is in the wrong PR confusing matters # This is the commit message #4: Change name to backtrack_causes Create is_backtrack_cause function # This is the commit message #5: Fix newlines # This is the commit message #6: Typo Fix in Comment # This is the commit message #7: Fix lint errors # This is the commit message #8: Add News Item # This is the commit message #9: Newline # This is the commit message #10: Better news. # This is the commit message #11: Fix known depths # This is the commit message #12: Fix known depths # This is the commit message #13: Fix known depths # This is the commit message #14: This fix is in the wrong PR confusing matters --- news/10479.feature.rst | 1 + .../resolution/resolvelib/provider.py | 22 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 news/10479.feature.rst diff --git a/news/10479.feature.rst b/news/10479.feature.rst new file mode 100644 index 00000000000..e070c0e163a --- /dev/null +++ b/news/10479.feature.rst @@ -0,0 +1 @@ +New resolver: When backtracking prefer the dependencies which caused the most recent backtracking. In some cases this will significantly reduce the amount of backtracking required. diff --git a/src/pip/_internal/resolution/resolvelib/provider.py b/src/pip/_internal/resolution/resolvelib/provider.py index c2203933e40..f1d295aeb6a 100644 --- a/src/pip/_internal/resolution/resolvelib/provider.py +++ b/src/pip/_internal/resolution/resolvelib/provider.py @@ -71,7 +71,8 @@ def get_preference( identifier: str, resolutions: Mapping[str, Candidate], candidates: Mapping[str, Iterator[Candidate]], - information: Mapping[str, Iterable["PreferenceInformation"]], + information: Mapping[str, Iterator["PreferenceInformation"]], + backtrack_causes: Sequence["RequirementInformation"], ) -> "Preference": """Produce a sort key for given requirement based on preference. @@ -112,9 +113,9 @@ def get_preference( for _, parent in information[identifier] ) inferred_depth = min(d for d in parent_depths) + 1.0 + self._known_depths[identifier] = inferred_depth else: inferred_depth = 1.0 - self._known_depths[identifier] = inferred_depth requested_order = self._user_requested.get(identifier, math.inf) @@ -132,11 +133,17 @@ def get_preference( # while we work on "proper" branch pruning techniques. delay_this = identifier == "setuptools" + # Prefer the causes of backtracking on the assumption that the problem + # resolving the dependency tree is related to the failures that caused + # the backtracking + backtrack_cause = self.is_backtrack_cause(identifier, backtrack_causes) + return ( not requires_python, delay_this, not direct, not pinned, + not backtrack_cause, inferred_depth, requested_order, not unfree, @@ -195,3 +202,14 @@ def is_satisfied_by(self, requirement: Requirement, candidate: Candidate) -> boo def get_dependencies(self, candidate: Candidate) -> Sequence[Requirement]: with_requires = not self._ignore_dependencies return [r for r in candidate.iter_dependencies(with_requires) if r is not None] + + @staticmethod + def is_backtrack_cause( + identifier: str, backtrack_causes: Sequence["RequirementInformation"] + ) -> bool: + for backtrack_cause in backtrack_causes: + if identifier == backtrack_cause.requirement.name: + return True + if backtrack_cause.parent and identifier == backtrack_cause.parent.name: + return True + return False