Skip to content

Commit c2a4343

Browse files
committed
Repurpose backtracking hook
1 parent f47bc88 commit c2a4343

File tree

4 files changed

+12
-44
lines changed

4 files changed

+12
-44
lines changed

src/pip/_internal/resolution/resolvelib/reporter.py

+9-36
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,18 @@
1-
from collections import defaultdict
21
from logging import getLogger
3-
from typing import Any, DefaultDict
2+
from typing import Any
43

54
from pip._vendor.resolvelib.reporters import BaseReporter
5+
from pip._vendor.resolvelib.resolvers import Criterion
66

77
from .base import Candidate, Requirement
88

99
logger = getLogger(__name__)
1010

1111

1212
class PipReporter(BaseReporter):
13-
def __init__(self) -> None:
14-
self.backtracks_by_package: DefaultDict[str, int] = defaultdict(int)
15-
16-
self._messages_at_backtrack = {
17-
1: (
18-
"pip is looking at multiple versions of {package_name} to "
19-
"determine which version is compatible with other "
20-
"requirements. This could take a while."
21-
),
22-
8: (
23-
"pip is looking at multiple versions of {package_name} to "
24-
"determine which version is compatible with other "
25-
"requirements. This could take a while."
26-
),
27-
13: (
28-
"This is taking longer than usual. You might need to provide "
29-
"the dependency resolver with stricter constraints to reduce "
30-
"runtime. See https://pip.pypa.io/warnings/backtracking for "
31-
"guidance. If you want to abort this run, press Ctrl + C."
32-
),
33-
}
34-
35-
def discarding_conflicted_criterion(self, criterion, candidate) -> None:
13+
def backtracking(
14+
self, criterion: Criterion[Any, Any, Any], candidate: Candidate
15+
) -> None:
3616
msg = "Will try a different candidate, due to conflict:"
3717
for req_info in criterion.information:
3818
req, parent = req_info.requirement, req_info.parent
@@ -43,17 +23,8 @@ def discarding_conflicted_criterion(self, criterion, candidate) -> None:
4323
else:
4424
msg += "The user requested "
4525
msg += req.format_for_error()
46-
logger.info(msg)
47-
48-
def backtracking(self, candidate: Candidate) -> None:
49-
self.backtracks_by_package[candidate.name] += 1
50-
51-
count = self.backtracks_by_package[candidate.name]
52-
if count not in self._messages_at_backtrack:
53-
return
5426

55-
message = self._messages_at_backtrack[count]
56-
logger.info("INFO: %s", message.format(package_name=candidate.name))
27+
logger.info("INFO: %s", msg)
5728

5829

5930
class PipDebuggingReporter(BaseReporter):
@@ -74,7 +45,9 @@ def ending(self, state: Any) -> None:
7445
def adding_requirement(self, requirement: Requirement, parent: Candidate) -> None:
7546
logger.info("Reporter.adding_requirement(%r, %r)", requirement, parent)
7647

77-
def backtracking(self, candidate: Candidate) -> None:
48+
def backtracking(
49+
self, criterion: Criterion[Any, Any, Any], candidate: Candidate
50+
) -> None:
7851
logger.info("Reporter.backtracking(%r)", candidate)
7952

8053
def pinning(self, candidate: Candidate) -> None:

src/pip/_vendor/resolvelib/reporters.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,13 @@ def adding_requirement(self, requirement, parent):
3030
requirements passed in from ``Resolver.resolve()``.
3131
"""
3232

33-
def discarding_conflicted_criterion(self, criterion, candidate):
34-
"""Called when discarding conflicted requirements."""
35-
3633
def resolving_conflicts(self, causes):
3734
"""Called when starting to attempt requirement conflict resolution.
3835
3936
:param causes: The information on the collision that caused the backtracking.
4037
"""
4138

42-
def backtracking(self, candidate):
39+
def backtracking(self, criterion, candidate):
4340
"""Called when rejecting a candidate during backtracking."""
4441

4542
def pinning(self, candidate):

src/pip/_vendor/resolvelib/reporters.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ class BaseReporter:
66
def ending_round(self, index: int, state: Any) -> Any: ...
77
def ending(self, state: Any) -> Any: ...
88
def adding_requirement(self, requirement: Any, parent: Any) -> Any: ...
9-
def backtracking(self, candidate: Any) -> Any: ...
9+
def backtracking(self, criterion: Any, candidate: Any) -> Any: ...
1010
def resolving_conflicts(self, causes: Any) -> Any: ...
1111
def pinning(self, candidate: Any) -> Any: ...

src/pip/_vendor/resolvelib/resolvers.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def _attempt_to_pin_criterion(self, name):
212212
try:
213213
criteria = self._get_updated_criteria(candidate)
214214
except RequirementsConflicted as e:
215-
self._r.discarding_conflicted_criterion(e.criterion, candidate)
215+
self._r.backtracking(e.criterion, candidate)
216216
causes.append(e.criterion)
217217
continue
218218

@@ -282,8 +282,6 @@ def _backtrack(self):
282282
# Also mark the newly known incompatibility.
283283
incompatibilities_from_broken.append((name, [candidate]))
284284

285-
self._r.backtracking(candidate=candidate)
286-
287285
# Create a new state from the last known-to-work one, and apply
288286
# the previously gathered incompatibility information.
289287
def _patch_criteria():

0 commit comments

Comments
 (0)