Skip to content

Commit 6c04fef

Browse files
authored
Sort applicable candidates before computing best candidate (#7332)
2 parents b580b74 + 997db00 commit 6c04fef

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

docs/html/development/architecture/package-finding.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,11 @@ user, and other user preferences, etc.
187187

188188
Specifically, the class has a ``get_applicable_candidates()`` method.
189189
This accepts the ``InstallationCandidate`` objects resulting from the links
190-
accepted by the ``LinkEvaluator`` class's ``evaluate_link()`` method, and
191-
it further filters them to a list of "applicable" candidates.
190+
accepted by the ``LinkEvaluator`` class's ``evaluate_link()`` method, filters
191+
them to a list of "applicable" candidates and orders them by preference.
192192

193193
The ``CandidateEvaluator`` class also has a ``sort_best_candidate()`` method
194-
that orders the applicable candidates by preference, and then returns the
195-
best (i.e. most preferred).
194+
that returns the best (i.e. most preferred) candidate.
196195

197196
Finally, the class has a ``compute_best_candidate()`` method that calls
198197
``get_applicable_candidates()`` followed by ``sort_best_candidate()``, and

src/pip/_internal/index/package_finder.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,14 @@ def get_applicable_candidates(
474474
c for c in candidates if str(c.version) in versions
475475
]
476476

477-
return filter_unallowed_hashes(
477+
filtered_applicable_candidates = filter_unallowed_hashes(
478478
candidates=applicable_candidates,
479479
hashes=self._hashes,
480480
project_name=self._project_name,
481481
)
482482

483+
return sorted(filtered_applicable_candidates, key=self._sort_key)
484+
483485
def _sort_key(self, candidate):
484486
# type: (InstallationCandidate) -> CandidateSortingKey
485487
"""

0 commit comments

Comments
 (0)