@@ -40,6 +40,14 @@ def get_preference(
40
40
) -> Preference :
41
41
"""Produce a sort key for given requirement based on preference.
42
42
43
+ As this is a sort key it will be called O(n) times per backtrack step,
44
+ where n is the number of `identifier`s. If you have a check which is
45
+ expensive in some sense, e.g. it needs to make O(n) checks per
46
+ identifier, or takes significant wall clock time but could be short
47
+ circuited once finding an identifier that matches the check, consider
48
+ using `narrow_requirement_selection` to filter the `identifier`s
49
+ before this sort key is called.
50
+
43
51
The preference is defined as "I think this requirement should be
44
52
resolved first". The lower the return value is, the more preferred
45
53
this group of arguments is.
@@ -146,11 +154,8 @@ def narrow_requirement_selection(
146
154
) -> Iterable [KT ]:
147
155
"""
148
156
An optional method to narrow the selection of requirements being
149
- considered during resolution.
150
-
151
- The requirement selection is defined as "The possible requirements
152
- that will be resolved next." If a requirement is not part of the returned
153
- iterable, it will not be considered during the next step of resolution.
157
+ considered during resolution. This method is called O(1) time per
158
+ backtrack step.
154
159
155
160
:param identifiers: An iterable of `identifiers` as returned by
156
161
``identify()``. These identify all requirements currently being
@@ -174,19 +179,17 @@ def narrow_requirement_selection(
174
179
the requirement, or ``None`` to indicate a root requirement.
175
180
176
181
Must return a non-empty subset of `identifiers`, with the default
177
- implementation being to return `identifiers` unchanged.
178
-
179
- Can be used by the provider to optimize the dependency resolution
180
- process. `get_preference` will only be called for the identifiers
181
- returned. If there is only one identifier returned, then `get_preference`
182
- won't be called at all.
183
-
184
- Serving a similar purpose as `get_preference`, this method allows the
185
- provider to guide resolvelib through the resolution process. It should
186
- be used instead of `get_preference` for logic when the provider needs
187
- to consider multiple identifiers simultaneously, or when the provider
188
- wants to skip checking all identifiers, e.g., because the checks are
189
- prohibitively expensive.
182
+ implementation being to return `identifiers` unchanged. Those `identifiers`
183
+ will then be passed to the sort key `get_preference` to pick the most
184
+ prefered requirement to attempt to pin, unless `narrow_requirement_selection`
185
+ returns only 1 requirement, in which case that will be used without
186
+ calling the sort key `get_preference`.
187
+
188
+ This method is designed to be used by the provider to optimize the
189
+ dependency resolution, e.g. if a check cost is O(m) and it can be done
190
+ against all identifiers at once then filtering the requirement selection
191
+ here will cost O(m) but making it part of the sort key in `get_preference`
192
+ will cost O(m*n), where n is the number of `identifiers`.
190
193
191
194
Returns:
192
195
Iterable[KT]: A non-empty subset of `identifiers`.
0 commit comments