[PATCH 2 of 5]revsetbenchmarks: use absolute_import and print_function

Pulkit Goyal 7895pulkit at gmail.com
Fri Mar 11 14:45:15 UTC 2016


# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1457228303 -19800
#      Sun Mar 06 07:08:23 2016 +0530
# Node ID d945babe0ded0a6edef49601ab44b35d7106f8b2
# Parent  3f76c4e8dd6b18d75fbcabc283dcfae14cc3ac3d
revsetbenchmarks: use absolute_import and print_function

diff -r 3f76c4e8dd6b -r d945babe0ded contrib/revsetbenchmarks.py
--- a/contrib/revsetbenchmarks.py    Sun Mar 06 06:49:13 2016 +0530
+++ b/contrib/revsetbenchmarks.py    Sun Mar 06 07:08:23 2016 +0530
@@ -8,11 +8,18 @@
 #
 # call with --help for details

-import sys
+from __future__ import absolute_import, print_function
+import math
 import os
 import re
-import math
-from subprocess import check_call, Popen, CalledProcessError, STDOUT, PIPE
+import sys
+from subprocess import (
+CalledProcessError,
+check_call,
+PIPE,
+Popen,
+STDOUT,
+)
 # cannot use argparse, python 2.7 only
 from optparse import OptionParser

@@ -36,7 +43,7 @@
         check_output(['make', 'local'],
                      stderr=None)  # suppress output except for error/warning
     except CalledProcessError as exc:
-        print >> sys.stderr, 'update to revision %s failed, aborting' % rev
+        print('update to revision %s failed, aborting' % rev, file=sys.stderr)
         sys.exit(exc.returncode)


@@ -62,11 +69,11 @@
         output = hg(args, repo=target)
         return parseoutput(output)
     except CalledProcessError as exc:
-        print >> sys.stderr, 'abort: cannot run revset benchmark: %s' % exc.cmd
+        print('abort: cannot run revset benchmark: %s'%exc.cmd,
file=sys.stderr)
         if getattr(exc, 'output', None) is None: # no output before 2.7
-            print >> sys.stderr, '(no output)'
+            print('(no output)', file=sys.stderr)
         else:
-            print >> sys.stderr, exc.output
+            print(exc.output, file=sys.stderr)
         return None

 outputre = re.compile(r'! wall (\d+.\d+) comb (\d+.\d+) user (\d+.\d+) '
@@ -80,8 +87,8 @@
     """
     match = outputre.search(output)
     if not match:
-        print >> sys.stderr, 'abort: invalid output:'
-        print >> sys.stderr, output
+        print('abort: invalid output:', file=sys.stderr)
+        print(output, file=sys.stderr)
         sys.exit(1)
     return {'comb': float(match.group(2)),
             'count': int(match.group(5)),
@@ -183,7 +190,7 @@
             out.append(formattiming(data[var]['user']))
             out.append(formattiming(data[var]['sys']))
             out.append('%6d'    % data[var]['count'])
-    print mask % (idx, ' '.join(out))
+    print(mask % (idx, ' '.join(out)))

 def printheader(variants, maxidx, verbose=False, relative=False):
     header = [' ' * (idxwidth(maxidx) + 1)]
@@ -200,14 +207,14 @@
             header.append('%-8s' % 'user')
             header.append('%-8s' % 'sys')
             header.append('%6s' % 'count')
-    print ' '.join(header)
+    print(' '.join(header))

 def getrevs(spec):
     """get the list of rev matched by a revset"""
     try:
         out = check_output(['hg', 'log', '--template={rev}\n', '--rev', spec])
     except CalledProcessError as exc:
-        print >> sys.stderr, "abort, can't get revision from %s" % spec
+        print("abort, can't get revision from %s" % spec, file=sys.stderr)
         sys.exit(exc.returncode)
     return [r for r in out.split() if r]

@@ -261,14 +268,14 @@
 revsets = [l.strip() for l in revsetsfile if not l.startswith('#')]
 revsets = [l for l in revsets if l]

-print "Revsets to benchmark"
-print "----------------------------"
+print("Revsets to benchmark")
+print("----------------------------")

 for idx, rset in enumerate(revsets):
-    print "%i) %s" % (idx, rset)
+    print("%i) %s" % (idx, rset))

-print "----------------------------"
-print
+print("----------------------------")
+print()

 revs = []
 for a in args:
@@ -278,9 +285,9 @@

 results = []
 for r in revs:
-    print "----------------------------"
+    print("----------------------------")
     printrevision(r)
-    print "----------------------------"
+    print("----------------------------")
     update(r)
     res = []
     results.append(res)
@@ -295,31 +302,31 @@
         printresult(variants, idx, varres, len(revsets),
                     verbose=options.verbose)
         sys.stdout.flush()
-    print "----------------------------"
+    print("----------------------------")


-print """
+print("""

 Result by revset
 ================
 """
-
-print 'Revision:'
+)
+print('Revision:')
 for idx, rev in enumerate(revs):
     sys.stdout.write('%i) ' % idx)
     sys.stdout.flush()
     printrevision(rev)

-print
-print
+print()
+print()

 for ridx, rset in enumerate(revsets):

-    print "revset #%i: %s" % (ridx, rset)
+    print("revset #%i: %s" % (ridx, rset))
     printheader(variants, len(results), verbose=options.verbose, relative=True)
     ref = None
     for idx, data in enumerate(results):
         printresult(variants, idx, data[ridx], len(results),
                     verbose=options.verbose, reference=ref)
         ref = data[ridx]
-    print
+    print()
diff -r 3f76c4e8dd6b -r d945babe0ded tests/test-check-py3-compat.t
--- a/tests/test-check-py3-compat.t    Sun Mar 06 06:49:13 2016 +0530
+++ b/tests/test-check-py3-compat.t    Sun Mar 06 07:08:23 2016 +0530
@@ -11,8 +11,6 @@
   contrib/memory.py not using absolute_import
   contrib/perf.py not using absolute_import
   contrib/python-hook-examples.py not using absolute_import
-  contrib/revsetbenchmarks.py not using absolute_import
-  contrib/revsetbenchmarks.py requires print_function
   contrib/showstack.py not using absolute_import
   contrib/synthrepo.py not using absolute_import
   contrib/win32/hgwebdir_wsgi.py not using absolute_import


More information about the Mercurial-devel mailing list