Skip to content

Commit

Permalink
Merge pull request #8924 from uranusjr/new-resolver-try-user-requeste…
Browse files Browse the repository at this point in the history
…d-combinations-first
  • Loading branch information
pradyunsg authored Sep 29, 2020
2 parents b98cf9c + df6d3c7 commit 428a790
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions news/8924.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
New resolver: Tweak resolution logic to improve user experience when
user-supplied requirements conflict.
17 changes: 12 additions & 5 deletions src/pip/_internal/resolution/resolvelib/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(
self._constraints = constraints
self._ignore_dependencies = ignore_dependencies
self._upgrade_strategy = upgrade_strategy
self.user_requested = user_requested
self._user_requested = user_requested

def _sort_matches(self, matches):
# type: (Iterable[Candidate]) -> Sequence[Candidate]
Expand Down Expand Up @@ -84,7 +84,7 @@ def _eligible_for_upgrade(name):
if self._upgrade_strategy == "eager":
return True
elif self._upgrade_strategy == "only-if-needed":
return (name in self.user_requested)
return (name in self._user_requested)
return False

def sort_key(c):
Expand Down Expand Up @@ -115,11 +115,18 @@ def get_preference(
self,
resolution, # type: Optional[Candidate]
candidates, # type: Sequence[Candidate]
information # type: Sequence[Tuple[Requirement, Candidate]]
information # type: Sequence[Tuple[Requirement, Optional[Candidate]]]
):
# type: (...) -> Any
# Use the "usual" value for now
return len(candidates)
"""Return a sort key to determine what dependency to look next.
A smaller value makes a dependency higher priority. We put direct
(user-requested) dependencies first since they may contain useful
user-specified version ranges. Users tend to expect us to catch
problems in them early as well.
"""
transitive = all(parent is not None for _, parent in information)
return (transitive, len(candidates))

def find_matches(self, requirements):
# type: (Sequence[Requirement]) -> Iterable[Candidate]
Expand Down

0 comments on commit 428a790

Please sign in to comment.