Skip to content

Commit

Permalink
Also prefer requirements with non-empty specifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Dec 3, 2020
1 parent 4ad924a commit 82fe333
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/pip/_internal/resolution/resolvelib/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def get_preference(
Currently pip considers the followings in order:
* Prefer if any of the known requirements points to an explicit URL.
* If equal, prefer if any requirements contain `===` and `==`.
* If equal, prefer if any requirements contain ``===`` and ``==``.
* If equal, prefer if requirements include version constraints, e.g.
``>=`` and ``<``.
* If equal, prefer user-specified (non-transitive) requirements.
* If equal, order alphabetically for consistency (helps debuggability).
"""
Expand All @@ -90,14 +92,17 @@ def _get_restrictive_rating(requirements):
if any(cand is not None for cand in cands):
return 0
spec_sets = (ireq.specifier for ireq in ireqs if ireq)
operators = (
operators = [
specifier.operator
for spec_set in spec_sets
for specifier in spec_set
)
]
if any(op in ("==", "===") for op in operators):
return 1
return 2
if operators:
return 2
# A "bare" requirement without any version requirements.
return 3

restrictive = _get_restrictive_rating(req for req, _ in information)
transitive = all(parent is not None for _, parent in information)
Expand Down

0 comments on commit 82fe333

Please sign in to comment.