##// END OF EJS Templates
import-checker: show stdlib and relative imports separately...
Mads Kiilerich -
r20386:a05d31b0 default
parent child Browse files
Show More
@@ -139,7 +139,7 b' def verify_stdlib_on_own_line(source):'
139 http://bugs.python.org/issue19510.
139 http://bugs.python.org/issue19510.
140
140
141 >>> list(verify_stdlib_on_own_line('import sys, foo'))
141 >>> list(verify_stdlib_on_own_line('import sys, foo'))
142 ['mixed stdlib and relative imports:\\n foo, sys']
142 ['mixed imports\\n stdlib: sys\\n relative: foo']
143 >>> list(verify_stdlib_on_own_line('import sys, os'))
143 >>> list(verify_stdlib_on_own_line('import sys, os'))
144 []
144 []
145 >>> list(verify_stdlib_on_own_line('import foo, bar'))
145 >>> list(verify_stdlib_on_own_line('import foo, bar'))
@@ -147,13 +147,13 b' def verify_stdlib_on_own_line(source):'
147 """
147 """
148 for node in ast.walk(ast.parse(source)):
148 for node in ast.walk(ast.parse(source)):
149 if isinstance(node, ast.Import):
149 if isinstance(node, ast.Import):
150 from_stdlib = {}
150 from_stdlib = {False: [], True: []}
151 for n in node.names:
151 for n in node.names:
152 from_stdlib[n.name] = n.name in stdlib_modules
152 from_stdlib[n.name in stdlib_modules].append(n.name)
153 num_std = len([x for x in from_stdlib.values() if x])
153 if from_stdlib[True] and from_stdlib[False]:
154 if num_std not in (len(from_stdlib.values()), 0):
154 yield ('mixed imports\n stdlib: %s\n relative: %s' %
155 yield ('mixed stdlib and relative imports:\n %s' %
155 (', '.join(sorted(from_stdlib[True])),
156 ', '.join(sorted(from_stdlib.iterkeys())))
156 ', '.join(sorted(from_stdlib[False]))))
157
157
158 class CircularImport(Exception):
158 class CircularImport(Exception):
159 pass
159 pass
@@ -23,16 +23,21 b' hidden by deduplication algorithm in the'
23 these may expose other cycles.
23 these may expose other cycles.
24
24
25 $ hg locate 'mercurial/**.py' | xargs python "$import_checker"
25 $ hg locate 'mercurial/**.py' | xargs python "$import_checker"
26 mercurial/dispatch.py mixed stdlib and relative imports:
26 mercurial/dispatch.py mixed imports
27 commands, error, extensions, fancyopts, hg, hook, util
27 stdlib: commands
28 mercurial/fileset.py mixed stdlib and relative imports:
28 relative: error, extensions, fancyopts, hg, hook, util
29 error, merge, parser, util
29 mercurial/fileset.py mixed imports
30 mercurial/revset.py mixed stdlib and relative imports:
30 stdlib: parser
31 discovery, error, hbisect, parser, phases, util
31 relative: error, merge, util
32 mercurial/templater.py mixed stdlib and relative imports:
32 mercurial/revset.py mixed imports
33 config, error, parser, templatefilters, util
33 stdlib: parser
34 mercurial/ui.py mixed stdlib and relative imports:
34 relative: discovery, error, hbisect, phases, util
35 config, error, formatter, scmutil, util
35 mercurial/templater.py mixed imports
36 stdlib: parser
37 relative: config, error, templatefilters, util
38 mercurial/ui.py mixed imports
39 stdlib: formatter
40 relative: config, error, scmutil, util
36 Import cycle: mercurial.cmdutil -> mercurial.subrepo -> mercurial.cmdutil
41 Import cycle: mercurial.cmdutil -> mercurial.subrepo -> mercurial.cmdutil
37 Import cycle: mercurial.repoview -> mercurial.revset -> mercurial.repoview
42 Import cycle: mercurial.repoview -> mercurial.revset -> mercurial.repoview
38 Import cycle: mercurial.fileset -> mercurial.merge -> mercurial.subrepo -> mercurial.match -> mercurial.fileset
43 Import cycle: mercurial.fileset -> mercurial.merge -> mercurial.subrepo -> mercurial.match -> mercurial.fileset
General Comments 0
You need to be logged in to leave comments. Login now