py3: use print_function in import-checker

This commit is contained in:
timeless 2016-03-30 04:55:16 +00:00
parent 9580d303e6
commit 14b03acded
2 changed files with 6 additions and 7 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python
from __future__ import absolute_import
from __future__ import absolute_import, print_function
import ast
import collections
@ -544,11 +544,12 @@ def find_cycles(imports):
All module names recorded in `imports` should be absolute one.
>>> from __future__ import print_function
>>> imports = {'top.foo': ['top.bar', 'os.path', 'top.qux'],
... 'top.bar': ['top.baz', 'sys'],
... 'top.baz': ['top.foo'],
... 'top.qux': ['top.foo']}
>>> print '\\n'.join(sorted(find_cycles(imports)))
>>> print('\\n'.join(sorted(find_cycles(imports))))
top.bar -> top.baz -> top.foo -> top.bar
top.foo -> top.qux -> top.foo
"""
@ -566,7 +567,7 @@ def _cycle_sortkey(c):
def main(argv):
if len(argv) < 2 or (argv[1] == '-' and len(argv) > 2):
print 'Usage: %s {-|file [file] [file] ...}'
print('Usage: %s {-|file [file] [file] ...}')
return 1
if argv[1] == '-':
argv = argv[:1]
@ -584,7 +585,7 @@ def main(argv):
imported_modules(src, modname, localmods, ignore_nested=True))
for error, lineno in verify_import_convention(modname, src, localmods):
any_errors = True
print '%s:%d: %s' % (source_path, lineno, error)
print('%s:%d: %s' % (source_path, lineno, error))
f.close()
cycles = find_cycles(used_imports)
if cycles:
@ -596,7 +597,7 @@ def main(argv):
# of cycles that are effectively duplicates.
if first in firstmods:
continue
print 'Import cycle:', c
print('Import cycle:', c)
firstmods.add(first)
any_errors = True
return any_errors != 0

View File

@ -3,7 +3,6 @@
$ cd "$TESTDIR"/..
$ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs python contrib/check-py3-compat.py
contrib/import-checker.py requires print_function
doc/check-seclevel.py not using absolute_import
doc/gendoc.py not using absolute_import
doc/hgmanpage.py not using absolute_import
@ -112,7 +111,6 @@
#if py3exe
$ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs $PYTHON3 contrib/check-py3-compat.py
contrib/check-code.py: invalid syntax: (unicode error) 'unicodeescape' codec can't decode bytes in position *-*: malformed \N character escape (<unknown>, line *) (glob)
contrib/import-checker.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line *) (glob)
doc/hgmanpage.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
hgext/acl.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
hgext/automv.py: error importing module: <SyntaxError> invalid syntax (commands.py, line *) (line *) (glob)