-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Pull in typing information from ResolveLib #9699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Upgrade vendored resolvelib to 0.5.5. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import functools | ||
import logging | ||
import os | ||
from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple | ||
from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple, cast | ||
|
||
from pip._vendor.packaging.utils import canonicalize_name | ||
from pip._vendor.packaging.version import parse as parse_version | ||
from pip._vendor.resolvelib import BaseReporter, ResolutionImpossible | ||
from pip._vendor.resolvelib import Resolver as RLResolver | ||
from pip._vendor.resolvelib.resolvers import Result | ||
from pip._vendor.resolvelib.structs import DirectedGraph | ||
|
||
from pip._internal.cache import WheelCache | ||
from pip._internal.exceptions import InstallationError | ||
|
@@ -28,11 +28,14 @@ | |
from pip._internal.utils.filetypes import is_archive_file | ||
from pip._internal.utils.misc import dist_is_editable | ||
|
||
from .base import Constraint | ||
from .base import Candidate, Constraint, Requirement | ||
from .factory import Factory | ||
|
||
if TYPE_CHECKING: | ||
from pip._vendor.resolvelib.structs import DirectedGraph | ||
from pip._vendor.resolvelib.resolvers import Result as RLResult | ||
|
||
Result = RLResult[Requirement, Candidate, str] | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -114,7 +117,10 @@ def resolve(self, root_reqs, check_supported_wheels): | |
reporter = PipDebuggingReporter() # type: BaseReporter | ||
else: | ||
reporter = PipReporter() | ||
resolver = RLResolver(provider, reporter) | ||
resolver = RLResolver( | ||
provider, | ||
reporter, | ||
) # type: RLResolver[Requirement, Candidate, str] | ||
|
||
try: | ||
try_to_avoid_resolution_too_deep = 2000000 | ||
|
@@ -123,7 +129,10 @@ def resolve(self, root_reqs, check_supported_wheels): | |
) | ||
|
||
except ResolutionImpossible as e: | ||
error = self.factory.get_installation_error(e, constraints) | ||
error = self.factory.get_installation_error( | ||
cast("ResolutionImpossible[Requirement, Candidate]", e), | ||
constraints, | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a better way to handle the type of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nah, this is fine. |
||
raise error from e | ||
|
||
req_set = RequirementSet(check_supported_wheels=check_supported_wheels) | ||
|
@@ -148,7 +157,7 @@ def resolve(self, root_reqs, check_supported_wheels): | |
# The incoming distribution is editable, or different in | ||
# editable-ness to installation -- reinstall. | ||
ireq.should_reinstall = True | ||
elif candidate.source_link.is_file: | ||
elif candidate.source_link and candidate.source_link.is_file: | ||
# The incoming distribution is under file:// | ||
if candidate.source_link.is_wheel: | ||
# is a local wheel -- do nothing. | ||
|
@@ -236,7 +245,7 @@ def get_installation_order(self, req_set): | |
|
||
|
||
def get_topological_weights(graph, expected_node_count): | ||
# type: (DirectedGraph, int) -> Dict[Optional[str], int] | ||
# type: (DirectedGraph[Optional[str]], int) -> Dict[Optional[str], int] | ||
"""Assign weights to each node based on how "deep" they are. | ||
|
||
This implementation may change at any point in the future without prior | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
__version__: str | ||
|
||
from .providers import ( | ||
AbstractResolver as AbstractResolver, | ||
AbstractProvider as AbstractProvider, | ||
) | ||
from .reporters import BaseReporter as BaseReporter | ||
from .resolvers import ( | ||
InconsistentCandidate as InconsistentCandidate, | ||
RequirementsConflicted as RequirementsConflicted, | ||
Resolver as Resolver, | ||
ResolutionError as ResolutionError, | ||
ResolutionImpossible as ResolutionImpossible, | ||
ResolutionTooDeep as ResolutionTooDeep, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from typing import ( | ||
Any, | ||
Collection, | ||
Generic, | ||
Iterable, | ||
Mapping, | ||
Optional, | ||
Protocol, | ||
Sequence, | ||
Union, | ||
) | ||
|
||
from .reporters import BaseReporter | ||
from .resolvers import RequirementInformation | ||
from .structs import ( | ||
KT, | ||
RT, | ||
CT, | ||
IterableView, | ||
Matches, | ||
) | ||
|
||
class Preference(Protocol): | ||
def __lt__(self, __other: Any) -> bool: ... | ||
|
||
class AbstractProvider(Generic[RT, CT, KT]): | ||
def identify(self, requirement_or_candidate: Union[RT, CT]) -> KT: ... | ||
def get_preference( | ||
self, | ||
resolution: Optional[CT], | ||
candidates: IterableView[CT], | ||
information: Collection[RequirementInformation[RT, CT]], | ||
) -> Preference: ... | ||
def find_matches(self, requirements: Sequence[RT]) -> Matches: ... | ||
def is_satisfied_by(self, requirement: RT, candidate: CT) -> bool: ... | ||
def get_dependencies(self, candidate: CT) -> Iterable[RT]: ... | ||
|
||
class AbstractResolver(Generic[RT, CT, KT]): | ||
base_exception = Exception | ||
provider: AbstractProvider[RT, CT, KT] | ||
reporter: BaseReporter | ||
def __init__( | ||
self, provider: AbstractProvider[RT, CT, KT], reporter: BaseReporter | ||
): ... |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from typing import Any | ||
|
||
class BaseReporter: | ||
def starting(self) -> Any: ... | ||
def starting_round(self, index: int) -> Any: ... | ||
def ending_round(self, index: int, state: Any) -> Any: ... | ||
def ending(self, state: Any) -> Any: ... | ||
def adding_requirement(self, requirement: Any, parent: Any) -> Any: ... | ||
def backtracking(self, candidate: Any) -> Any: ... | ||
def pinning(self, candidate: Any) -> Any: ... |
Uh oh!
There was an error while loading. Please reload this page.