31 UnsupportedPythonVersion,
42 check_invalid_constraint_type,
50from .base
import Candidate, CandidateVersion, Constraint, Requirement
51from .candidates
import (
52 AlreadyInstalledCandidate,
57 RequiresPythonCandidate,
60from .found_candidates
import FoundCandidates, IndexCandidateInfo
61from .requirements
import (
63 RequiresPythonRequirement,
65 UnsatisfiableRequirement,
69 from typing
import Protocol
72 requirement: RequiresPythonRequirement
83 requirements: List[Requirement]
84 constraints: Dict[str, Constraint]
85 user_requested: Dict[str, int]
91 finder: PackageFinder,
92 preparer: RequirementPreparer,
93 make_install_req: InstallRequirementProvider,
94 wheel_cache: Optional[WheelCache],
96 force_reinstall: bool,
97 ignore_installed: bool,
98 ignore_requires_python: bool,
99 py_version_info: Optional[Tuple[int, ...]] =
None,
110 self._build_failures: Cache[InstallationError] = {}
111 self._link_candidate_cache: Cache[LinkCandidate] = {}
112 self._editable_candidate_cache: Cache[EditableCandidate] = {}
113 self._installed_candidate_cache: Dict[str, AlreadyInstalledCandidate] = {}
114 self._extras_candidate_cache: Dict[
115 Tuple[int, FrozenSet[str]], ExtrasCandidate
118 if not ignore_installed:
119 env = get_default_environment()
137 msg = f
"{link.filename} is not a supported wheel on this platform."
141 self, base: BaseCandidate, extras: FrozenSet[str]
142 ) -> ExtrasCandidate:
143 cache_key = (id(base), extras)
145 candidate = self._extras_candidate_cache[cache_key]
148 self._extras_candidate_cache[cache_key] = candidate
153 dist: BaseDistribution,
154 extras: FrozenSet[str],
155 template: InstallRequirement,
169 extras: FrozenSet[str],
170 template: InstallRequirement,
171 name: Optional[NormalizedName],
172 version: Optional[CandidateVersion],
173 ) -> Optional[Candidate]:
177 if link
in self._build_failures:
183 if link
not in self._editable_candidate_cache:
192 except MetadataInconsistent
as e:
194 "Discarding [blue underline]%s[/]: [yellow]%s[reset]",
197 extra={
"markup":
True},
199 self._build_failures[link] = e
202 base: BaseCandidate = self._editable_candidate_cache[link]
204 if link
not in self._link_candidate_cache:
213 except MetadataInconsistent
as e:
215 "Discarding [blue underline]%s[/]: [yellow]%s[reset]",
218 extra={
"markup":
True},
220 self._build_failures[link] = e
222 base = self._link_candidate_cache[link]
230 ireqs: Sequence[InstallRequirement],
231 specifier: SpecifierSet,
233 prefers_installed: bool,
234 incompatible_ids: Set[int],
235 ) -> Iterable[Candidate]:
244 assert template.req,
"Candidates found on index must be PEP 508"
249 assert ireq.req,
"Candidates found on index must be PEP 508"
255 """Get the candidate for the currently-installed version."""
274 if id(candidate)
in incompatible_ids:
279 result = self.
_finder.find_best_candidate(
291 def is_pinned(specifier: SpecifierSet) -> bool:
302 pinned = is_pinned(specifier)
319 iter_index_candidate_infos,
327 base_requirements: Iterable[Requirement],
328 extras: FrozenSet[str],
329 ) -> Iterator[Candidate]:
330 """Produce explicit candidates from the base given an extra-ed package.
332 :param base_requirements: Requirements known to the resolver. The
333 requirements are guaranteed to not have extras.
334 :param extras: The extras to inject into the explicit requirements'
337 for req
in base_requirements:
339 if lookup_cand
is None:
343 base_cand = as_base_candidate(lookup_cand)
344 assert base_cand
is not None,
"no extras here"
350 constraint: Constraint,
351 template: InstallRequirement,
352 ) -> Iterator[Candidate]:
353 """Produce explicit candidates from constraints.
355 This creates "fake" InstallRequirement objects that are basically clones
356 of what "should" be the template, but with original_link set to link.
363 template=install_req_from_link_and_ireq(link, template),
364 name=canonicalize_name(identifier),
373 requirements: Mapping[str, Iterable[Requirement]],
374 incompatibilities: Mapping[str, Iterator[Candidate]],
375 constraint: Constraint,
376 prefers_installed: bool,
377 ) -> Iterable[Candidate]:
379 explicit_candidates: Set[Candidate] = set()
380 ireqs: List[InstallRequirement] = []
381 for req
in requirements[identifier]:
391 parsed_requirement = get_requirement(identifier)
412 except UnsupportedWheel:
423 if not explicit_candidates:
434 for c
in explicit_candidates
435 if id(c)
not in incompat_ids
441 self, ireq: InstallRequirement, requested_extras: Iterable[str]
442 ) -> Optional[Requirement]:
445 "Ignoring %s: markers '%s' don't match your environment",
473 self, root_ireqs: List[InstallRequirement]
474 ) -> CollectedRootRequirements:
479 problem = check_invalid_constraint_type(ireq)
484 assert ireq.name,
"Constraint must be named"
503 self, candidate: Candidate
504 ) -> ExplicitRequirement:
510 comes_from: Optional[InstallRequirement],
511 requested_extras: Iterable[str] = (),
512 ) -> Optional[Requirement]:
518 specifier: SpecifierSet,
519 ) -> Optional[Requirement]:
523 if not str(specifier):
528 self, link: Link, name: Optional[str]
529 ) -> Optional[CacheEntry]:
530 """Look up the link in the wheel cache.
532 If ``preparer.require_hashes`` is True, don't use the wheel cache,
533 because cached wheels, always built locally, have different hashes
534 than the files downloaded from the index server and thus throw false
535 hash mismatches. Furthermore, cached wheels at present have
536 nondeterministic contents due to file modification times.
543 supported_tags=get_supported(),
568 f
"Will not install to the user site because it will lack "
569 f
"sys.path precedence to {dist.raw_name} in {dist.location}"
575 self, causes: Sequence[
"ConflictCause"]
576 ) -> UnsupportedPythonVersion:
577 assert causes,
"Requires-Python error reported with no cause"
584 f
"Package {causes[0].parent.name!r} requires a different "
585 f
"Python: {version} not in {specifier!r}"
589 message = f
"Packages require a different Python. {version} not in:"
593 message += f
"\n{specifier!r} (required by {package})"
597 self, req: Requirement, parent: Optional[Candidate]
598 ) -> DistributionNotFound:
602 req_disp = f
"{req} (from {parent.name})"
605 skipped_by_requires_python = self.
_finder.requires_python_skipped_reasons()
606 versions = [str(v)
for v
in sorted({
c.version for c
in cands})]
608 if skipped_by_requires_python:
610 "Ignored the following versions that require a different python "
612 "; ".join(skipped_by_requires_python)
or "none",
615 "Could not find a version that satisfies the requirement %s "
616 "(from versions: %s)",
618 ", ".join(versions)
or "none",
620 if str(req) ==
"requirements.txt":
622 "HINT: You are attempting to install a package literally "
623 'named "requirements.txt" (which cannot exist). Consider '
624 "using the '-r' flag to install the packages listed in "
632 e:
"ResolutionImpossible[Requirement, Candidate]",
633 constraints: Dict[str, Constraint],
634 ) -> InstallationError:
635 assert e.causes,
"Installation error reported with no cause"
639 requires_python_causes = [
645 if requires_python_causes:
649 cast(
"Sequence[ConflictCause]", requires_python_causes),
670 return ", ".join(parts[:-1]) +
" and " + parts[-1]
675 return f
"{parent.name}=={parent.version}"
692 info =
"the requested packages"
695 "Cannot install {} because these package versions "
696 "have conflicting dependencies.".format(info)
699 msg =
"\nThe conflict is caused by:"
701 relevant_constraints = set()
707 msg = msg + f
"{parent.name} {parent.version} depends on "
709 msg = msg +
"The user requested "
711 for key
in relevant_constraints:
712 spec = constraints[key].specifier
713 msg += f
"\n The user requested (constraint) {key}{spec}"
718 +
"To fix this you could try to:\n"
719 +
"1. loosen the range of package versions you've specified\n"
720 +
"2. remove package versions to allow pip attempt to solve "
721 +
"the dependency conflict\n"
727 "ResolutionImpossible: for help visit "
728 "https://pip.pypa.io/en/latest/topics/dependency-resolution/"
729 "#dealing-with-dependency-conflicts"
ExplicitRequirement make_requirement_from_candidate(self, Candidate candidate)
CollectedRootRequirements collect_root_requirements(self, List[InstallRequirement] root_ireqs)
Iterable[Candidate] _iter_found_candidates(self, Sequence[InstallRequirement] ireqs, SpecifierSet specifier, Hashes hashes, bool prefers_installed, Set[int] incompatible_ids)
InstallationError get_installation_error(self, "ResolutionImpossible[Requirement, Candidate]" e, Dict[str, Constraint] constraints)
None _fail_if_link_is_unsupported_wheel(self, Link link)
Optional[Requirement] _make_requirement_from_install_req(self, InstallRequirement ireq, Iterable[str] requested_extras)
DistributionNotFound _report_single_requirement_conflict(self, Requirement req, Optional[Candidate] parent)
Iterator[Candidate] _iter_explicit_candidates_from_base(self, Iterable[Requirement] base_requirements, FrozenSet[str] extras)
Optional[BaseDistribution] get_dist_to_uninstall(self, Candidate candidate)
Optional[Requirement] make_requirement_from_spec(self, str specifier, Optional[InstallRequirement] comes_from, Iterable[str] requested_extras=())
Optional[Requirement] make_requires_python_requirement(self, SpecifierSet specifier)
Iterable[Candidate] find_candidates(self, str identifier, Mapping[str, Iterable[Requirement]] requirements, Mapping[str, Iterator[Candidate]] incompatibilities, Constraint constraint, bool prefers_installed)
Iterator[Candidate] _iter_candidates_from_constraints(self, str identifier, Constraint constraint, InstallRequirement template)
UnsupportedPythonVersion _report_requires_python_error(self, Sequence["ConflictCause"] causes)
Optional[Candidate] _make_candidate_from_link(self, Link link, FrozenSet[str] extras, InstallRequirement template, Optional[NormalizedName] name, Optional[CandidateVersion] version)
bool force_reinstall(self)
None __init__(self, PackageFinder finder, RequirementPreparer preparer, InstallRequirementProvider make_install_req, Optional[WheelCache] wheel_cache, bool use_user_site, bool force_reinstall, bool ignore_installed, bool ignore_requires_python, Optional[Tuple[int,...]] py_version_info=None)
_make_install_req_from_spec
_make_candidate_from_link
Optional[CacheEntry] get_wheel_cache_entry(self, Link link, Optional[str] name)
Candidate _make_candidate_from_dist(self, BaseDistribution dist, FrozenSet[str] extras, InstallRequirement template)
ExtrasCandidate _make_extras_candidate(self, BaseCandidate base, FrozenSet[str] extras)