diff --git a/news/101.feature.rst b/news/101.feature.rst new file mode 100644 index 0000000..9f78ff4 --- /dev/null +++ b/news/101.feature.rst @@ -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. diff --git a/src/resolvelib/__init__.py b/src/resolvelib/__init__.py index 62352e7..8d22a3e 100644 --- a/src/resolvelib/__init__.py +++ b/src/resolvelib/__init__.py @@ -11,7 +11,7 @@ "ResolutionTooDeep", ] -__version__ = "0.8.2.dev0" +__version__ = "0.9.0.dev0" from .providers import AbstractProvider, AbstractResolver diff --git a/src/resolvelib/reporters.py b/src/resolvelib/reporters.py index 6695480..688b5e1 100644 --- a/src/resolvelib/reporters.py +++ b/src/resolvelib/reporters.py @@ -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): diff --git a/src/resolvelib/reporters.pyi b/src/resolvelib/reporters.pyi index 03d4f09..b2ad286 100644 --- a/src/resolvelib/reporters.pyi +++ b/src/resolvelib/reporters.pyi @@ -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: ... diff --git a/src/resolvelib/resolvers.py b/src/resolvelib/resolvers.py index 787681b..be8d5f0 100644 --- a/src/resolvelib/resolvers.py +++ b/src/resolvelib/resolvers.py @@ -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 @@ -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(): diff --git a/tests/conftest.py b/tests/conftest.py index c9fb2d0..9603944 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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="")