Skip to content

Commit

Permalink
Merge pull request pypa#8924 from uranusjr/new-resolver-try-user-requ…
Browse files Browse the repository at this point in the history
…ested-combinations-first
  • Loading branch information
pradyunsg committed Oct 16, 2020
1 parent 99a6938 commit a025993
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 @@ -52,7 +52,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 @@ -93,7 +93,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 @@ -124,11 +124,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 a025993

Please sign in to comment.