Skip to content

Commit e7f52d0

Browse files
committed
Clarify get_preference docs
1 parent de28f96 commit e7f52d0

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

docs/html/topics/more-dependency-resolution.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,22 @@ Pip's current implementation of the provider implements
160160

161161
* If Requires-Python is present only consider that
162162
* If there are causes of resolution conflict (backtrack causes) then
163-
only consider them until there are no longer any resolution conflicts
164-
165-
Pip's current implementation of the provider implements `get_preference` as
166-
follows:
167-
168-
* Prefer if any of the known requirements is "direct", e.g. points to an
169-
explicit URL.
170-
* If equal, prefer if any requirement is "pinned", i.e. contains
171-
operator ``===`` or ``==`` without a wildcard.
172-
* Prefer requirements that are "upper-bounded" using operators that do
173-
not allow all future versions, i.e. ``<``, ``<=``, ``~=``, and ``==``
174-
with a wildcard.
175-
* Order user-specified requirements by the order they are specified.
176-
* If equal, prefers "non-free" requirements, i.e. contains at least one
163+
only consider them until there are no longer any resolution conflicts
164+
165+
Pip's current implementation of the provider implements `get_preference`
166+
for known requirements with the following preferences in following order:
167+
168+
* Any requirement that is "direct", e.g., points to an explicit URL.
169+
* Any requirement that is "pinned", i.e., contains the operator ``===``
170+
or ``==`` without a wildcard.
171+
* Any requirement that imposes an upper version limit, i.e., contains the
172+
operator ``<``, ``<=``, ``~=``, or ``==`` with a wildcard. Because
173+
pip prioritizes the latest version, preferring explicit upper bounds
174+
can rule out infeasible candidates sooner. This does not imply that
175+
upper bounds are good practice; they can make dependency management
176+
and resolution harder.
177+
* Order user-specified requirements as they are specified, placing
178+
other requirements afterward.
179+
* Any "non-free" requirement, i.e., one that contains at least one
177180
operator, such as ``>=`` or ``!=``.
178-
* If equal, order alphabetically for consistency (helps debuggability).
181+
* Alphabetical order for consistency (aids debuggability).

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,20 @@ def get_preference(
161161
162162
Currently pip considers the following in order:
163163
164-
* Prefer if any of the known requirements is "direct", e.g. points to an
165-
explicit URL.
166-
* If equal, prefer if any requirement is "pinned", i.e. contains
167-
operator ``===`` or ``==`` without a wildcard.
168-
* Prefer requirements that are "upper-bounded" using operators that do
169-
not allow all future versions, i.e. ``<``, ``<=``, ``~=``, and ``==``
170-
with a wildcard.
171-
* Order user-specified requirements by the order they are specified.
172-
* If equal, prefers "non-free" requirements, i.e. contains at least one
164+
* Any requirement that is "direct", e.g., points to an explicit URL.
165+
* Any requirement that is "pinned", i.e., contains the operator ``===``
166+
or ``==`` without a wildcard.
167+
* Any requirement that imposes an upper version limit, i.e., contains the
168+
operator ``<``, ``<=``, ``~=``, or ``==`` with a wildcard. Because
169+
pip prioritizes the latest version, preferring explicit upper bounds
170+
can rule out infeasible candidates sooner. This does not imply that
171+
upper bounds are good practice; they can make dependency management
172+
and resolution harder.
173+
* Order user-specified requirements as they are specified, placing
174+
other requirements afterward.
175+
* Any "non-free" requirement, i.e., one that contains at least one
173176
operator, such as ``>=`` or ``!=``.
174-
* If equal, order alphabetically for consistency (helps debuggability).
177+
* Alphabetical order for consistency (aids debuggability).
175178
"""
176179
try:
177180
next(iter(information[identifier]))

0 commit comments

Comments
 (0)