Skip to content

Commit

Permalink
# This is a combination of 14 commits.tree 962cf1d58cffa4bd5102aa4cc6…
Browse files Browse the repository at this point in the history
…c1adaedb8c3cc0

parent 02b4f86
author Damian <[email protected]> 1633754869 -0400
committer Damian <[email protected]> 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 (pypa#10263)

Co-authored-by: Tzu-ping Chung <[email protected]>
Co-authored-by: Pradyun Gedam <[email protected]>
# 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 pypa#4:

Change name to backtrack_causes
Create is_backtrack_cause function

# This is the commit message pypa#5:

Fix newlines

# This is the commit message pypa#6:

Typo Fix in Comment

# This is the commit message pypa#7:

Fix lint errors

# This is the commit message pypa#8:

Add News Item

# This is the commit message pypa#9:

Newline

# This is the commit message pypa#10:

Better news.

# This is the commit message pypa#11:

Fix known depths

# This is the commit message pypa#12:

Fix known depths

# This is the commit message pypa#13:

Fix known depths

# This is the commit message pypa#14:

This fix is in the wrong PR confusing matters
  • Loading branch information
notatallshaw committed Oct 9, 2021
1 parent 02b4f86 commit 142e002
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions news/10479.feature.rst
Original file line number Diff line number Diff line change
@@ -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.
22 changes: 20 additions & 2 deletions src/pip/_internal/resolution/resolvelib/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand All @@ -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,
Expand Down Expand Up @@ -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

0 comments on commit 142e002

Please sign in to comment.