Show More
@@ -166,22 +166,21 b' class CircularImport(Exception):' | |||||
166 | def cyclekey(names): |
|
166 | def cyclekey(names): | |
167 | return tuple(sorted(names)) |
|
167 | return tuple(sorted(names)) | |
168 |
|
168 | |||
169 |
def check |
|
169 | def checkmod(mod, imports): | |
170 | if path is None: |
|
170 | shortest = {} | |
171 | path = [] |
|
171 | visit = [[mod]] | |
172 | if ignore is None: |
|
172 | while visit: | |
173 | ignore = [] |
|
173 | path = visit.pop(0) | |
174 | path = path + [mod] |
|
174 | for i in sorted(imports.get(path[-1], [])): | |
175 | for i in sorted(imports.get(mod, [])): |
|
175 | if i not in stdlib_modules and not i.startswith('mercurial.'): | |
176 | if i not in stdlib_modules and not i.startswith('mercurial.'): |
|
176 | i = mod.rsplit('.', 1)[0] + '.' + i | |
177 | i = mod.rsplit('.', 1)[0] + '.' + i |
|
177 | if len(path) < shortest.get(i, 1000): | |
178 | if i in path: |
|
178 | shortest[i] = len(path) | |
179 |
|
|
179 | if i in path: | |
180 | cycle = path[firstspot:] |
|
180 | if i == path[0]: | |
181 | if cyclekey(cycle) not in ignore: |
|
181 | raise CircularImport(path) | |
182 | raise CircularImport(cycle) |
|
182 | continue | |
183 | continue |
|
183 | visit.append(path + [i]) | |
184 | check_one_mod(i, imports, path=path, ignore=ignore) |
|
|||
185 |
|
184 | |||
186 | def rotatecycle(cycle): |
|
185 | def rotatecycle(cycle): | |
187 | """arrange a cycle so that the lexicographically first module listed first |
|
186 | """arrange a cycle so that the lexicographically first module listed first | |
@@ -207,7 +206,7 b' def find_cycles(imports):' | |||||
207 | cycles = {} |
|
206 | cycles = {} | |
208 | for mod in sorted(imports.iterkeys()): |
|
207 | for mod in sorted(imports.iterkeys()): | |
209 | try: |
|
208 | try: | |
210 |
check |
|
209 | checkmod(mod, imports) | |
211 | except CircularImport, e: |
|
210 | except CircularImport, e: | |
212 | cycle = e.args[0] |
|
211 | cycle = e.args[0] | |
213 | cycles[cyclekey(cycle)] = ' -> '.join(rotatecycle(cycle)) |
|
212 | cycles[cyclekey(cycle)] = ' -> '.join(rotatecycle(cycle)) |
General Comments 0
You need to be logged in to leave comments.
Login now