Skip to content
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

Repurpose backtracking hook #101

Merged
merged 6 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions news/101.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
A new reporter hook ``rejecting_candidate`` is added, replacing the former
``backtracking`` one. The resolver triggers this hook every time it rejects
a conflicting package before trying out an older version of it.
The hook accepts two arguments: ``criterion`` (a ``resolvers.Criterion``
object) and ``candidate``.
uranusjr marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion src/resolvelib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"ResolutionTooDeep",
]

__version__ = "0.8.2.dev0"
__version__ = "0.9.0.dev0"


from .providers import AbstractProvider, AbstractResolver
Expand Down
2 changes: 1 addition & 1 deletion src/resolvelib/reporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def resolving_conflicts(self, causes):
:param causes: The information on the collision that caused the backtracking.
"""

def backtracking(self, candidate):
def rejecting_candidate(self, criterion, candidate):
"""Called when rejecting a candidate during backtracking."""

def pinning(self, candidate):
Expand Down
2 changes: 1 addition & 1 deletion src/resolvelib/reporters.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class BaseReporter:
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 rejecting_candidate(self, criterion: Any, candidate: Any) -> Any: ...
def resolving_conflicts(self, causes: Any) -> Any: ...
def pinning(self, candidate: Any) -> Any: ...
3 changes: 1 addition & 2 deletions src/resolvelib/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def _attempt_to_pin_criterion(self, name):
try:
criteria = self._get_updated_criteria(candidate)
except RequirementsConflicted as e:
self._r.rejecting_candidate(e.criterion, candidate)
causes.append(e.criterion)
continue

Expand Down Expand Up @@ -281,8 +282,6 @@ def _backtrack(self):
# Also mark the newly known incompatibility.
incompatibilities_from_broken.append((name, [candidate]))

self._r.backtracking(candidate=candidate)

# Create a new state from the last known-to-work one, and apply
# the previously gathered incompatibility information.
def _patch_criteria():
Expand Down
5 changes: 2 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ class TestReporter(BaseReporter):
def __init__(self):
self._indent = 0

def backtracking(self, candidate):
def rejecting_candidate(self, criterion, candidate):
self._indent -= 1
assert self._indent >= 0
print(" " * self._indent, "Back ", candidate, sep="")
print(" " * self._indent, "Reject ", candidate, sep="")

def pinning(self, candidate):
print(" " * self._indent, "Pin ", candidate, sep="")
Expand Down