Skip to content

Commit 82fe333

Browse files
committed
Also prefer requirements with non-empty specifiers
1 parent 4ad924a commit 82fe333

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/pip/_internal/resolution/resolvelib/provider.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ def get_preference(
6464
Currently pip considers the followings in order:
6565
6666
* Prefer if any of the known requirements points to an explicit URL.
67-
* If equal, prefer if any requirements contain `===` and `==`.
67+
* If equal, prefer if any requirements contain ``===`` and ``==``.
68+
* If equal, prefer if requirements include version constraints, e.g.
69+
``>=`` and ``<``.
6870
* If equal, prefer user-specified (non-transitive) requirements.
6971
* If equal, order alphabetically for consistency (helps debuggability).
7072
"""
@@ -90,14 +92,17 @@ def _get_restrictive_rating(requirements):
9092
if any(cand is not None for cand in cands):
9193
return 0
9294
spec_sets = (ireq.specifier for ireq in ireqs if ireq)
93-
operators = (
95+
operators = [
9496
specifier.operator
9597
for spec_set in spec_sets
9698
for specifier in spec_set
97-
)
99+
]
98100
if any(op in ("==", "===") for op in operators):
99101
return 1
100-
return 2
102+
if operators:
103+
return 2
104+
# A "bare" requirement without any version requirements.
105+
return 3
101106

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

0 commit comments

Comments
 (0)