Patchwork [2,of,8] import-checker: use print_function

login
register
mail settings
Submitter timeless@mozdev.org
Date March 30, 2016, 9:24 a.m.
Message ID <044a54c5a3b80596f4c0.1459329842@waste.org>
Download mbox | patch
Permalink /patch/14179/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

timeless@mozdev.org - March 30, 2016, 9:24 a.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1459313716 0
#      Wed Mar 30 04:55:16 2016 +0000
# Node ID 044a54c5a3b80596f4c0c3625905248b7557691a
# Parent  5c2c41affe213e7b8ad26759fd6ce5498f9d4b4c
import-checker: use print_function
Yuya Nishihara - March 31, 2016, 2:54 p.m.
On Wed, 30 Mar 2016 04:24:02 -0500, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1459313716 0
> #      Wed Mar 30 04:55:16 2016 +0000
> # Node ID 044a54c5a3b80596f4c0c3625905248b7557691a
> # Parent  5c2c41affe213e7b8ad26759fd6ce5498f9d4b4c
> import-checker: use print_function

Queued the first two, thanks.

Patch

diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -1,6 +1,6 @@ 
 #!/usr/bin/env python
 
-from __future__ import absolute_import
+from __future__ import absolute_import, print_function
 
 import ast
 import collections
@@ -546,11 +546,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
     """
@@ -568,7 +569,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]
@@ -586,7 +587,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:
@@ -598,7 +599,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
diff --git a/tests/test-check-py3-compat.t b/tests/test-check-py3-compat.t
--- a/tests/test-check-py3-compat.t
+++ b/tests/test-check-py3-compat.t
@@ -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
@@ -120,7 +119,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:10)
   hgext/automv.py: error importing module: <SyntaxError> invalid syntax (commands.py, line *) (line *) (glob)