comparison python/unroll_deps.py @ 150:ef01512b2212

fixes; doesnt quite work
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 12 Jul 2011 17:25:21 -0700
parents 05e461e4b409
children f89c3615b414
comparison
equal deleted inserted replaced
149:05e461e4b409 150:ef01512b2212
2 2
3 def unroll_dependencies(dependencies): 3 def unroll_dependencies(dependencies):
4 """unroll dependencies""" 4 """unroll dependencies"""
5 order = [] 5 order = []
6 for package, deps in dependencies.items(): 6 for package, deps in dependencies.items():
7 print package, order
7 try: 8 try:
8 index = order.index(package) 9 index = order.index(package)
9 except ValueError: 10 except ValueError:
10 order.append(package) 11 order.append(package)
11 index = len(order) - 1 12 index = len(order) - 1
12 for dep in deps: 13 for dep in deps:
13 try: 14 try:
14 dep_index = order.index(dep) 15 dep_index = order.index(dep)
15 assert dep_index < index, "Cyclic dependencies detected" 16 assert dep_index < index, "Cyclic dependencies detected: %s, %s" % (package, dep)
16 except ValueError: 17 except ValueError:
17 order.insert(index, dep) 18 order.insert(index, dep)
18 return order 19 return order
19 20
20 if __name__ == '__main__': 21 if __name__ == '__main__':
21 deps = {'packageA': set(['packageB', 'packageC']), 22 deps = {'packageA': set(['packageB', 'packageC']),
22 'packageB': set(['packageC', 'packageD']), 23 'packageB': set(['packageC', 'packageD', 'packageE']),
23 'packageC': set()} 24 'packageC': set(['packageE'])}
24 unrolled = unroll_dependencies(deps) 25 unrolled = unroll_dependencies(deps)
25 print unrolled 26 print unrolled