Skip to content

Commit

Permalink
Merge pull request #143 from notatallshaw/deduplicate-causes
Browse files Browse the repository at this point in the history
Deduplicate causes
  • Loading branch information
frostming committed Nov 29, 2023
2 parents 044ab9f + ccbe1e5 commit 995ed67
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/resolvelib/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,14 @@ def _patch_criteria() -> bool:
# No way to backtrack anymore.
return False

def _extract_causes(
self, criteron: list[Criterion[RT, CT]]
) -> list[RequirementInformation[RT, CT]]:
"""Extract causes from list of criterion and deduplicate"""
return list(
{id(i): i for c in criteron for i in c.information}.values()
)

def resolve(
self, requirements: Iterable[RT], max_rounds: int
) -> State[RT, CT, KT]:
Expand Down Expand Up @@ -429,10 +437,10 @@ def resolve(

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

if failure_causes:
causes = [i for c in failure_causes for i in c.information]
if failure_criterion:
causes = self._extract_causes(failure_criterion)
# Backjump if pinning fails. The backjump process puts us in
# an unpinned state, so we can work on it in the next round.
self._r.resolving_conflicts(causes=causes)
Expand Down

0 comments on commit 995ed67

Please sign in to comment.