From c411a98ee2204cb1aa596ba323c92abff7829dea Mon Sep 17 00:00:00 2001 From: Joe Bylund Date: Mon, 1 Nov 2021 10:59:42 -0400 Subject: [PATCH 1/3] Pass in a prepare method which is called over causes before calling get preference. --- src/resolvelib/resolvers.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/resolvelib/resolvers.py b/src/resolvelib/resolvers.py index 787681b..1bf4dc7 100644 --- a/src/resolvelib/resolvers.py +++ b/src/resolvelib/resolvers.py @@ -108,10 +108,11 @@ class Resolution(object): the resolution process, and holds the results afterwards. """ - def __init__(self, provider, reporter): + def __init__(self, provider, reporter, prepare_causes=None): self._p = provider self._r = reporter self._states = [] + self.prepare = prepare_causes @property def state(self): @@ -173,7 +174,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, @@ -185,7 +186,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): @@ -368,8 +369,16 @@ def resolve(self, requirements, max_rounds): self._r.ending(state=self.state) return self.state + if self.prepare is None: + processed_causes = self.state.backtrack_causes + else: + processed_causes = self.prepare(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: From 9d5ee1abd540f31e76b35bf0016936412afdda2f Mon Sep 17 00:00:00 2001 From: Joseph Bylund Date: Mon, 20 Dec 2021 17:23:20 -0500 Subject: [PATCH 2/3] empty commit to trigger ci From b7ba6a7e743673d85ac031b6c48e3d0ec201fc9c Mon Sep 17 00:00:00 2001 From: Joseph Bylund Date: Mon, 20 Dec 2021 18:46:48 -0500 Subject: [PATCH 3/3] Move prepare causes to the provider --- src/resolvelib/resolvers.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/resolvelib/resolvers.py b/src/resolvelib/resolvers.py index 1bf4dc7..8ed8716 100644 --- a/src/resolvelib/resolvers.py +++ b/src/resolvelib/resolvers.py @@ -108,11 +108,10 @@ class Resolution(object): the resolution process, and holds the results afterwards. """ - def __init__(self, provider, reporter, prepare_causes=None): + def __init__(self, provider, reporter): self._p = provider self._r = reporter self._states = [] - self.prepare = prepare_causes @property def state(self): @@ -369,10 +368,12 @@ def resolve(self, requirements, max_rounds): self._r.ending(state=self.state) return self.state - if self.prepare is None: + try: + prepare_fn = self._p.prepare_causes + except AttributeError: processed_causes = self.state.backtrack_causes else: - processed_causes = self.prepare(self.state.backtrack_causes) + processed_causes = prepare_fn(self.state.backtrack_causes) def key_fn(name): return self._get_preference(name, processed_causes)