16from .base
import Candidate, Constraint, Requirement
17from .candidates
import REQUIRES_PYTHON_IDENTIFIER
18from .factory
import Factory
24 PreferenceInformation = RequirementInformation[Requirement, Candidate]
26 _ProviderBase = AbstractProvider[Requirement, Candidate, str]
28 _ProviderBase = AbstractProvider
54 mapping: Mapping[str, V],
58 """Get item from a package name lookup mapping with a resolver identifier.
60 This extra logic is needed when the target mapping is keyed by package
61 name, which cannot be directly looked up with an identifier (which may
62 contain requested extras). Additional logic is added to also look up a value
63 by "cleaning up" the extras from the identifier.
65 if identifier
in mapping:
66 return mapping[identifier]
73 if open_bracket
and name
in mapping:
79 """Pip's provider implementation for resolvelib.
81 :params constraints: A mapping of constraints specified by the user. Keys
82 are canonicalized project names.
83 :params ignore_dependencies: Whether the user specified ``--no-deps``.
84 :params upgrade_strategy: The user-specified upgrade strategy.
85 :params user_requested: A set of canonicalized package names that the user
86 supplied for pip to install/upgrade.
92 constraints: Dict[str, Constraint],
93 ignore_dependencies: bool,
94 upgrade_strategy: str,
95 user_requested: Dict[str, int],
104 def identify(self, requirement_or_candidate: Union[Requirement, Candidate]) -> str:
110 resolutions: Mapping[str, Candidate],
111 candidates: Mapping[str, Iterator[Candidate]],
112 information: Mapping[str, Iterable[
"PreferenceInformation"]],
113 backtrack_causes: Sequence[
"PreferenceInformation"],
115 """Produce a sort key for given requirement based on preference.
117 The lower the return value is, the more preferred this group of
120 Currently pip considers the following in order:
122 * Prefer if any of the known requirements is "direct", e.g. points to an
124 * If equal, prefer if any requirement is "pinned", i.e. contains
125 operator ``===`` or ``==``.
126 * If equal, calculate an approximate "depth" and resolve requirements
127 closer to the user-specified requirements first. If the depth cannot
128 by determined (eg: due to no matching parents), it is considered
130 * Order user-specified requirements by the order they are specified.
131 * If equal, prefers "non-free" requirements, i.e. contains at least one
132 operator, such as ``>=`` or ``<``.
133 * If equal, order alphabetically for consistency (helps debuggability).
136 next(iter(information[identifier]))
137 except StopIteration:
140 has_information =
False
142 has_information =
True
146 candidate, ireqs =
zip(*lookups)
148 candidate, ireqs =
None, ()
153 for specifier
in specifier_set
156 direct = candidate
is not None
157 pinned =
any(op[:2] ==
"==" for op
in operators)
158 unfree = bool(operators)
166 self._known_depths[
parent.name]
if parent
is not None else 0.0
167 for _, parent
in information[identifier]
169 inferred_depth = min(d
for d
in parent_depths) + 1.0
174 self._known_depths[identifier] = inferred_depth
180 requires_python = identifier == REQUIRES_PYTHON_IDENTIFIER
201 requirements: Mapping[str, Iterator[Requirement]],
202 incompatibilities: Mapping[str, Iterator[Candidate]],
203 ) -> Iterable[Candidate]:
205 """Are upgrades allowed for this project?
207 This checks the upgrade strategy, and whether the project was one
208 that the user specified in the command line, in order to decide
209 whether we should upgrade if there's a newer version available.
211 (Note that we don't need access to the `--upgrade` flag, because
212 an upgrade strategy of "to-satisfy-only" means that `--upgrade`
223 return user_order
is not None
231 return self.
_factory.find_candidates(
232 identifier=identifier,
233 requirements=requirements,
234 constraint=constraint,
236 incompatibilities=incompatibilities,
248 identifier: str, backtrack_causes: Sequence[
"PreferenceInformation"]
250 for backtrack_cause
in backtrack_causes:
"Preference" get_preference(self, str identifier, Mapping[str, Candidate] resolutions, Mapping[str, Iterator[Candidate]] candidates, Mapping[str, Iterable["PreferenceInformation"]] information, Sequence["PreferenceInformation"] backtrack_causes)
bool is_backtrack_cause(str identifier, Sequence["PreferenceInformation"] backtrack_causes)
Iterable[Candidate] find_matches(self, str identifier, Mapping[str, Iterator[Requirement]] requirements, Mapping[str, Iterator[Candidate]] incompatibilities)
str identify(self, Union[Requirement, Candidate] requirement_or_candidate)
bool is_satisfied_by(self, Requirement requirement, Candidate candidate)
None __init__(self, Factory factory, Dict[str, Constraint] constraints, bool ignore_dependencies, str upgrade_strategy, Dict[str, int] user_requested)
Sequence[Requirement] get_dependencies(self, Candidate candidate)
Union[D, V] _get_with_identifier(Mapping[str, V] mapping, str identifier, D default)