Skip to content

Commit

Permalink
Merge pull request #101 from astrojuanlu/repurpose-backtracking
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr authored Mar 25, 2022
2 parents ebf6c51 + 56736c3 commit f1136b4
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 8 deletions.
3 changes: 3 additions & 0 deletions news/101.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A new reporter hook ``rejecting_candidate`` is added, replacing ``backtracking``.
The hook is called every time the resolver rejects a conflicting candidate before
trying out the next one in line.
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

0 comments on commit f1136b4

Please sign in to comment.