diff python/unroll_deps.py @ 151:f89c3615b414

this is how its done
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 12 Jul 2011 18:21:48 -0700
parents ef01512b2212
children 8d04ad79ef79
line wrap: on
line diff
--- a/python/unroll_deps.py	Tue Jul 12 17:25:21 2011 -0700
+++ b/python/unroll_deps.py	Tue Jul 12 18:21:48 2011 -0700
@@ -3,6 +3,8 @@
 def unroll_dependencies(dependencies):
     """unroll dependencies"""
     order = []
+
+    # unroll the dependencies
     for package, deps in dependencies.items():
         print package, order
         try:
@@ -13,14 +15,32 @@
         for dep in deps:
             try:
                 dep_index = order.index(dep)
-                assert dep_index < index, "Cyclic dependencies detected: %s, %s" % (package, dep)
+                if dep_index > index:
+                    order.insert(dep_index+1, package)
+                    order.pop(index)
+                    index = dep_index
             except ValueError:
                 order.insert(index, dep)
+            except AssertionError:
+                print reverse_deps
+                raise
+
+    # ensure no cyclic dependencies
+    # XXX should do this first
+    order_dict = dict([(j, i) for i, j in enumerate(order)])
+    for package, deps in dependencies.items():
+        index = order_dict[package]
+        for d in deps:
+            assert index > order_dict[d], "Cyclic dependencies detected"
+
     return order
 
 if __name__ == '__main__':
-    deps = {'packageA': set(['packageB', 'packageC']),
-            'packageB': set(['packageC', 'packageD', 'packageE']),
-            'packageC': set(['packageE'])}
+    deps = {'packageA': set(['packageB', 'packageC', 'packageF']),
+            'packageB': set(['packageC', 'packageD', 'packageE', 'packageG']),
+            'packageC': set(['packageE']),
+            'packageE': set(['packageF', 'packageG']),
+            'packageF': set(['packageG']),
+            'packageX': set()}
     unrolled = unroll_dependencies(deps)
     print unrolled