def _topological_sort(pairlist):
 numpreds = {}
 successors = {}
 for (second, target) in pairlist.items():
  if (second not in numpreds):
   numpreds[second] = 0
  if (second not in successors):
   successors[second] = []
  deps = target.expanded_deps
  for first in deps:
   if (first not in numpreds):
    numpreds[first] = 0
   numpreds[second] = (numpreds[second] + 1)
   if (first in successors):
    successors[first].append(second)
   else:
    successors[first] = [second]
 answer = filter((lambda x, numpreds=numpreds: (numpreds[x] == 0)), numpreds.keys())
 for x in answer:
  assert (numpreds[x] == 0)
  del numpreds[x]
  if (x in successors):
   for y in successors[x]:
    numpreds[y] = (numpreds[y] - 1)
    if (numpreds[y] == 0):
     answer.append(y)
 return (answer, successors)

def _topological_sort ( pairlist ) : numpreds = { } successors = { } for ( second , target ) in pairlist . items ( ) : if ( second not in numpreds ) : numpreds [ second ] = 0 if ( second not in successors ) : successors [ second ] = [ ] deps = target . expanded_deps for first in deps : if ( first not in numpreds ) : numpreds [ first ] = 0 numpreds [ second ] = ( numpreds [ second ] + 1 ) if ( first in successors ) : successors [ first ] . append ( second ) else : successors [ first ] = [ second ] answer = filter ( ( lambda x , numpreds = numpreds : ( numpreds [ x ] == 0 ) ) , numpreds . keys ( ) ) for x in answer : assert ( numpreds [ x ] == 0 ) del numpreds [ x ] if ( x in successors ) : for y in successors [ x ] : numpreds [ y ] = ( numpreds [ y ] - 1 ) if ( numpreds [ y ] == 0 ) : answer . append ( y ) return ( answer , successors )
sort the targets .