Skip to content

Commit 88ceab2

Browse files
committed
Upgrade resolvelib to 1.1.0
1 parent 4204359 commit 88ceab2

19 files changed

+612
-515
lines changed

news/resolvelib.vendor.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Upgrade resolvelib to 1.1.0

src/pip/_vendor/resolvelib/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
"ResolutionTooDeep",
1212
]
1313

14-
__version__ = "1.0.1"
14+
__version__ = "1.1.0"
1515

1616

17-
from .providers import AbstractProvider, AbstractResolver
17+
from .providers import AbstractProvider
1818
from .reporters import BaseReporter
1919
from .resolvers import (
20+
AbstractResolver,
2021
InconsistentCandidate,
2122
RequirementsConflicted,
2223
ResolutionError,

src/pip/_vendor/resolvelib/__init__.pyi

-11
This file was deleted.

src/pip/_vendor/resolvelib/compat/__init__.py

Whitespace-only changes.

src/pip/_vendor/resolvelib/compat/collections_abc.py

-6
This file was deleted.

src/pip/_vendor/resolvelib/compat/collections_abc.pyi

-1
This file was deleted.
+103-40
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,68 @@
1-
class AbstractProvider(object):
1+
from __future__ import annotations
2+
3+
from typing import (
4+
TYPE_CHECKING,
5+
Generic,
6+
Iterable,
7+
Iterator,
8+
Mapping,
9+
Sequence,
10+
)
11+
12+
from .structs import CT, KT, RT, Matches, RequirementInformation
13+
14+
if TYPE_CHECKING:
15+
from typing import Any, Protocol
16+
17+
class Preference(Protocol):
18+
def __lt__(self, __other: Any) -> bool: ...
19+
20+
21+
class AbstractProvider(Generic[RT, CT, KT]):
222
"""Delegate class to provide the required interface for the resolver."""
323

4-
def identify(self, requirement_or_candidate):
5-
"""Given a requirement, return an identifier for it.
24+
def identify(self, requirement_or_candidate: RT | CT) -> KT:
25+
"""Given a requirement or candidate, return an identifier for it.
626
7-
This is used to identify a requirement, e.g. whether two requirements
8-
should have their specifier parts merged.
27+
This is used to identify, e.g. whether two requirements
28+
should have their specifier parts merged or a candidate matches a
29+
requirement via ``find_matches()``.
930
"""
1031
raise NotImplementedError
1132

1233
def get_preference(
1334
self,
14-
identifier,
15-
resolutions,
16-
candidates,
17-
information,
18-
backtrack_causes,
19-
):
35+
identifier: KT,
36+
resolutions: Mapping[KT, CT],
37+
candidates: Mapping[KT, Iterator[CT]],
38+
information: Mapping[KT, Iterator[RequirementInformation[RT, CT]]],
39+
backtrack_causes: Sequence[RequirementInformation[RT, CT]],
40+
) -> Preference:
2041
"""Produce a sort key for given requirement based on preference.
2142
43+
As this is a sort key it will be called O(n) times per backtrack
44+
step, where n is the number of `identifier`s, if you have a check
45+
which is expensive in some sense. E.g. It needs to make O(n) checks
46+
per call or takes significant wall clock time, consider using
47+
`narrow_requirement_selection` to filter the `identifier`s, which
48+
is applied before this sort key is called.
49+
2250
The preference is defined as "I think this requirement should be
2351
resolved first". The lower the return value is, the more preferred
2452
this group of arguments is.
2553
2654
:param identifier: An identifier as returned by ``identify()``. This
27-
identifies the dependency matches which should be returned.
55+
identifies the requirement being considered.
2856
:param resolutions: Mapping of candidates currently pinned by the
2957
resolver. Each key is an identifier, and the value is a candidate.
3058
The candidate may conflict with requirements from ``information``.
3159
:param candidates: Mapping of each dependency's possible candidates.
3260
Each value is an iterator of candidates.
3361
:param information: Mapping of requirement information of each package.
3462
Each value is an iterator of *requirement information*.
35-
:param backtrack_causes: Sequence of requirement information that were
36-
the requirements that caused the resolver to most recently backtrack.
63+
:param backtrack_causes: Sequence of *requirement information* that are
64+
the requirements that caused the resolver to most recently
65+
backtrack.
3766
3867
A *requirement information* instance is a named tuple with two members:
3968
@@ -60,15 +89,21 @@ def get_preference(
6089
"""
6190
raise NotImplementedError
6291

63-
def find_matches(self, identifier, requirements, incompatibilities):
92+
def find_matches(
93+
self,
94+
identifier: KT,
95+
requirements: Mapping[KT, Iterator[RT]],
96+
incompatibilities: Mapping[KT, Iterator[CT]],
97+
) -> Matches[CT]:
6498
"""Find all possible candidates that satisfy the given constraints.
6599
66-
:param identifier: An identifier as returned by ``identify()``. This
67-
identifies the dependency matches of which should be returned.
100+
:param identifier: An identifier as returned by ``identify()``. All
101+
candidates returned by this method should produce the same
102+
identifier.
68103
:param requirements: A mapping of requirements that all returned
69104
candidates must satisfy. Each key is an identifier, and the value
70105
an iterator of requirements for that dependency.
71-
:param incompatibilities: A mapping of known incompatibilities of
106+
:param incompatibilities: A mapping of known incompatibile candidates of
72107
each dependency. Each key is an identifier, and the value an
73108
iterator of incompatibilities known to the resolver. All
74109
incompatibilities *must* be excluded from the return value.
@@ -89,7 +124,7 @@ def find_matches(self, identifier, requirements, incompatibilities):
89124
"""
90125
raise NotImplementedError
91126

92-
def is_satisfied_by(self, requirement, candidate):
127+
def is_satisfied_by(self, requirement: RT, candidate: CT) -> bool:
93128
"""Whether the given requirement can be satisfied by a candidate.
94129
95130
The candidate is guaranteed to have been generated from the
@@ -100,34 +135,62 @@ def is_satisfied_by(self, requirement, candidate):
100135
"""
101136
raise NotImplementedError
102137

103-
def get_dependencies(self, candidate):
138+
def get_dependencies(self, candidate: CT) -> Iterable[RT]:
104139
"""Get dependencies of a candidate.
105140
106141
This should return a collection of requirements that `candidate`
107142
specifies as its dependencies.
108143
"""
109144
raise NotImplementedError
110145

146+
def narrow_requirement_selection(
147+
self,
148+
identifiers: Iterable[KT],
149+
resolutions: Mapping[KT, CT],
150+
candidates: Mapping[KT, Iterator[CT]],
151+
information: Mapping[KT, Iterator[RequirementInformation[RT, CT]]],
152+
backtrack_causes: Sequence[RequirementInformation[RT, CT]],
153+
) -> Iterable[KT]:
154+
"""
155+
An optional method to narrow the selection of requirements being
156+
considered during resolution. This method is called O(1) time per
157+
backtrack step.
158+
159+
:param identifiers: An iterable of `identifiers` as returned by
160+
``identify()``. These identify all requirements currently being
161+
considered.
162+
:param resolutions: A mapping of candidates currently pinned by the
163+
resolver. Each key is an identifier, and the value is a candidate
164+
that may conflict with requirements from ``information``.
165+
:param candidates: A mapping of each dependency's possible candidates.
166+
Each value is an iterator of candidates.
167+
:param information: A mapping of requirement information for each package.
168+
Each value is an iterator of *requirement information*.
169+
:param backtrack_causes: A sequence of *requirement information* that are
170+
the requirements causing the resolver to most recently
171+
backtrack.
111172
112-
class AbstractResolver(object):
113-
"""The thing that performs the actual resolution work."""
114-
115-
base_exception = Exception
116-
117-
def __init__(self, provider, reporter):
118-
self.provider = provider
119-
self.reporter = reporter
120-
121-
def resolve(self, requirements, **kwargs):
122-
"""Take a collection of constraints, spit out the resolution result.
123-
124-
This returns a representation of the final resolution state, with one
125-
guarenteed attribute ``mapping`` that contains resolved candidates as
126-
values. The keys are their respective identifiers.
127-
128-
:param requirements: A collection of constraints.
129-
:param kwargs: Additional keyword arguments that subclasses may accept.
173+
A *requirement information* instance is a named tuple with two members:
130174
131-
:raises: ``self.base_exception`` or its subclass.
175+
* ``requirement`` specifies a requirement contributing to the current
176+
list of candidates.
177+
* ``parent`` specifies the candidate that provides (is depended on for)
178+
the requirement, or ``None`` to indicate a root requirement.
179+
180+
Must return a non-empty subset of `identifiers`, with the default
181+
implementation being to return `identifiers` unchanged. Those `identifiers`
182+
will then be passed to the sort key `get_preference` to pick the most
183+
prefered requirement to attempt to pin, unless `narrow_requirement_selection`
184+
returns only 1 requirement, in which case that will be used without
185+
calling the sort key `get_preference`.
186+
187+
This method is designed to be used by the provider to optimize the
188+
dependency resolution, e.g. if a check cost is O(m) and it can be done
189+
against all identifiers at once then filtering the requirement selection
190+
here will cost O(m) but making it part of the sort key in `get_preference`
191+
will cost O(m*n), where n is the number of `identifiers`.
192+
193+
Returns:
194+
Iterable[KT]: A non-empty subset of `identifiers`.
132195
"""
133-
raise NotImplementedError
196+
return identifiers

src/pip/_vendor/resolvelib/providers.pyi

-44
This file was deleted.
+21-9
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
1-
class BaseReporter(object):
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING, Collection, Generic
4+
5+
from .structs import CT, KT, RT, RequirementInformation, State
6+
7+
if TYPE_CHECKING:
8+
from .resolvers import Criterion
9+
10+
11+
class BaseReporter(Generic[RT, CT, KT]):
212
"""Delegate class to provider progress reporting for the resolver."""
313

4-
def starting(self):
14+
def starting(self) -> None:
515
"""Called before the resolution actually starts."""
616

7-
def starting_round(self, index):
17+
def starting_round(self, index: int) -> None:
818
"""Called before each round of resolution starts.
919
1020
The index is zero-based.
1121
"""
1222

13-
def ending_round(self, index, state):
23+
def ending_round(self, index: int, state: State[RT, CT, KT]) -> None:
1424
"""Called before each round of resolution ends.
1525
1626
This is NOT called if the resolution ends at this round. Use `ending`
1727
if you want to report finalization. The index is zero-based.
1828
"""
1929

20-
def ending(self, state):
30+
def ending(self, state: State[RT, CT, KT]) -> None:
2131
"""Called before the resolution ends successfully."""
2232

23-
def adding_requirement(self, requirement, parent):
33+
def adding_requirement(self, requirement: RT, parent: CT | None) -> None:
2434
"""Called when adding a new requirement into the resolve criteria.
2535
2636
:param requirement: The additional requirement to be applied to filter
@@ -30,14 +40,16 @@ def adding_requirement(self, requirement, parent):
3040
requirements passed in from ``Resolver.resolve()``.
3141
"""
3242

33-
def resolving_conflicts(self, causes):
43+
def resolving_conflicts(
44+
self, causes: Collection[RequirementInformation[RT, CT]]
45+
) -> None:
3446
"""Called when starting to attempt requirement conflict resolution.
3547
3648
:param causes: The information on the collision that caused the backtracking.
3749
"""
3850

39-
def rejecting_candidate(self, criterion, candidate):
51+
def rejecting_candidate(self, criterion: Criterion[RT, CT], candidate: CT) -> None:
4052
"""Called when rejecting a candidate during backtracking."""
4153

42-
def pinning(self, candidate):
54+
def pinning(self, candidate: CT) -> None:
4355
"""Called when adding a candidate to the potential solution."""

src/pip/_vendor/resolvelib/reporters.pyi

-11
This file was deleted.

0 commit comments

Comments
 (0)