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

Consumer passes in a prepare method which is called over backtrack causes #96

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 13 additions & 3 deletions src/resolvelib/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def _add_to_criteria(self, criteria, requirement, parent):
raise RequirementsConflicted(criterion)
criteria[identifier] = criterion

def _get_preference(self, name):
def _get_preference(self, name, causes):
return self._p.get_preference(
identifier=name,
resolutions=self.state.mapping,
Expand All @@ -185,7 +185,7 @@ def _get_preference(self, name):
self.state.criteria,
operator.attrgetter("information"),
),
backtrack_causes=self.state.backtrack_causes,
backtrack_causes=causes,
)

def _is_current_pin_satisfying(self, name, criterion):
Expand Down Expand Up @@ -368,8 +368,18 @@ def resolve(self, requirements, max_rounds):
self._r.ending(state=self.state)
return self.state

try:
prepare_fn = self._p.prepare_causes
except AttributeError:
processed_causes = self.state.backtrack_causes
else:
processed_causes = prepare_fn(self.state.backtrack_causes)

def key_fn(name):
return self._get_preference(name, processed_causes)

# Choose the most preferred unpinned criterion to try.
name = min(unsatisfied_names, key=self._get_preference)
name = min(unsatisfied_names, key=key_fn)
failure_causes = self._attempt_to_pin_criterion(name)

if failure_causes:
Expand Down