Sort applicable candidates before computing best candidate (#7332)

This commit is contained in:
Pradyun Gedam 2019-11-11 22:10:57 +05:30 committed by GitHub
commit 6c04feff1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View File

@ -187,12 +187,11 @@ user, and other user preferences, etc.
Specifically, the class has a ``get_applicable_candidates()`` method.
This accepts the ``InstallationCandidate`` objects resulting from the links
accepted by the ``LinkEvaluator`` class's ``evaluate_link()`` method, and
it further filters them to a list of "applicable" candidates.
accepted by the ``LinkEvaluator`` class's ``evaluate_link()`` method, filters
them to a list of "applicable" candidates and orders them by preference.
The ``CandidateEvaluator`` class also has a ``sort_best_candidate()`` method
that orders the applicable candidates by preference, and then returns the
best (i.e. most preferred).
that returns the best (i.e. most preferred) candidate.
Finally, the class has a ``compute_best_candidate()`` method that calls
``get_applicable_candidates()`` followed by ``sort_best_candidate()``, and

View File

@ -474,12 +474,14 @@ class CandidateEvaluator(object):
c for c in candidates if str(c.version) in versions
]
return filter_unallowed_hashes(
filtered_applicable_candidates = filter_unallowed_hashes(
candidates=applicable_candidates,
hashes=self._hashes,
project_name=self._project_name,
)
return sorted(filtered_applicable_candidates, key=self._sort_key)
def _sort_key(self, candidate):
# type: (InstallationCandidate) -> CandidateSortingKey
"""