changeset 28703:a274c4f9087a

py3: use print_function in import-checker
author timeless <timeless@mozdev.org>
date Wed, 30 Mar 2016 04:55:16 +0000
parents e44f671018e3
children 1fa6fdb72275
files contrib/import-checker.py tests/test-check-py3-compat.t
diffstat 2 files changed, 6 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/import-checker.py	Wed Mar 30 04:50:19 2016 +0000
+++ b/contrib/import-checker.py	Wed Mar 30 04:55:16 2016 +0000
@@ -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 @@
 
     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 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 @@
             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 @@
             # 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
--- a/tests/test-check-py3-compat.t	Wed Mar 30 04:50:19 2016 +0000
+++ b/tests/test-check-py3-compat.t	Wed Mar 30 04:55:16 2016 +0000
@@ -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)