Skip to content

Commit

Permalink
Fix backjumping by checking if broken_state.mapping is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
notatallshaw committed Jun 14, 2024
1 parent 87c9d7b commit 27e254d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/resolvelib/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,23 +309,29 @@ def _backjump(self, causes: list[RequirementInformation[RT, CT]]) -> bool:
# Remove the state that triggered backtracking.
del self._states[-1]

# Ensure to backtrack to a state that caused the incompatibility
incompatible_state = False
# Optimistically backtrack to a state that caused the incompatibility
broken_state = self.state
while not incompatible_state:
while True:
# Retrieve the last candidate pin and known incompatibilities.
try:
broken_state = self._states.pop()
name, candidate = broken_state.mapping.popitem()
except (IndexError, KeyError):
raise ResolutionImpossible(causes) from None

# If the current dependencies and the incompatible dependencies
# are overlapping then we have found a cause of the incompatibility
current_dependencies = {
self._p.identify(d)
for d in self._p.get_dependencies(candidate)
}
incompatible_state = not current_dependencies.isdisjoint(
incompatible_deps
)
if not current_dependencies.isdisjoint(incompatible_deps):
break

# Stop backtracking if there is no state to backtrack on
if not broken_state.mapping:
break


incompatibilities_from_broken = [
(k, list(v.incompatibilities))
Expand Down

0 comments on commit 27e254d

Please sign in to comment.