Skip to content

Commit

Permalink
linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nadavwe committed Aug 2, 2021
1 parent 78b2fdd commit a9ef2de
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 68 deletions.
137 changes: 70 additions & 67 deletions src/pip/_internal/resolution/resolvelib/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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]
Expand All @@ -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.
Expand Down Expand Up @@ -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 ()
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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()
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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"

Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -648,16 +648,19 @@ 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

# 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):
Expand Down Expand Up @@ -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)
]
6 changes: 5 additions & 1 deletion src/pip/_internal/resolution/resolvelib/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a9ef2de

Please sign in to comment.