[PATCH 2 of 6]check-code: use absolute_import and print_function
Pulkit Goyal
7895pulkit at gmail.com
Sat Mar 5 21:28:54 UTC 2016
# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1457212958 -19800
# Sun Mar 06 02:52:38 2016 +0530
# Node ID 66064b2c5c954a4f050f76d34d8d77060a2dcc73
# Parent e544fb40b78c49f46449d403008431f2bc976876
check-code: use absolute_import and print_function
diff -r e544fb40b78c -r 66064b2c5c95 contrib/check-code.py
--- a/contrib/check-code.py Sun Mar 06 02:25:50 2016 +0530
+++ b/contrib/check-code.py Sun Mar 06 02:52:38 2016 +0530
@@ -18,10 +18,14 @@
* 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, print_function
+import glob
import keyword
import optparse
+import os
+import re
+import sys
+
try:
import re2
except ImportError:
@@ -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,18 @@
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 +505,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 +517,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 +548,7 @@
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 +568,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 e544fb40b78c -r 66064b2c5c95 tests/test-check-py3-compat.t
--- a/tests/test-check-py3-compat.t Sun Mar 06 02:25:50 2016 +0530
+++ b/tests/test-check-py3-compat.t Sun Mar 06 02:52:38 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
More information about the Mercurial-devel
mailing list