Mercurial > hg-stable
changeset 24488:4b3fc46097f7
import-checker: drop duplicate element from cycle
This will allow optimizing cyclekey creation
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Fri, 27 Mar 2015 19:25:40 -0500 |
parents | 642d245ff537 |
children | 0f6594b0a4e2 |
files | contrib/import-checker.py |
diffstat | 1 files changed, 4 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/import-checker.py Fri Mar 27 18:50:39 2015 -0500 +++ b/contrib/import-checker.py Fri Mar 27 19:25:40 2015 -0500 @@ -164,7 +164,7 @@ def cyclekey(names): - return tuple(sorted(set(names))) + return tuple(sorted((names))) def check_one_mod(mod, imports, path=None, ignore=None): if path is None: @@ -177,7 +177,7 @@ i = mod.rsplit('.', 1)[0] + '.' + i if i in path: firstspot = path.index(i) - cycle = path[firstspot:] + [i] + cycle = path[firstspot:] if cyclekey(cycle) not in ignore: raise CircularImport(cycle) continue @@ -186,12 +186,12 @@ def rotatecycle(cycle): """arrange a cycle so that the lexicographically first module listed first - >>> rotatecycle(['foo', 'bar', 'foo']) + >>> rotatecycle(['foo', 'bar']) ['bar', 'foo', 'bar'] """ lowest = min(cycle) idx = cycle.index(lowest) - return cycle[idx:-1] + cycle[:idx] + [lowest] + return cycle[idx:] + cycle[:idx] + [lowest] def find_cycles(imports): """Find cycles in an already-loaded import graph.