@@ -99,7 +99,7 @@ def __init__(self, round_count):
99
99
100
100
101
101
# Resolution state in a round.
102
- State = collections .namedtuple ("State" , "mapping criteria" )
102
+ State = collections .namedtuple ("State" , "mapping criteria backtrack_causes " )
103
103
104
104
105
105
class Resolution (object ):
@@ -131,6 +131,7 @@ def _push_new_state(self):
131
131
state = State (
132
132
mapping = base .mapping .copy (),
133
133
criteria = base .criteria .copy (),
134
+ backtrack_causes = base .backtrack_causes [:],
134
135
)
135
136
self ._states .append (state )
136
137
@@ -185,6 +186,7 @@ def _get_preference(self, name):
185
186
self .state .criteria ,
186
187
operator .attrgetter ("information" ),
187
188
),
189
+ backtrack_causes = self .state .backtrack_causes ,
188
190
)
189
191
190
192
def _is_current_pin_satisfying (self , name , criterion ):
@@ -335,7 +337,13 @@ def resolve(self, requirements, max_rounds):
335
337
self ._r .starting ()
336
338
337
339
# Initialize the root state.
338
- self ._states = [State (mapping = collections .OrderedDict (), criteria = {})]
340
+ self ._states = [
341
+ State (
342
+ mapping = collections .OrderedDict (),
343
+ criteria = {},
344
+ backtrack_causes = [],
345
+ )
346
+ ]
339
347
for r in requirements :
340
348
try :
341
349
self ._add_to_criteria (self .state .criteria , r , parent = None )
@@ -369,11 +377,13 @@ def resolve(self, requirements, max_rounds):
369
377
# Backtrack if pinning fails. The backtrack process puts us in
370
378
# an unpinned state, so we can work on it in the next round.
371
379
success = self ._backtrack ()
380
+ self .state .backtrack_causes [:] = [
381
+ i for c in failure_causes for i in c .information
382
+ ]
372
383
373
384
# Dead ends everywhere. Give up.
374
385
if not success :
375
- causes = [i for c in failure_causes for i in c .information ]
376
- raise ResolutionImpossible (causes )
386
+ raise ResolutionImpossible (self .state .backtrack_causes )
377
387
else :
378
388
# Pinning was successful. Push a new state to do another pin.
379
389
self ._push_new_state ()
0 commit comments