Skip to content

Commit

Permalink
Fix backjumping back checking if name in incompatible_deps
Browse files Browse the repository at this point in the history
  • Loading branch information
notatallshaw committed Jun 14, 2024
1 parent 87c9d7b commit 402310e
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/resolvelib/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,23 +309,32 @@ 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

# If the name is in the incompatible dependencies then this
# is an unexpected incompatible state and we must exit.
# Hint: This could be because the provider has chosen a
# backtracking path not related to trying to pin directly
# conflicting causes when they are available
if name in incompatible_deps:
break

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

0 comments on commit 402310e

Please sign in to comment.