import-checker: convert localmods to a set of module names
This makes it easy to add a source-less module name to the set.
--- a/contrib/import-checker.py Tue May 02 22:24:57 2017 +0900
+++ b/contrib/import-checker.py Sun May 28 15:21:18 2017 +0900
@@ -88,9 +88,8 @@
`modulename` is an `dotted_name_of_path()`-ed source file path,
which may have `.__init__` at the end of it, of the target source.
- `localmods` is a dict (or set), of which key is an absolute
- `dotted_name_of_path()`-ed source file path of locally defined (=
- Mercurial specific) modules.
+ `localmods` is a set of absolute `dotted_name_of_path()`-ed source file
+ paths of locally defined (= Mercurial specific) modules.
This function assumes that module names not existing in
`localmods` are from the Python standard library.
@@ -114,9 +113,9 @@
convenient, even though this is also equivalent to "absname !=
dottednpath")
- >>> localmods = {'foo.__init__': True, 'foo.foo1': True,
- ... 'foo.bar.__init__': True, 'foo.bar.bar1': True,
- ... 'baz.__init__': True, 'baz.baz1': True }
+ >>> localmods = {'foo.__init__', 'foo.foo1',
+ ... 'foo.bar.__init__', 'foo.bar.bar1',
+ ... 'baz.__init__', 'baz.baz1'}
>>> fromlocal = fromlocalfunc('foo.xxx', localmods)
>>> # relative
>>> fromlocal('foo1')
@@ -257,7 +256,7 @@
Args:
source: The python source to examine as a string.
modulename: of specified python source (may have `__init__`)
- localmods: dict of locally defined module names (may have `__init__`)
+ localmods: set of locally defined module names (may have `__init__`)
ignore_nested: If true, import statements that do not start in
column zero will be ignored.
@@ -696,13 +695,14 @@
if argv[1] == '-':
argv = argv[:1]
argv.extend(l.rstrip() for l in sys.stdin.readlines())
- localmods = {}
+ localmodpaths = {}
used_imports = {}
any_errors = False
for source_path in argv[1:]:
modname = dotted_name_of_path(source_path)
- localmods[modname] = source_path
- for localmodname, source_path in sorted(localmods.items()):
+ localmodpaths[modname] = source_path
+ localmods = set(localmodpaths)
+ for localmodname, source_path in sorted(localmodpaths.items()):
for src, modname, name, line in sources(source_path, localmodname):
try:
used_imports[modname] = sorted(