[PATCH] check-code.py: use absolute_import and print_function

Pulkit Goyal 7895pulkit at gmail.com
Tue Mar 1 22:37:27 UTC 2016


# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1456871704 -19800
#      Wed Mar 02 04:05:04 2016 +0530
# Node ID 90d2a0ee68b0c280db54ac2af7c0446c336b3021
# Parent  31cedec0974f06ba10c0e40f8a36710b7d2ff5a3
check-code.py: Added absolute_import and print_function

diff -r 31cedec0974f -r 90d2a0ee68b0 contrib/check-code.py
--- a/contrib/check-code.py    Wed Mar 02 03:36:44 2016 +0530
+++ b/contrib/check-code.py    Wed Mar 02 04:05:04 2016 +0530
@@ -18,8 +18,12 @@
  * change the pattern to a warning and list the exception in
test-check-code-hg
  * ONLY use no--check-code for skipping entire files from external sources
 """
-
-import re, glob, os, sys
+from __future__ import absolute_import
+from __future__ import print_function
+import re
+import glob
+import os
+import sys
 import keyword
 import optparse
 try:
@@ -446,12 +450,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()

@@ -481,19 +485,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:
@@ -502,7 +506,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)
@@ -514,7 +518,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 = []
@@ -545,8 +549,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:
@@ -566,7 +570,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
diff -r 31cedec0974f -r 90d2a0ee68b0 tests/test-check-py3-compat.t
--- a/tests/test-check-py3-compat.t    Wed Mar 02 03:36:44 2016 +0530
+++ b/tests/test-check-py3-compat.t    Wed Mar 02 04:05:04 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/check-config.py not using absolute_import
   contrib/check-config.py requires print_function
   contrib/debugcmdserver.py not using absolute_import
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20160302/3c9a0aea/attachment.html>


More information about the Mercurial-devel mailing list