From a9ef2dee158e74afe520b9709939152ffae7921b Mon Sep 17 00:00:00 2001 From: Nadav Wexler Date: Mon, 2 Aug 2021 16:24:26 +0300 Subject: [PATCH] linting fixes --- .../resolution/resolvelib/factory.py | 137 +++++++++--------- .../resolution/resolvelib/resolver.py | 6 +- 2 files changed, 75 insertions(+), 68 deletions(-) diff --git a/src/pip/_internal/resolution/resolvelib/factory.py b/src/pip/_internal/resolution/resolvelib/factory.py index 7c0d3c3eaa5..1f8287b0414 100644 --- a/src/pip/_internal/resolution/resolvelib/factory.py +++ b/src/pip/_internal/resolution/resolvelib/factory.py @@ -69,11 +69,11 @@ if TYPE_CHECKING: from typing import Protocol - class ConflictCause(Protocol): requirement: RequiresPythonRequirement parent: Candidate + logger = logging.getLogger(__name__) C = TypeVar("C") @@ -88,16 +88,16 @@ class CollectedRootRequirements(NamedTuple): class Factory: def __init__( - self, - finder: PackageFinder, - preparer: RequirementPreparer, - make_install_req: InstallRequirementProvider, - wheel_cache: Optional[WheelCache], - use_user_site: bool, - force_reinstall: bool, - ignore_installed: bool, - ignore_requires_python: bool, - py_version_info: Optional[Tuple[int, ...]] = None, + self, + finder: PackageFinder, + preparer: RequirementPreparer, + make_install_req: InstallRequirementProvider, + wheel_cache: Optional[WheelCache], + use_user_site: bool, + force_reinstall: bool, + ignore_installed: bool, + ignore_requires_python: bool, + py_version_info: Optional[Tuple[int, ...]] = None, ) -> None: self._finder = finder self.preparer = preparer @@ -139,7 +139,7 @@ def _fail_if_link_is_unsupported_wheel(self, link: Link) -> None: raise UnsupportedWheel(msg) def _make_extras_candidate( - self, base: BaseCandidate, extras: FrozenSet[str] + self, base: BaseCandidate, extras: FrozenSet[str] ) -> ExtrasCandidate: cache_key = (id(base), extras) try: @@ -150,10 +150,10 @@ def _make_extras_candidate( return candidate def _make_candidate_from_dist( - self, - dist: BaseDistribution, - extras: FrozenSet[str], - template: InstallRequirement, + self, + dist: BaseDistribution, + extras: FrozenSet[str], + template: InstallRequirement, ) -> Candidate: try: base = self._installed_candidate_cache[dist.canonical_name] @@ -168,12 +168,12 @@ def _make_candidate_from_dist( return self._make_extras_candidate(base, extras) def _make_candidate_from_link( - self, - link: Link, - extras: FrozenSet[str], - template: InstallRequirement, - name: Optional[NormalizedName], - version: Optional[CandidateVersion], + self, + link: Link, + extras: FrozenSet[str], + template: InstallRequirement, + name: Optional[NormalizedName], + version: Optional[CandidateVersion], ) -> Optional[Candidate]: # TODO: Check already installed candidate, and use it if the link and # editable flag match. @@ -219,12 +219,12 @@ def _make_candidate_from_link( return self._make_extras_candidate(base, extras) def _iter_found_candidates( - self, - ireqs: Sequence[InstallRequirement], - specifier: SpecifierSet, - hashes: Hashes, - prefers_installed: bool, - incompatible_ids: Set[int], + self, + ireqs: Sequence[InstallRequirement], + specifier: SpecifierSet, + hashes: Hashes, + prefers_installed: bool, + incompatible_ids: Set[int], ) -> Iterable[Candidate]: if not ireqs: return () @@ -303,9 +303,9 @@ def iter_index_candidate_infos() -> Iterator[IndexCandidateInfo]: ) def _iter_explicit_candidates_from_base( - self, - base_requirements: Iterable[Requirement], - extras: FrozenSet[str], + self, + base_requirements: Iterable[Requirement], + extras: FrozenSet[str], ) -> Iterator[Candidate]: """Produce explicit candidates from the base given an extra-ed package. @@ -325,10 +325,10 @@ def _iter_explicit_candidates_from_base( yield self._make_extras_candidate(base_cand, extras) def _iter_candidates_from_constraints( - self, - identifier: str, - constraint: Constraint, - template: InstallRequirement, + self, + identifier: str, + constraint: Constraint, + template: InstallRequirement, ) -> Iterator[Candidate]: """Produce explicit candidates from constraints. @@ -348,12 +348,12 @@ def _iter_candidates_from_constraints( yield candidate def find_candidates( - self, - identifier: str, - requirements: Mapping[str, Iterator[Requirement]], - incompatibilities: Mapping[str, Iterator[Candidate]], - constraint: Constraint, - prefers_installed: bool, + self, + identifier: str, + requirements: Mapping[str, Iterator[Requirement]], + incompatibilities: Mapping[str, Iterator[Candidate]], + constraint: Constraint, + prefers_installed: bool, ) -> Iterable[Candidate]: # Collect basic lookup information from the requirements. explicit_candidates: Set[Candidate] = set() @@ -413,12 +413,12 @@ def find_candidates( c for c in explicit_candidates if id(c) not in incompat_ids - and constraint.is_satisfied_by(c) - and all(req.is_satisfied_by(c) for req in requirements[identifier]) + and constraint.is_satisfied_by(c) + and all(req.is_satisfied_by(c) for req in requirements[identifier]) ) def _make_requirement_from_install_req( - self, ireq: InstallRequirement, requested_extras: Iterable[str] + self, ireq: InstallRequirement, requested_extras: Iterable[str] ) -> Optional[Requirement]: if not ireq.match_markers(requested_extras): logger.info( @@ -450,7 +450,7 @@ def _make_requirement_from_install_req( return self.make_requirement_from_candidate(cand) def collect_root_requirements( - self, root_ireqs: List[InstallRequirement] + self, root_ireqs: List[InstallRequirement] ) -> CollectedRootRequirements: collected = CollectedRootRequirements([], {}, {}) for i, ireq in enumerate(root_ireqs): @@ -480,28 +480,28 @@ def collect_root_requirements( return collected def make_requirement_from_candidate( - self, candidate: Candidate + self, candidate: Candidate ) -> ExplicitRequirement: return ExplicitRequirement(candidate) def make_requirement_from_spec( - self, - specifier: str, - comes_from: InstallRequirement, - requested_extras: Iterable[str] = (), + self, + specifier: str, + comes_from: InstallRequirement, + requested_extras: Iterable[str] = (), ) -> Optional[Requirement]: ireq = self._make_install_req_from_spec(specifier, comes_from) return self._make_requirement_from_install_req(ireq, requested_extras) def make_requires_python_requirement( - self, specifier: Optional[SpecifierSet] + self, specifier: Optional[SpecifierSet] ) -> Optional[Requirement]: if self._ignore_requires_python or specifier is None: return None return RequiresPythonRequirement(specifier, self._python_candidate) def get_wheel_cache_entry( - self, link: Link, name: Optional[str] + self, link: Link, name: Optional[str] ) -> Optional[CacheEntry]: """Look up the link in the wheel cache. @@ -548,7 +548,7 @@ def get_dist_to_uninstall(self, candidate: Candidate) -> Optional[BaseDistributi return None def _report_requires_python_error( - self, causes: Sequence["ConflictCause"] + self, causes: Sequence["ConflictCause"] ) -> UnsupportedPythonVersion: assert causes, "Requires-Python error reported with no cause" @@ -570,7 +570,7 @@ def _report_requires_python_error( return UnsupportedPythonVersion(message) def _report_single_requirement_conflict( - self, req: Requirement, parent: Optional[Candidate] + self, req: Requirement, parent: Optional[Candidate] ) -> DistributionNotFound: if parent is None: req_disp = str(req) @@ -597,9 +597,9 @@ def _report_single_requirement_conflict( return DistributionNotFound(f"No matching distribution found for {req}") def get_installation_error( - self, - e: "ResolutionImpossible[Requirement, Candidate]", - constraints: Dict[str, Constraint], + self, + e: "ResolutionImpossible[Requirement, Candidate]", + constraints: Dict[str, Constraint], ) -> InstallationError: failure_causes = e.causes @@ -631,12 +631,12 @@ def get_installation_error( logger.critical(self.triggers_message(failure_causes)) msg = ( - self.causes_message(constraints, failure_causes) - + "\n\n" - + "To fix this you could try to:\n" - + "1. loosen the range of package versions you've specified\n" - + "2. remove package versions to allow pip attempt to solve " - + "the dependency conflict\n" + self.causes_message(constraints, failure_causes) + + "\n\n" + + "To fix this you could try to:\n" + + "1. loosen the range of package versions you've specified\n" + + "2. remove package versions to allow pip attempt to solve " + + "the dependency conflict\n" ) logger.info(msg) @@ -648,7 +648,9 @@ def get_installation_error( ) def get_backtracking_reason_message(self, backtracking_causes, constraints): - requires_python_causes = self.extract_requires_python_causes(backtracking_causes) + requires_python_causes = self.extract_requires_python_causes( + backtracking_causes + ) if requires_python_causes or len(backtracking_causes) == 1: # no message when python causes or a single failure, since this is probably a genuine problem return @@ -656,8 +658,9 @@ def get_backtracking_reason_message(self, backtracking_causes, constraints): # OK, we now have a list of requirements that can't all be # satisfied at once. - return (self.triggers_message(backtracking_causes) + - self.causes_message(constraints, backtracking_causes)) + return self.triggers_message(backtracking_causes) + self.causes_message( + constraints, backtracking_causes + ) @staticmethod def causes_message(constraints, failure_causes): @@ -717,5 +720,5 @@ def extract_requires_python_causes(self, failure_causes): cause for cause in failure_causes if isinstance(cause.requirement, RequiresPythonRequirement) - and not cause.requirement.is_satisfied_by(self._python_candidate) + and not cause.requirement.is_satisfied_by(self._python_candidate) ] diff --git a/src/pip/_internal/resolution/resolvelib/resolver.py b/src/pip/_internal/resolution/resolvelib/resolver.py index adff835c69e..d9c7e00eebb 100644 --- a/src/pip/_internal/resolution/resolvelib/resolver.py +++ b/src/pip/_internal/resolution/resolvelib/resolver.py @@ -84,7 +84,11 @@ def resolve( reporter: BaseReporter = PipDebuggingReporter() else: reporter = PipReporter( - functools.partial(self.factory.get_backtracking_reason_message, constraints=collected.constraints)) + functools.partial( + self.factory.get_backtracking_reason_message, + constraints=collected.constraints, + ) + ) resolver: RLResolver[Requirement, Candidate, str] = RLResolver( provider, reporter,