##// END OF EJS Templates
py3: make contrib/revsetbenchmarks.py not import symbols from stdlib modules
Yuya Nishihara -
r29210:984c4d23 default
parent child Browse files
Show More
@@ -10,41 +10,32 b''
10
10
11 from __future__ import absolute_import, print_function
11 from __future__ import absolute_import, print_function
12 import math
12 import math
13 import optparse # cannot use argparse, python 2.7 only
13 import os
14 import os
14 import re
15 import re
16 import subprocess
15 import sys
17 import sys
16 from subprocess import (
17 CalledProcessError,
18 check_call,
19 PIPE,
20 Popen,
21 STDOUT,
22 )
23 # cannot use argparse, python 2.7 only
24 from optparse import (
25 OptionParser,
26 )
27
18
28 DEFAULTVARIANTS = ['plain', 'min', 'max', 'first', 'last',
19 DEFAULTVARIANTS = ['plain', 'min', 'max', 'first', 'last',
29 'reverse', 'reverse+first', 'reverse+last',
20 'reverse', 'reverse+first', 'reverse+last',
30 'sort', 'sort+first', 'sort+last']
21 'sort', 'sort+first', 'sort+last']
31
22
32 def check_output(*args, **kwargs):
23 def check_output(*args, **kwargs):
33 kwargs.setdefault('stderr', PIPE)
24 kwargs.setdefault('stderr', subprocess.PIPE)
34 kwargs.setdefault('stdout', PIPE)
25 kwargs.setdefault('stdout', subprocess.PIPE)
35 proc = Popen(*args, **kwargs)
26 proc = subprocess.Popen(*args, **kwargs)
36 output, error = proc.communicate()
27 output, error = proc.communicate()
37 if proc.returncode != 0:
28 if proc.returncode != 0:
38 raise CalledProcessError(proc.returncode, ' '.join(args[0]))
29 raise subprocess.CalledProcessError(proc.returncode, ' '.join(args[0]))
39 return output
30 return output
40
31
41 def update(rev):
32 def update(rev):
42 """update the repo to a revision"""
33 """update the repo to a revision"""
43 try:
34 try:
44 check_call(['hg', 'update', '--quiet', '--check', str(rev)])
35 subprocess.check_call(['hg', 'update', '--quiet', '--check', str(rev)])
45 check_output(['make', 'local'],
36 check_output(['make', 'local'],
46 stderr=None) # suppress output except for error/warning
37 stderr=None) # suppress output except for error/warning
47 except CalledProcessError as exc:
38 except subprocess.CalledProcessError as exc:
48 print('update to revision %s failed, aborting'%rev, file=sys.stderr)
39 print('update to revision %s failed, aborting'%rev, file=sys.stderr)
49 sys.exit(exc.returncode)
40 sys.exit(exc.returncode)
50
41
@@ -60,7 +51,7 b' def hg(cmd, repo=None):'
60 fullcmd += ['--config',
51 fullcmd += ['--config',
61 'extensions.perf=' + os.path.join(contribdir, 'perf.py')]
52 'extensions.perf=' + os.path.join(contribdir, 'perf.py')]
62 fullcmd += cmd
53 fullcmd += cmd
63 return check_output(fullcmd, stderr=STDOUT)
54 return check_output(fullcmd, stderr=subprocess.STDOUT)
64
55
65 def perf(revset, target=None, contexts=False):
56 def perf(revset, target=None, contexts=False):
66 """run benchmark for this very revset"""
57 """run benchmark for this very revset"""
@@ -70,7 +61,7 b' def perf(revset, target=None, contexts=F'
70 args.append('--contexts')
61 args.append('--contexts')
71 output = hg(args, repo=target)
62 output = hg(args, repo=target)
72 return parseoutput(output)
63 return parseoutput(output)
73 except CalledProcessError as exc:
64 except subprocess.CalledProcessError as exc:
74 print('abort: cannot run revset benchmark: %s'%exc.cmd, file=sys.stderr)
65 print('abort: cannot run revset benchmark: %s'%exc.cmd, file=sys.stderr)
75 if getattr(exc, 'output', None) is None: # no output before 2.7
66 if getattr(exc, 'output', None) is None: # no output before 2.7
76 print('(no output)', file=sys.stderr)
67 print('(no output)', file=sys.stderr)
@@ -103,9 +94,9 b' def printrevision(rev):'
103 """print data about a revision"""
94 """print data about a revision"""
104 sys.stdout.write("Revision ")
95 sys.stdout.write("Revision ")
105 sys.stdout.flush()
96 sys.stdout.flush()
106 check_call(['hg', 'log', '--rev', str(rev), '--template',
97 subprocess.check_call(['hg', 'log', '--rev', str(rev), '--template',
107 '{if(tags, " ({tags})")} '
98 '{if(tags, " ({tags})")} '
108 '{rev}:{node|short}: {desc|firstline}\n'])
99 '{rev}:{node|short}: {desc|firstline}\n'])
109
100
110 def idxwidth(nbidx):
101 def idxwidth(nbidx):
111 """return the max width of number used for index
102 """return the max width of number used for index
@@ -215,7 +206,7 b' def getrevs(spec):'
215 """get the list of rev matched by a revset"""
206 """get the list of rev matched by a revset"""
216 try:
207 try:
217 out = check_output(['hg', 'log', '--template={rev}\n', '--rev', spec])
208 out = check_output(['hg', 'log', '--template={rev}\n', '--rev', spec])
218 except CalledProcessError as exc:
209 except subprocess.CalledProcessError as exc:
219 print("abort, can't get revision from %s"%spec, file=sys.stderr)
210 print("abort, can't get revision from %s"%spec, file=sys.stderr)
220 sys.exit(exc.returncode)
211 sys.exit(exc.returncode)
221 return [r for r in out.split() if r]
212 return [r for r in out.split() if r]
@@ -234,8 +225,8 b' summary output is provided. Use it to de'
234 point regressions. Revsets to run are specified in a file (or from stdin), one
225 point regressions. Revsets to run are specified in a file (or from stdin), one
235 revsets per line. Line starting with '#' will be ignored, allowing insertion of
226 revsets per line. Line starting with '#' will be ignored, allowing insertion of
236 comments."""
227 comments."""
237 parser = OptionParser(usage="usage: %prog [options] <revs>",
228 parser = optparse.OptionParser(usage="usage: %prog [options] <revs>",
238 description=helptext)
229 description=helptext)
239 parser.add_option("-f", "--file",
230 parser.add_option("-f", "--file",
240 help="read revset from FILE (stdin if omitted)",
231 help="read revset from FILE (stdin if omitted)",
241 metavar="FILE")
232 metavar="FILE")
General Comments 0
You need to be logged in to leave comments. Login now