mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Add get_applicable_candidates(), and test.
This commit is contained in:
parent
b2389bf8c7
commit
4a9e306678
|
@ -507,22 +507,15 @@ class CandidateEvaluator(object):
|
||||||
self._prefer_binary = prefer_binary
|
self._prefer_binary = prefer_binary
|
||||||
self._supported_tags = supported_tags
|
self._supported_tags = supported_tags
|
||||||
|
|
||||||
def make_found_candidates(
|
def get_applicable_candidates(
|
||||||
self,
|
self,
|
||||||
candidates, # type: List[InstallationCandidate]
|
candidates, # type: List[InstallationCandidate]
|
||||||
specifier=None, # type: Optional[specifiers.BaseSpecifier]
|
specifier, # type: specifiers.BaseSpecifier
|
||||||
):
|
):
|
||||||
# type: (...) -> FoundCandidates
|
# type: (...) -> List[InstallationCandidate]
|
||||||
"""
|
"""
|
||||||
Create and return a `FoundCandidates` instance.
|
Return the applicable candidates from a list of candidates.
|
||||||
|
|
||||||
:param specifier: An optional object implementing `filter`
|
|
||||||
(e.g. `packaging.specifiers.SpecifierSet`) to filter applicable
|
|
||||||
versions.
|
|
||||||
"""
|
"""
|
||||||
if specifier is None:
|
|
||||||
specifier = specifiers.SpecifierSet()
|
|
||||||
|
|
||||||
# Using None infers from the specifier instead.
|
# Using None infers from the specifier instead.
|
||||||
allow_prereleases = self._allow_all_prereleases or None
|
allow_prereleases = self._allow_all_prereleases or None
|
||||||
versions = {
|
versions = {
|
||||||
|
@ -543,6 +536,28 @@ class CandidateEvaluator(object):
|
||||||
applicable_candidates = [
|
applicable_candidates = [
|
||||||
c for c in candidates if str(c.version) in versions
|
c for c in candidates if str(c.version) in versions
|
||||||
]
|
]
|
||||||
|
return applicable_candidates
|
||||||
|
|
||||||
|
def make_found_candidates(
|
||||||
|
self,
|
||||||
|
candidates, # type: List[InstallationCandidate]
|
||||||
|
specifier=None, # type: Optional[specifiers.BaseSpecifier]
|
||||||
|
):
|
||||||
|
# type: (...) -> FoundCandidates
|
||||||
|
"""
|
||||||
|
Create and return a `FoundCandidates` instance.
|
||||||
|
|
||||||
|
:param specifier: An optional object implementing `filter`
|
||||||
|
(e.g. `packaging.specifiers.SpecifierSet`) to filter applicable
|
||||||
|
versions.
|
||||||
|
"""
|
||||||
|
if specifier is None:
|
||||||
|
specifier = specifiers.SpecifierSet()
|
||||||
|
|
||||||
|
applicable_candidates = self.get_applicable_candidates(
|
||||||
|
candidates=candidates,
|
||||||
|
specifier=specifier,
|
||||||
|
)
|
||||||
|
|
||||||
return FoundCandidates(
|
return FoundCandidates(
|
||||||
candidates,
|
candidates,
|
||||||
|
|
|
@ -205,6 +205,23 @@ class TestCandidateEvaluator:
|
||||||
|
|
||||||
return candidate
|
return candidate
|
||||||
|
|
||||||
|
def test_get_applicable_candidates(self):
|
||||||
|
specifier = SpecifierSet('<= 1.11')
|
||||||
|
versions = ['1.10', '1.11', '1.12']
|
||||||
|
candidates = [
|
||||||
|
self.make_mock_candidate(version) for version in versions
|
||||||
|
]
|
||||||
|
evaluator = CandidateEvaluator.create()
|
||||||
|
actual = evaluator.get_applicable_candidates(
|
||||||
|
candidates, specifier=specifier,
|
||||||
|
)
|
||||||
|
expected_applicable = candidates[:2]
|
||||||
|
assert [str(c.version) for c in expected_applicable] == [
|
||||||
|
'1.10',
|
||||||
|
'1.11',
|
||||||
|
]
|
||||||
|
assert actual == expected_applicable
|
||||||
|
|
||||||
def test_make_found_candidates(self):
|
def test_make_found_candidates(self):
|
||||||
specifier = SpecifierSet('<= 1.11')
|
specifier = SpecifierSet('<= 1.11')
|
||||||
versions = ['1.10', '1.11', '1.12']
|
versions = ['1.10', '1.11', '1.12']
|
||||||
|
|
Loading…
Reference in a new issue