Mercurial > hg > config
annotate 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 |
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 = [] |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
6 for package, deps in dependencies.items(): |
150 | 7 print package, order |
149
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 try: |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
9 index = order.index(package) |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
10 except ValueError: |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
11 order.append(package) |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
12 index = len(order) - 1 |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
13 for dep in deps: |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
14 try: |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
15 dep_index = order.index(dep) |
150 | 16 assert dep_index < index, "Cyclic dependencies detected: %s, %s" % (package, dep) |
149
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
17 except ValueError: |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
18 order.insert(index, dep) |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
19 return order |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
20 |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
21 if __name__ == '__main__': |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
22 deps = {'packageA': set(['packageB', 'packageC']), |
150 | 23 'packageB': set(['packageC', 'packageD', 'packageE']), |
24 'packageC': set(['packageE'])} | |
149
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
25 unrolled = unroll_dependencies(deps) |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
26 print unrolled |