Mercurial > hg > config
comparison python/unroll_deps.py @ 149:05e461e4b409
add an unroll-deps example prog
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 12 Jul 2011 13:48:50 -0700 |
parents | |
children | ef01512b2212 |
comparison
equal
deleted
inserted
replaced
148:7a4c86310463 | 149:05e461e4b409 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 def unroll_dependencies(dependencies): | |
4 """unroll dependencies""" | |
5 order = [] | |
6 for package, deps in dependencies.items(): | |
7 try: | |
8 index = order.index(package) | |
9 except ValueError: | |
10 order.append(package) | |
11 index = len(order) - 1 | |
12 for dep in deps: | |
13 try: | |
14 dep_index = order.index(dep) | |
15 assert dep_index < index, "Cyclic dependencies detected" | |
16 except ValueError: | |
17 order.insert(index, dep) | |
18 return order | |
19 | |
20 if __name__ == '__main__': | |
21 deps = {'packageA': set(['packageB', 'packageC']), | |
22 'packageB': set(['packageC', 'packageD']), | |
23 'packageC': set()} | |
24 unrolled = unroll_dependencies(deps) | |
25 print unrolled |