-
-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathcommands.py
More file actions
268 lines (213 loc) · 7.52 KB
/
commands.py
File metadata and controls
268 lines (213 loc) · 7.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
import logging
import os.path
import sys
def cmd_list(options, benchmarks):
print("%r benchmarks:" % options.benchmarks)
for bench in sorted(benchmarks):
print("- %s" % bench.name)
print()
print("Total: %s benchmarks" % len(benchmarks))
def cmd_list_groups(manifest, *, showtags=True):
all_benchmarks = set(manifest.benchmarks)
groups = sorted(manifest.groups - {"all", "default"})
groups[0:0] = ["all", "default"]
for group in groups:
specs = list(manifest.resolve_group(group))
known = set(specs) & all_benchmarks
if not known:
# skip empty groups
continue
print("%s (%s):" % (group, len(specs)))
for spec in sorted(specs):
print("- %s" % spec.name)
print()
if showtags:
print("=============================")
print()
print("tags:")
print()
tags = sorted(manifest.tags or ())
if not tags:
print("(no tags)")
else:
for tag in tags:
specs = list(manifest.resolve_group(tag))
known = set(specs) & all_benchmarks
if not known:
# skip empty groups
continue
print("%s (%s):" % (tag, len(specs)))
for spec in sorted(specs):
print("- %s" % spec.name)
print()
def cmd_venv_create(options, root, python, benchmarks):
from . import _venv
from .venv import Requirements, VenvForBenchmarks
if _venv.venv_exists(root):
sys.exit(f"ERROR: the virtual environment already exists at {root}")
requirements = Requirements.from_benchmarks(benchmarks)
venv = VenvForBenchmarks.ensure(
root,
python or sys.executable,
inherit_environ=options.inherit_environ,
)
venv.ensure_pip()
try:
venv.install_pyperformance()
venv.ensure_reqs(requirements)
except _venv.RequirementsInstallationFailedError:
sys.exit(1)
print("The virtual environment %s has been created" % root)
def cmd_venv_recreate(options, root, python, benchmarks):
from . import _utils, _venv
from .venv import Requirements, VenvForBenchmarks
requirements = Requirements.from_benchmarks(benchmarks)
if _venv.venv_exists(root):
venv_python = _venv.resolve_venv_python(root)
if venv_python == sys.executable:
print("The virtual environment %s already exists" % root)
print("(it matches the currently running Python executable)")
venv = VenvForBenchmarks(
root,
inherit_environ=options.inherit_environ,
)
venv.ensure_pip()
try:
venv.ensure_reqs(requirements)
except _venv.RequirementsInstallationFailedError:
sys.exit(1)
else:
print("The virtual environment %s already exists" % root)
_utils.safe_rmtree(root)
print("The old virtual environment %s has been removed" % root)
print()
venv = VenvForBenchmarks.ensure(
root,
python or sys.executable,
inherit_environ=options.inherit_environ,
)
venv.ensure_pip()
try:
venv.install_pyperformance()
venv.ensure_reqs(requirements)
except _venv.RequirementsInstallationFailedError:
sys.exit(1)
print("The virtual environment %s has been recreated" % root)
else:
venv = VenvForBenchmarks.create(
root,
python or sys.executable,
inherit_environ=options.inherit_environ,
)
venv.ensure_pip()
try:
venv.install_pyperformance()
venv.ensure_reqs(requirements)
except _venv.RequirementsInstallationFailedError:
sys.exit(1)
print("The virtual environment %s has been created" % root)
def cmd_venv_remove(options, root):
from . import _utils
if _utils.safe_rmtree(root):
print("The virtual environment %s has been removed" % root)
else:
print("The virtual environment %s does not exist" % root)
def cmd_venv_show(options, root):
from . import _venv
exists = _venv.venv_exists(root)
text = "Virtual environment path: %s" % root
if exists:
text += " (already created)"
else:
text += " (not created yet)"
print(text)
if not exists:
print()
print("Command to create it:")
cmd = "%s -m pyperformance venv create" % options.python
if options.venv:
cmd += " --venv=%s" % options.venv
print(cmd)
def cmd_run(options, benchmarks):
import pyperf
import pyperformance
from .compare import display_benchmark_suite
from .run import run_benchmarks
logging.basicConfig(level=logging.INFO)
print("Python benchmark suite %s" % pyperformance.__version__)
print()
if options.output and os.path.exists(options.output):
print("ERROR: the output file %s already exists!" % options.output)
sys.exit(1)
if hasattr(options, "python"):
executable = options.python
else:
executable = sys.executable
if not os.path.isabs(executable):
print('ERROR: "%s" is not an absolute path' % executable)
sys.exit(1)
suite, errors = run_benchmarks(benchmarks, executable, options)
if not suite:
print("ERROR: No benchmark was run")
sys.exit(1)
if options.output:
suite.dump(options.output)
if options.append:
pyperf.add_runs(options.append, suite)
display_benchmark_suite(suite)
if errors:
print("%s benchmarks failed:" % len(errors))
for name, reason in errors:
print("- %s (%s)" % (name, reason))
print()
sys.exit(1)
def cmd_compile(options):
from .compile import BenchmarkRevision, parse_config
conf = parse_config(options.config_file, "compile")
if options is not None:
if options.no_update:
conf.update = False
if options.no_tune:
conf.system_tune = False
bench = BenchmarkRevision(
conf, options.revision, options.branch, patch=options.patch, options=options
)
bench.main()
def cmd_compile_all(options):
from .compile import BenchmarkAll
bench = BenchmarkAll(options.config_file, options=options)
bench.main()
def cmd_upload(options):
import pyperf
from .compile import BenchmarkRevision, parse_config, parse_date
conf = parse_config(options.config_file, "upload")
filename = options.json_file
bench = pyperf.BenchmarkSuite.load(filename)
metadata = bench.get_metadata()
revision = metadata["commit_id"]
branch = metadata["commit_branch"]
commit_date = parse_date(metadata["commit_date"])
bench = BenchmarkRevision(
conf,
revision,
branch,
filename=filename,
commit_date=commit_date,
setup_log=False,
options=options,
)
bench.upload()
def cmd_show(options):
import pyperf
from .compare import display_benchmark_suite
suite = pyperf.BenchmarkSuite.load(options.filename)
display_benchmark_suite(suite)
def cmd_compare(options):
from .compare import VersionMismatchError, compare_results, write_csv
try:
results = compare_results(options)
except VersionMismatchError as exc:
print(f"ERROR: {exc}")
sys.exit(1)
if options.csv:
write_csv(results, options.csv)