# HG changeset patch # User Matt Mackall # Date 2015-03-28 00:25:40 # Node ID 4b3fc46097f74cdd1aceceed82e3e475ce2b9eba # Parent 642d245ff5374808ab6ceca60bce3d390aa7b649 import-checker: drop duplicate element from cycle This will allow optimizing cyclekey creation diff --git a/contrib/import-checker.py b/contrib/import-checker.py --- a/contrib/import-checker.py +++ b/contrib/import-checker.py @@ -164,7 +164,7 @@ class CircularImport(Exception): 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 @@ def check_one_mod(mod, imports, path=Non 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 check_one_mod(mod, imports, path=Non 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.