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

Backtrack if incompatibilities fail to apply #65

Merged
merged 1 commit into from
Dec 27, 2020
Merged
Changes from all 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
34 changes: 21 additions & 13 deletions src/resolvelib/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,28 +271,36 @@ def _backtrack(self):
for k, v in broken_state.criteria.items()
]

# Also mark the newly known incompatibility.
incompatibilities_from_broken.append((name, [candidate]))

self._r.backtracking(candidate)

# Create a new state from the last known-to-work one, and apply
# the previously gathered incompatibility information.
self._push_new_state()
for k, incompatibilities in incompatibilities_from_broken:
try:
crit = self.state.criteria[k]
except KeyError:
continue
self.state.criteria[k] = crit.excluded_of(incompatibilities)
def _patch_criteria():
for k, incompatibilities in incompatibilities_from_broken:
if not incompatibilities:
continue
try:
criterion = self.state.criteria[k]
except KeyError:
continue
criterion = criterion.excluded_of(incompatibilities)
if criterion is None:
return False
self.state.criteria[k] = criterion
return True

# Mark the newly known incompatibility.
criterion = self.state.criteria[name].excluded_of([candidate])
self._push_new_state()
success = _patch_criteria()

# It works! Let's work on this new state.
if criterion:
self.state.criteria[name] = criterion
if success:
return True

# State does not work after adding the new incompatibility
# information. Try the still previous state.
# State does not work after applying known incompatibilities.
# Try the still previous state.

# No way to backtrack anymore.
return False
Expand Down