Mercurial > hg > config
comparison python/unroll_deps.py @ 682:3fe1024377ca
STUB: python/unroll_deps.py
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Tue, 13 May 2014 13:02:45 -0700 |
parents | bc1f4762027b |
children |
comparison
equal
deleted
inserted
replaced
681:bc1f4762027b | 682:3fe1024377ca |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | |
3 """ | |
4 unroll a set of dependencies | |
5 """ | |
6 | |
7 import sys | |
2 | 8 |
3 def cycle_check(order, dependencies): | 9 def cycle_check(order, dependencies): |
4 """ensure no cyclic dependencies""" | 10 """ensure no cyclic dependencies""" |
5 order_dict = dict([(j, i) for i, j in enumerate(order)]) | 11 order_dict = dict([(j, i) for i, j in enumerate(order)]) |
6 for package, deps in dependencies.items(): | 12 for package, deps in dependencies.items(): |
53 | 59 |
54 cycle_check(order, dependencies) # sanity | 60 cycle_check(order, dependencies) # sanity |
55 | 61 |
56 return order | 62 return order |
57 | 63 |
58 if __name__ == '__main__': | 64 |
65 ### testing and CLI | |
66 | |
67 def main(args=sys.argv[:1]): | |
59 | 68 |
60 # testing set of dependencies | 69 # testing set of dependencies |
61 deps = {'packageA': set(['packageB', 'packageC', 'packageF']), | 70 deps = {'packageA': set(['packageB', 'packageC', 'packageF']), |
62 'packageB': set(['packageC', 'packageD', 'packageE', 'packageG']), | 71 'packageB': set(['packageC', 'packageD', 'packageE', 'packageG']), |
63 'packageC': set(['packageE']), | 72 'packageC': set(['packageE']), |
75 try: | 84 try: |
76 unroll_dependencies(deps) | 85 unroll_dependencies(deps) |
77 raise Exception("Missed a cyclic dependency!") | 86 raise Exception("Missed a cyclic dependency!") |
78 except AssertionError: | 87 except AssertionError: |
79 pass | 88 pass |
80 | 89 |
81 try: | 90 try: |
82 unroll_dependencies2(deps) | 91 unroll_dependencies2(deps) |
83 raise Exception("Missed a cyclic dependency!") | 92 raise Exception("Missed a cyclic dependency!") |
84 except AssertionError: | 93 except AssertionError: |
85 pass | 94 pass |
95 | |
96 if __name__ == '__main__': | |
97 main() |