annotate tests/test-module-imports.t @ 25174:86298718b01c

import-checker: make imported_modules yield absolute dotted_name_of_path This patch makes `imported_modules()` always yield absolute `dotted_name_of_path()`-ed name by strict detection with `fromlocal()`. This change improves circular detection in some points: - locally defined modules, of which name collides against one of standard library, can be examined correctly For example, circular import related to `commands` is overlooked before this patch. - names not useful for circular detection are ignored Names below are also yielded before this patch: - module names of standard library (= not locally defined one) - non-module names (e.g. `node.nullid` of `from node import nullid`) These redundant names decrease performance of circular detection. For example, with files at 1ef96a3b8b89, average loops per file in `checkmod()` is reduced from 165 to 109. - `__init__` can be handled correctly in `checkmod()` For example, current implementation has problems below: - `from xxx import yyy` doesn't recognize `xxx.__init__` as imported - `xxx.__init__` imported via `import xxx` is treated as `xxx`, and circular detection is aborted, because `key` of such module name is not `xxx` but `xxx.__init__` - it is easy to enhance for `from . import xxx` style or so (in the future) Module name detection in `imported_modules()` can use information in `ast.ImportFrom` fully. It is assumed that all locally defined modules are correctly specified to `import-checker.py` at once. Strictly speaking, when `from foo.bar.baz import module1` imports `foo.bar.baz.module1` module, current `imported_modules()` yields only `foo.bar.baz.__init__`, even though also `foo.__init__` and `foo.bar.__init__` should be yielded to detect circular import exactly. But this limitation is reasonable one for improvement in this patch, because current `__init__` files in Mercurial seems to be implemented carefully.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Mon, 18 May 2015 02:52:55 +0900
parents 723e364488f4
children 665a9deae8dd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23894
f388ceae2250 test-module-imports: use test-repo requirement
Matt Mackall <mpm@selenic.com>
parents: 22947
diff changeset
1 #require test-repo
f388ceae2250 test-module-imports: use test-repo requirement
Matt Mackall <mpm@selenic.com>
parents: 22947
diff changeset
2
20059
385e209377a6 test-module-imports: skip on Python < 2.6, since ast is new in 2.6
Augie Fackler <raf@durin42.com>
parents: 20039
diff changeset
3 This code uses the ast module, which was new in 2.6, so we'll skip
385e209377a6 test-module-imports: skip on Python < 2.6, since ast is new in 2.6
Augie Fackler <raf@durin42.com>
parents: 20039
diff changeset
4 this test on anything earlier.
22947
c63a09b6b337 tests: use $PYTHON instead of hardcoding python
Augie Fackler <raf@durin42.com>
parents: 20519
diff changeset
5 $ $PYTHON -c 'import sys ; assert sys.version_info >= (2, 6)' || exit 80
20059
385e209377a6 test-module-imports: skip on Python < 2.6, since ast is new in 2.6
Augie Fackler <raf@durin42.com>
parents: 20039
diff changeset
6
20039
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
7 $ import_checker="$TESTDIR"/../contrib/import-checker.py
23894
f388ceae2250 test-module-imports: use test-repo requirement
Matt Mackall <mpm@selenic.com>
parents: 22947
diff changeset
8
20039
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
9 Run the doctests from the import checker, and make sure
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
10 it's working correctly.
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
11 $ TERM=dumb
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
12 $ export TERM
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
13 $ python -m doctest $import_checker
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
14
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
15 $ cd "$TESTDIR"/..
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
16
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
17 There are a handful of cases here that require renaming a module so it
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
18 doesn't overlap with a stdlib module name. There are also some cycles
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
19 here that we should still endeavor to fix, and some cycles will be
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
20 hidden by deduplication algorithm in the cycle detector, so fixing
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
21 these may expose other cycles.
05626e87489c test-module-imports.t: new test to use the import cycle detector
Augie Fackler <raf@durin42.com>
parents:
diff changeset
22
25063
723e364488f4 import-checker: add xargs like mode
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24909
diff changeset
23 $ hg locate 'mercurial/**.py' | sed 's-\\-/-g' | python "$import_checker" -
20386
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
24 mercurial/dispatch.py mixed imports
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
25 stdlib: commands
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
26 relative: error, extensions, fancyopts, hg, hook, util
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
27 mercurial/fileset.py mixed imports
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
28 stdlib: parser
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
29 relative: error, merge, util
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
30 mercurial/revset.py mixed imports
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
31 stdlib: parser
24722
02a5618e2fbf revset: don't import discovery at module level
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24487
diff changeset
32 relative: error, hbisect, phases, util
20386
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
33 mercurial/templater.py mixed imports
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
34 stdlib: parser
20519
cda9d2b6beab template: add revset() template function
Durham Goode <durham@fb.com>
parents: 20405
diff changeset
35 relative: config, error, templatefilters, templatekw, util
20386
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
36 mercurial/ui.py mixed imports
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
37 stdlib: formatter
a05d31b040d7 import-checker: show stdlib and relative imports separately
Mads Kiilerich <madski@unity3d.com>
parents: 20199
diff changeset
38 relative: config, error, scmutil, util
24487
642d245ff537 import-checker: fix rotatecycle
Matt Mackall <mpm@selenic.com>
parents: 24423
diff changeset
39 Import cycle: mercurial.cmdutil -> mercurial.context -> mercurial.subrepo -> mercurial.cmdutil
25174
86298718b01c import-checker: make imported_modules yield absolute dotted_name_of_path
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25063
diff changeset
40 Import cycle: mercurial.commands -> mercurial.commandserver -> mercurial.dispatch -> mercurial.commands