changeset 20038:c65a6937b828

import-checker: try a little harder to show fewer cycles This makes sure that all cycles begin with the lexicographically first module, so that we're less likely to show overlapping cycles in the final analysis.
author Augie Fackler <raf@durin42.com>
date Sun, 17 Nov 2013 13:33:20 -0500
parents 957b43371928
children 05626e87489c
files contrib/import-checker.py
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/import-checker.py	Sun Nov 17 16:58:18 2013 -0500
+++ b/contrib/import-checker.py	Sun Nov 17 13:33:20 2013 -0500
@@ -153,6 +153,15 @@
             continue
         check_one_mod(i, imports, path=path, ignore=ignore)
 
+def rotatecycle(cycle):
+    """arrange a cycle so that the lexicographically first module listed first
+
+    >>> rotatecycle(['foo', 'bar', 'foo'])
+    ['bar', 'foo', 'bar']
+    """
+    lowest = min(cycle)
+    idx = cycle.index(lowest)
+    return cycle[idx:] + cycle[1:idx] + [lowest]
 
 def find_cycles(imports):
     """Find cycles in an already-loaded import graph.
@@ -162,8 +171,8 @@
     ...            'top.baz': ['foo'],
     ...            'top.qux': ['foo']}
     >>> print '\\n'.join(sorted(find_cycles(imports)))
-    top.bar -> top.baz -> top.foo -> top.bar
-    top.foo -> top.qux -> top.foo
+    top.bar -> top.baz -> top.foo -> top.bar -> top.bar
+    top.foo -> top.qux -> top.foo -> top.foo
     """
     cycles = {}
     for mod in sorted(imports.iterkeys()):