Mercurial > hg > config
annotate python/unroll_deps.py @ 152:8d04ad79ef79
another test
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 12 Jul 2011 20:17:10 -0700 |
parents | f89c3615b414 |
children | 17310d15ad26 |
rev | line source |
---|---|
149
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
2 |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
3 def unroll_dependencies(dependencies): |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
4 """unroll dependencies""" |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
5 order = [] |
151 | 6 |
7 # unroll the dependencies | |
149
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 for package, deps in dependencies.items(): |
150 | 9 print package, order |
149
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
10 try: |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
11 index = order.index(package) |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
12 except ValueError: |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
13 order.append(package) |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
14 index = len(order) - 1 |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
15 for dep in deps: |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
16 try: |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
17 dep_index = order.index(dep) |
151 | 18 if dep_index > index: |
19 order.insert(dep_index+1, package) | |
20 order.pop(index) | |
21 index = dep_index | |
149
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
22 except ValueError: |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
23 order.insert(index, dep) |
151 | 24 except AssertionError: |
25 print reverse_deps | |
26 raise | |
27 | |
28 # ensure no cyclic dependencies | |
29 # XXX should do this first | |
30 order_dict = dict([(j, i) for i, j in enumerate(order)]) | |
31 for package, deps in dependencies.items(): | |
32 index = order_dict[package] | |
33 for d in deps: | |
34 assert index > order_dict[d], "Cyclic dependencies detected" | |
35 | |
149
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
36 return order |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
37 |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
38 if __name__ == '__main__': |
151 | 39 deps = {'packageA': set(['packageB', 'packageC', 'packageF']), |
40 'packageB': set(['packageC', 'packageD', 'packageE', 'packageG']), | |
41 'packageC': set(['packageE']), | |
42 'packageE': set(['packageF', 'packageG']), | |
43 'packageF': set(['packageG']), | |
152 | 44 'packageX': set(['packageA', 'packageG'])} |
149
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
45 unrolled = unroll_dependencies(deps) |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
46 print unrolled |