-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
- Loading branch information
Showing
8 changed files
with
111 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import abc | ||
|
||
from pip._vendor.six import add_metaclass | ||
|
||
|
||
@add_metaclass(abc.ABCMeta) | ||
class AbstractStrategy: | ||
|
||
@abc.abstractmethod | ||
def get_preferred_candidate( | ||
self, | ||
resolution, # type: Optional[Candidate] | ||
candidates, # type: Sequence[Candidate] | ||
information, # type: Sequence[Tuple[Requirement, Candidate]] | ||
): | ||
# type: (...) -> int | ||
raise NotImplementedError() | ||
|
||
@abc.abstractmethod | ||
def sort_candidates(self, candidates): | ||
# type: (Sequence[Candidates]) -> Sequence[Candidate] | ||
raise NotImplementedError() | ||
|
||
|
||
class DefaultStrategy(AbstractStrategy): | ||
|
||
def get_preferred_candidate( | ||
self, | ||
resolution, # type: Optional[Candidate] | ||
candidates, # type: Sequence[Candidate] | ||
information, # type: Sequence[Tuple[Requirement, Candidate]] | ||
): | ||
# type: (...) -> int | ||
return len(candidates) | ||
|
||
def sort_candidates(self, candidates): | ||
# type: (Sequence[Candidate]) -> Sequence[Candidate] | ||
return reversed(candidates) | ||
|
||
|
||
class EarliestCompatible(AbstractStrategy): | ||
|
||
def get_preferred_candidate( | ||
self, | ||
resolution, # type: Optional[Candidate] | ||
candidates, # type: Sequence[Candidate] | ||
information, # type: Sequence[Tuple[Requirement, Candidate]] | ||
): | ||
# type: (...) -> int | ||
return 0 | ||
|
||
def sort_candidates(self, candidates): | ||
# type: (Sequence[Candidate]) -> Sequence[Candidate] | ||
return candidates | ||
|
||
|
||
def strategy_factory(name): | ||
# type: (str) -> AbstractStrategy | ||
f = { | ||
'earliest-compatible': EarliestCompatible, | ||
}.get(name, DefaultStrategy) | ||
return f() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters