Show More
@@ -153,6 +153,15 b' def check_one_mod(mod, imports, path=Non' | |||||
153 | continue |
|
153 | continue | |
154 | check_one_mod(i, imports, path=path, ignore=ignore) |
|
154 | check_one_mod(i, imports, path=path, ignore=ignore) | |
155 |
|
155 | |||
|
156 | def rotatecycle(cycle): | |||
|
157 | """arrange a cycle so that the lexicographically first module listed first | |||
|
158 | ||||
|
159 | >>> rotatecycle(['foo', 'bar', 'foo']) | |||
|
160 | ['bar', 'foo', 'bar'] | |||
|
161 | """ | |||
|
162 | lowest = min(cycle) | |||
|
163 | idx = cycle.index(lowest) | |||
|
164 | return cycle[idx:] + cycle[1:idx] + [lowest] | |||
156 |
|
165 | |||
157 | def find_cycles(imports): |
|
166 | def find_cycles(imports): | |
158 | """Find cycles in an already-loaded import graph. |
|
167 | """Find cycles in an already-loaded import graph. | |
@@ -162,8 +171,8 b' def find_cycles(imports):' | |||||
162 | ... 'top.baz': ['foo'], |
|
171 | ... 'top.baz': ['foo'], | |
163 | ... 'top.qux': ['foo']} |
|
172 | ... 'top.qux': ['foo']} | |
164 | >>> print '\\n'.join(sorted(find_cycles(imports))) |
|
173 | >>> print '\\n'.join(sorted(find_cycles(imports))) | |
165 | top.bar -> top.baz -> top.foo -> top.bar |
|
174 | top.bar -> top.baz -> top.foo -> top.bar -> top.bar | |
166 | top.foo -> top.qux -> top.foo |
|
175 | top.foo -> top.qux -> top.foo -> top.foo | |
167 | """ |
|
176 | """ | |
168 | cycles = {} |
|
177 | cycles = {} | |
169 | for mod in sorted(imports.iterkeys()): |
|
178 | for mod in sorted(imports.iterkeys()): |
General Comments 0
You need to be logged in to leave comments.
Login now