# HG changeset patch # User Augie Fackler # Date 2013-11-17 18:33:20 # Node ID c65a6937b828c0a111584805751e2120b4bce902 # Parent 957b43371928c688313b912d3739420fee219610 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. diff --git a/contrib/import-checker.py b/contrib/import-checker.py --- a/contrib/import-checker.py +++ b/contrib/import-checker.py @@ -153,6 +153,15 @@ def check_one_mod(mod, imports, path=Non 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 @@ def find_cycles(imports): ... '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()):