changeset 28509:9e3ecb6f4995

check-code: use absolute_import and print_function
author Pulkit Goyal <7895pulkit@gmail.com>
date Sun, 13 Mar 2016 01:08:39 +0530
parents 3c6e94d0811c
children ade330deb39a
files contrib/check-code.py tests/test-check-py3-compat.t
diffstat 2 files changed, 18 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/check-code.py	Fri Mar 11 21:27:26 2016 -0800
+++ b/contrib/check-code.py	Sun Mar 13 01:08:39 2016 +0530
@@ -19,9 +19,13 @@
  * ONLY use no--check-code for skipping entire files from external sources
 """
 
-import re, glob, os, sys
+from __future__ import absolute_import, print_function
+import glob
 import keyword
 import optparse
+import os
+import re
+import sys
 try:
     import re2
 except ImportError:
@@ -443,12 +447,12 @@
         msgid = fname, lineno, line
         if msgid != self._lastseen:
             if blame:
-                print "%s:%d (%s):" % (fname, lineno, blame)
+                print("%s:%d (%s):" % (fname, lineno, blame))
             else:
-                print "%s:%d:" % (fname, lineno)
-            print " > %s" % line
+                print("%s:%d:" % (fname, lineno))
+            print(" > %s" % line)
             self._lastseen = msgid
-        print " " + msg
+        print(" " + msg)
 
 _defaultlogger = norepeatlogger()
 
@@ -478,19 +482,19 @@
     try:
         fp = open(f)
     except IOError as e:
-        print "Skipping %s, %s" % (f, str(e).split(':', 1)[0])
+        print("Skipping %s, %s" % (f, str(e).split(':', 1)[0]))
         return result
     pre = post = fp.read()
     fp.close()
 
     for name, match, magic, filters, pats in checks:
         if debug:
-            print name, f
+            print(name, f)
         fc = 0
         if not (re.match(match, f) or (magic and re.search(magic, pre))):
             if debug:
-                print "Skipping %s for %s it doesn't match %s" % (
-                       name, match, f)
+                print("Skipping %s for %s it doesn't match %s" % (
+                       name, match, f))
             continue
         if "no-" "check-code" in pre:
             # If you're looking at this line, it's because a file has:
@@ -499,7 +503,7 @@
             # tests easier. So, instead of writing it with a normal
             # spelling, we write it with the expected spelling from
             # tests/test-check-code.t
-            print "Skipping %s it has no-che?k-code (glob)" % f
+            print("Skipping %s it has no-che?k-code (glob)" % f)
             return "Skip" # skip checking this file
         for p, r in filters:
             post = re.sub(p, r, post)
@@ -511,7 +515,7 @@
         # print post # uncomment to show filtered version
 
         if debug:
-            print "Checking %s for %s" % (name, f)
+            print("Checking %s for %s" % (name, f))
 
         prelines = None
         errors = []
@@ -542,8 +546,8 @@
 
                 if ignore and re.search(ignore, l, re.MULTILINE):
                     if debug:
-                        print "Skipping %s for %s:%s (ignore pattern)" % (
-                            name, f, n)
+                        print("Skipping %s for %s:%s (ignore pattern)" % (
+                            name, f, n))
                     continue
                 bd = ""
                 if blame:
@@ -563,7 +567,7 @@
             logfunc(*e)
             fc += 1
             if maxerr and fc >= maxerr:
-                print " (too many errors, giving up)"
+                print(" (too many errors, giving up)")
                 break
 
     return result
--- a/tests/test-check-py3-compat.t	Fri Mar 11 21:27:26 2016 -0800
+++ b/tests/test-check-py3-compat.t	Sun Mar 13 01:08:39 2016 +0530
@@ -3,8 +3,6 @@
   $ cd "$TESTDIR"/..
 
   $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs python contrib/check-py3-compat.py
-  contrib/check-code.py not using absolute_import
-  contrib/check-code.py requires print_function
   contrib/import-checker.py not using absolute_import
   contrib/import-checker.py requires print_function
   contrib/memory.py not using absolute_import