auto-optimize 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- auto_optimize/__init__.py +3 -0
- auto_optimize/__main__.py +5 -0
- auto_optimize/cli.py +651 -0
- auto_optimize/skills/auto-optimize-code/LICENSE +21 -0
- auto_optimize/skills/auto-optimize-code/SKILL.md +251 -0
- auto_optimize/skills/auto-optimize-code/VERSION +1 -0
- auto_optimize/skills/auto-optimize-code/references/algorithm.md +182 -0
- auto_optimize/skills/auto-optimize-code/references/changes.md +146 -0
- auto_optimize/skills/auto-optimize-code/references/cli.md +206 -0
- auto_optimize/skills/auto-optimize-code/references/dashboard.md +203 -0
- auto_optimize/skills/auto-optimize-code/references/documents.md +55 -0
- auto_optimize/skills/auto-optimize-code/references/extending.md +87 -0
- auto_optimize/skills/auto-optimize-code/references/external-validation.md +98 -0
- auto_optimize/skills/auto-optimize-code/references/glossary.md +134 -0
- auto_optimize/skills/auto-optimize-code/references/idea-miner.md +108 -0
- auto_optimize/skills/auto-optimize-code/references/issue-bugs.md +182 -0
- auto_optimize/skills/auto-optimize-code/references/layout.md +300 -0
- auto_optimize/skills/auto-optimize-code/references/main-session.md +45 -0
- auto_optimize/skills/auto-optimize-code/references/measuring.md +208 -0
- auto_optimize/skills/auto-optimize-code/references/pr-optimization.md +127 -0
- auto_optimize/skills/auto-optimize-code/references/pr-tests.md +254 -0
- auto_optimize/skills/auto-optimize-code/references/promotion.md +133 -0
- auto_optimize/skills/auto-optimize-code/references/reading-a-search.md +65 -0
- auto_optimize/skills/auto-optimize-code/references/repo-mode.md +224 -0
- auto_optimize/skills/auto-optimize-code/references/resume.md +81 -0
- auto_optimize/skills/auto-optimize-code/references/shared-knowledge.md +114 -0
- auto_optimize/skills/auto-optimize-code/references/step0-interview.md +298 -0
- auto_optimize/skills/auto-optimize-code/references/step1-unit-tests.md +136 -0
- auto_optimize/skills/auto-optimize-code/references/step2-baseline.md +708 -0
- auto_optimize/skills/auto-optimize-code/references/step3-rounds.md +350 -0
- auto_optimize/skills/auto-optimize-code/references/step4-final.md +121 -0
- auto_optimize/skills/auto-optimize-code/references/step5-ship.md +220 -0
- auto_optimize/skills/auto-optimize-code/references/step6-finish.md +67 -0
- auto_optimize/skills/auto-optimize-code/references/subagent.md +467 -0
- auto_optimize/skills/auto-optimize-code/references/symptoms.md +67 -0
- auto_optimize/skills/auto-optimize-code/references/writing-briefs.md +117 -0
- auto_optimize/skills/auto-optimize-code/scripts/attribution.py +156 -0
- auto_optimize/skills/auto-optimize-code/scripts/autoopt.py +12863 -0
- auto_optimize/skills/auto-optimize-code/scripts/check_seeding.py +334 -0
- auto_optimize/skills/auto-optimize-code/scripts/cold.py +90 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/README.md +165 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/autoopt_monitor.py +850 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/gpu_scan.py +954 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/monitor_writer.py +684 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/scan.py +1030 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/static/dashboard.css +775 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/static/dashboard.js +3652 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/static/index.html +191 -0
- auto_optimize/skills/auto-optimize-code/scripts/issue_body.py +2118 -0
- auto_optimize/skills/auto-optimize-code/scripts/lint_text.py +448 -0
- auto_optimize/skills/auto-optimize-code/scripts/opt_pr_body.py +894 -0
- auto_optimize/skills/auto-optimize-code/scripts/opt_pr_tables.py +367 -0
- auto_optimize/skills/auto-optimize-code/scripts/paired.py +188 -0
- auto_optimize/skills/auto-optimize-code/scripts/preflight.py +280 -0
- auto_optimize/skills/auto-optimize-code/scripts/probe_run.py +72 -0
- auto_optimize/skills/auto-optimize-code/scripts/publish.py +385 -0
- auto_optimize/skills/auto-optimize-code/scripts/run_iteration.py +1382 -0
- auto_optimize/skills/auto-optimize-code/scripts/ship.py +1193 -0
- auto_optimize/skills/auto-optimize-code/scripts/stages.py +651 -0
- auto_optimize/skills/auto-optimize-code/scripts/tests_pr_body.py +1267 -0
- auto_optimize/skills/auto-optimize-code/scripts/tests_pr_push.py +426 -0
- auto_optimize/skills/auto-optimize-code/scripts/tests_pr_tables.py +779 -0
- auto_optimize-1.0.0.dist-info/METADATA +610 -0
- auto_optimize-1.0.0.dist-info/RECORD +67 -0
- auto_optimize-1.0.0.dist-info/WHEEL +4 -0
- auto_optimize-1.0.0.dist-info/entry_points.txt +2 -0
- auto_optimize-1.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""The checks of a change that need no measurement, in one script.
|
|
3
|
+
|
|
4
|
+
python3 preflight.py WORK --id A12 # the iteration's own change, from its parent
|
|
5
|
+
python3 preflight.py WORK --id best --path # the whole path, from the commit the search copied
|
|
6
|
+
|
|
7
|
+
Four checks of the lines the change adds, each named in the output:
|
|
8
|
+
|
|
9
|
+
text comments that name the search (`lint_text.py`: winner, baseline,
|
|
10
|
+
a label such as A12, a path on this machine); the same in the
|
|
11
|
+
iteration's notes.md `## Change`, and the commit message rules
|
|
12
|
+
in its `## Commit message`, when it wrote them
|
|
13
|
+
indent an added line indented with tabs in a file indented with spaces,
|
|
14
|
+
or the reverse; a new file is compared with the repository's
|
|
15
|
+
files of the same extension
|
|
16
|
+
toolchain `after.oldest_toolchain_command`, run on an export of the tree
|
|
17
|
+
(`{src}`), exits non-zero: the oldest compiler or library the
|
|
18
|
+
repository supports does not build or pass. Skipped when the
|
|
19
|
+
key is unset
|
|
20
|
+
license an added line carries a license marker (an SPDX identifier, a
|
|
21
|
+
license name) of a family that cannot be added to a permissive
|
|
22
|
+
repository: GPL, LGPL, AGPL, MPL, a non-commercial or
|
|
23
|
+
share-alike terms. Code copied without any marker is not found
|
|
24
|
+
|
|
25
|
+
`autoopt.py promote` runs the first form in repository mode and refuses an
|
|
26
|
+
iteration with a problem, so it is fixed while its subagent is alive; the
|
|
27
|
+
second checks a whole winner at once.
|
|
28
|
+
`--path` writes `WORK/autooptimize/preflight.json` (`{winner, problems}`).
|
|
29
|
+
|
|
30
|
+
Exit codes: 0 no problem, 1 a problem (each on one line, `check: text`),
|
|
31
|
+
2 refused (not a repository search, no such iteration).
|
|
32
|
+
|
|
33
|
+
Standard library only, Python 3.9 or later; needs git.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
import os
|
|
37
|
+
import re
|
|
38
|
+
import sys
|
|
39
|
+
import json
|
|
40
|
+
import shutil
|
|
41
|
+
import argparse
|
|
42
|
+
import tempfile
|
|
43
|
+
import subprocess
|
|
44
|
+
import collections
|
|
45
|
+
|
|
46
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
47
|
+
|
|
48
|
+
import autoopt
|
|
49
|
+
import lint_text
|
|
50
|
+
|
|
51
|
+
# License families a permissive repository cannot take code from
|
|
52
|
+
# (references/promotion.md, *Code from another project*).
|
|
53
|
+
FORBIDDEN = (('GPL', re.compile(r'(?<![A-Za-z0-9])(A|L)?GPL(-| )?(v)?\d|GNU '
|
|
54
|
+
r'(Lesser |Affero |Library )?General Public', re.I)),
|
|
55
|
+
('MPL', re.compile(r'(?<![A-Za-z0-9])MPL-\d|Mozilla Public License', re.I)),
|
|
56
|
+
('non-commercial', re.compile(r'non-?commercial|academic use only|'
|
|
57
|
+
r'research use only|CC-BY-NC', re.I)),
|
|
58
|
+
('share-alike', re.compile(r'CC-BY-SA|ShareAlike', re.I)))
|
|
59
|
+
SAMPLE = 200
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def fail(message):
|
|
63
|
+
sys.stderr.write('preflight: {}\n'.format(message))
|
|
64
|
+
sys.exit(2)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def leading(line):
|
|
68
|
+
"""`tab`, `space` or None for a line's indentation."""
|
|
69
|
+
|
|
70
|
+
if line.startswith('\t'):
|
|
71
|
+
return 'tab'
|
|
72
|
+
|
|
73
|
+
return 'space' if line.startswith(' ') else None
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def style_of(lines):
|
|
77
|
+
"""The indentation most lines use, `tab` or `space`, or None when fewer
|
|
78
|
+
than five lines are indented or neither holds four fifths of them."""
|
|
79
|
+
|
|
80
|
+
count = collections.Counter(kind for kind in map(leading, lines) if kind)
|
|
81
|
+
total = sum(count.values())
|
|
82
|
+
|
|
83
|
+
if total < 5:
|
|
84
|
+
return None
|
|
85
|
+
|
|
86
|
+
kind, most = count.most_common(1)[0]
|
|
87
|
+
|
|
88
|
+
return kind if most >= 0.8 * total else None
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def blob_lines(bare, tree, path):
|
|
92
|
+
done = subprocess.run(['git', '-C', bare, 'show', '{}:{}'.format(tree,
|
|
93
|
+
path)], capture_output=True)
|
|
94
|
+
|
|
95
|
+
return done.stdout.decode('utf-8', 'replace').split('\n') if \
|
|
96
|
+
done.returncode == 0 else None
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def extension_style(bare, tree, path, cache):
|
|
100
|
+
"""The style of the repository's files with `path`'s extension."""
|
|
101
|
+
|
|
102
|
+
extension = os.path.splitext(path)[1]
|
|
103
|
+
|
|
104
|
+
if extension not in cache:
|
|
105
|
+
names = [name for name in subprocess.run(['git', '-C', bare, 'ls-tree',
|
|
106
|
+
'-r', '--name-only', tree], capture_output=True, text=True).stdout
|
|
107
|
+
.split('\n') if extension and name.endswith(extension)]
|
|
108
|
+
lines = []
|
|
109
|
+
|
|
110
|
+
for name in names[:20]:
|
|
111
|
+
lines += (blob_lines(bare, tree, name) or [])[:SAMPLE]
|
|
112
|
+
|
|
113
|
+
cache[extension] = style_of(lines)
|
|
114
|
+
|
|
115
|
+
return cache[extension]
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def indent_problems(bare, base, added):
|
|
119
|
+
"""Added lines whose indentation is not the file's."""
|
|
120
|
+
|
|
121
|
+
found, cache = [], {}
|
|
122
|
+
|
|
123
|
+
for path, lines in sorted(added.items()):
|
|
124
|
+
before = blob_lines(bare, base, path)
|
|
125
|
+
style = style_of(before) if before is not None else extension_style(
|
|
126
|
+
bare, base, path, cache)
|
|
127
|
+
|
|
128
|
+
if not style:
|
|
129
|
+
continue
|
|
130
|
+
|
|
131
|
+
wrong = [number for number, text in lines if leading(text) not in (
|
|
132
|
+
None, style)]
|
|
133
|
+
|
|
134
|
+
if wrong:
|
|
135
|
+
found.append('{}:{}: {} added line(s) are indented with {}s; the '
|
|
136
|
+
'{} is indented with {}s'.format(path, wrong[0], len(wrong),
|
|
137
|
+
'tab' if style == 'space' else 'space', 'file' if before is not
|
|
138
|
+
None else 'repository\'s {} files'.format(os.path.splitext(
|
|
139
|
+
path)[1]), style))
|
|
140
|
+
|
|
141
|
+
return found
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def license_problems(added):
|
|
145
|
+
found = []
|
|
146
|
+
|
|
147
|
+
for path, lines in sorted(added.items()):
|
|
148
|
+
for number, text in lines:
|
|
149
|
+
for family, pattern in FORBIDDEN:
|
|
150
|
+
if pattern.search(text):
|
|
151
|
+
found.append('{}:{}: the added line names a {} license, '
|
|
152
|
+
'which cannot be added to a permissive repository: '
|
|
153
|
+
'`{}`'.format(path, number, family, text.strip()[:120]))
|
|
154
|
+
break
|
|
155
|
+
|
|
156
|
+
return found
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def toolchain_problems(root, config, tree):
|
|
160
|
+
after = dict(autoopt.AFTER_DEFAULTS, **(config.get('after') or {}))
|
|
161
|
+
command = after.get('oldest_toolchain_command')
|
|
162
|
+
|
|
163
|
+
if not command:
|
|
164
|
+
return []
|
|
165
|
+
|
|
166
|
+
work = os.path.dirname(root)
|
|
167
|
+
scratch = autoopt.tmp_dir(work)
|
|
168
|
+
directory = tempfile.mkdtemp(prefix='preflight-', dir=scratch)
|
|
169
|
+
|
|
170
|
+
try:
|
|
171
|
+
archive = subprocess.run(['git', '-C', os.path.join(root, 'repo.git'),
|
|
172
|
+
'archive', tree], capture_output=True, check=True)
|
|
173
|
+
subprocess.run(['tar', '-x', '-C', directory], input=archive.stdout,
|
|
174
|
+
check=True)
|
|
175
|
+
done = subprocess.run(autoopt.fill(command, src=directory), shell=True,
|
|
176
|
+
cwd=directory, capture_output=True, text=True, errors='replace',
|
|
177
|
+
env=autoopt.clean_env(), stdin=subprocess.DEVNULL)
|
|
178
|
+
finally:
|
|
179
|
+
shutil.rmtree(directory, ignore_errors=True)
|
|
180
|
+
|
|
181
|
+
if done.returncode == 0:
|
|
182
|
+
return []
|
|
183
|
+
|
|
184
|
+
lines = [line for line in (done.stdout + done.stderr).splitlines() if
|
|
185
|
+
line.strip()]
|
|
186
|
+
|
|
187
|
+
return ['after.oldest_toolchain_command exited {}: {}'.format(
|
|
188
|
+
done.returncode, lines[-1][:300] if lines else 'no output')]
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def problems(root, config, identifier, whole=False):
|
|
192
|
+
"""`[(check, text)]` for iteration `identifier`: its own change, or with
|
|
193
|
+
`whole` everything from the commit the search copied."""
|
|
194
|
+
|
|
195
|
+
bare = os.path.join(root, 'repo.git')
|
|
196
|
+
meta = autoopt.load_meta(root, identifier)
|
|
197
|
+
|
|
198
|
+
if meta is None:
|
|
199
|
+
fail('no iteration {}'.format(identifier))
|
|
200
|
+
|
|
201
|
+
strip = autoopt.outputs_stripper(root, config)
|
|
202
|
+
tree_of = lambda ref: strip(autoopt.git('-C', bare, 'rev-parse', ref +
|
|
203
|
+
'^{tree}').strip())
|
|
204
|
+
parent = meta.get('parent')
|
|
205
|
+
base = tree_of(config['repo']['commit'] if whole or parent in (None, '',
|
|
206
|
+
'0', 0) else 'autoopt/{}'.format(parent))
|
|
207
|
+
tree = tree_of('autoopt/{}'.format(identifier))
|
|
208
|
+
added = lint_text.added_lines(bare, tree, base)
|
|
209
|
+
labels = [autoopt.label(root, i) for i in autoopt.iteration_ids(root)]
|
|
210
|
+
found = [('text', item) for item in lint_text.diff_problems(bare, tree,
|
|
211
|
+
base, labels)]
|
|
212
|
+
steps = autoopt.lineage(root, identifier)[1:] if whole else [identifier]
|
|
213
|
+
|
|
214
|
+
for step in steps:
|
|
215
|
+
fragment = autoopt.change_fragment(root, step)
|
|
216
|
+
name = autoopt.label(root, step)
|
|
217
|
+
|
|
218
|
+
# An iteration made after the end is promoted by hand, after its
|
|
219
|
+
# notes: what it lacks would be an agent's work at the review.
|
|
220
|
+
if not whole and (autoopt.load_meta(root, step) or {}).get('after_end'):
|
|
221
|
+
lacking = autoopt.fragment_problem(root, step)
|
|
222
|
+
|
|
223
|
+
if lacking:
|
|
224
|
+
found.append(('text', '{} notes.md {}'.format(name, lacking)))
|
|
225
|
+
|
|
226
|
+
if fragment['change']:
|
|
227
|
+
found += [('text', item) for item in lint_text.problems('{}\n{}'
|
|
228
|
+
.format(fragment['name'], fragment['change']), '{} notes.md '
|
|
229
|
+
'## Change'.format(name), labels)]
|
|
230
|
+
|
|
231
|
+
if fragment['message']:
|
|
232
|
+
found += [('text', '{} notes.md ## Commit message: {}'.format(name,
|
|
233
|
+
item)) for item in autoopt.message_problems(root,
|
|
234
|
+
autoopt.with_trailer(fragment['message'], autoopt.commit_trailer(
|
|
235
|
+
root)))]
|
|
236
|
+
|
|
237
|
+
found += [('indent', item) for item in indent_problems(bare, base, added)]
|
|
238
|
+
found += [('license', item) for item in license_problems(added)]
|
|
239
|
+
found += [('toolchain', item) for item in toolchain_problems(root, config,
|
|
240
|
+
tree)]
|
|
241
|
+
|
|
242
|
+
return found
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def main(argv=None):
|
|
246
|
+
parser = argparse.ArgumentParser(description=__doc__,
|
|
247
|
+
formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
248
|
+
parser.add_argument('work', help='the search\'s directory')
|
|
249
|
+
parser.add_argument('--id', default='best', help='the iteration (default '
|
|
250
|
+
'best)')
|
|
251
|
+
parser.add_argument('--path', action='store_true', help='check the whole '
|
|
252
|
+
'path from the commit the search copied, and write autooptimize/preflight.json')
|
|
253
|
+
args = parser.parse_args(argv)
|
|
254
|
+
root = autoopt.resolve(args.work)
|
|
255
|
+
config = autoopt.load_config(root)
|
|
256
|
+
|
|
257
|
+
if not config.get('repo'):
|
|
258
|
+
fail('this search was not made with `init --repo`')
|
|
259
|
+
|
|
260
|
+
identifier = autoopt.resolve_id(root, config, args.id)
|
|
261
|
+
found = problems(root, config, identifier, args.path)
|
|
262
|
+
|
|
263
|
+
if args.path:
|
|
264
|
+
path = os.path.join(root, 'preflight.json')
|
|
265
|
+
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
266
|
+
autoopt.write_json(path, {'winner': identifier, 'problems': [list(item)
|
|
267
|
+
for item in found]})
|
|
268
|
+
|
|
269
|
+
for check, text in found:
|
|
270
|
+
print('{}: {}'.format(check, text))
|
|
271
|
+
|
|
272
|
+
if not found:
|
|
273
|
+
print('preflight: no problem in {}'.format(autoopt.label(root,
|
|
274
|
+
identifier)))
|
|
275
|
+
|
|
276
|
+
return 1 if found else 0
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
if __name__ == '__main__':
|
|
280
|
+
sys.exit(main())
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""One timed run of a probe command, shared by `paired.py` and `cold.py`.
|
|
2
|
+
|
|
3
|
+
The command prints its seconds as the last number on its last line of
|
|
4
|
+
stdout and exits non-zero when its output is wrong.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
import re
|
|
9
|
+
import sys
|
|
10
|
+
import shlex
|
|
11
|
+
import signal
|
|
12
|
+
import subprocess
|
|
13
|
+
|
|
14
|
+
NUMBER = re.compile(r'[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?')
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def run_probe(template, directory, side, cache, extra=(), pattern=None,
|
|
18
|
+
timeout=None):
|
|
19
|
+
"""The seconds one run of `template` printed, or exit with why it did not.
|
|
20
|
+
|
|
21
|
+
`{src}` is `directory` and `{side}` the side's name, both shell-quoted.
|
|
22
|
+
`cache` is the compiler cache the run gets for numba, Triton and
|
|
23
|
+
Inductor; `extra` is `KEY=VALUE` items for the environment. `pattern` is
|
|
24
|
+
a regex whose first group is the seconds on the last line, for output
|
|
25
|
+
like `t=1.2s on GPU0` where the last number is not the time. A run past
|
|
26
|
+
`timeout` seconds is killed with everything it started, and exits 4.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
env = dict(os.environ, NUMBA_CACHE_DIR=cache,
|
|
30
|
+
TRITON_CACHE_DIR=os.path.join(cache, 'triton'),
|
|
31
|
+
TORCHINDUCTOR_CACHE_DIR=os.path.join(cache, 'inductor'))
|
|
32
|
+
|
|
33
|
+
for item in extra:
|
|
34
|
+
key, _, value = item.partition('=')
|
|
35
|
+
env[key] = value
|
|
36
|
+
|
|
37
|
+
command = template.format(src=shlex.quote(directory),
|
|
38
|
+
side=shlex.quote(side))
|
|
39
|
+
process = subprocess.Popen(command, shell=True, env=env, text=True,
|
|
40
|
+
stdout=subprocess.PIPE, stderr=subprocess.PIPE, start_new_session=True)
|
|
41
|
+
|
|
42
|
+
try:
|
|
43
|
+
out, err = process.communicate(timeout=timeout or None)
|
|
44
|
+
except subprocess.TimeoutExpired:
|
|
45
|
+
# The shell's children too: a hung tool outlives a killed shell.
|
|
46
|
+
try:
|
|
47
|
+
os.killpg(process.pid, signal.SIGKILL)
|
|
48
|
+
except ProcessLookupError:
|
|
49
|
+
pass
|
|
50
|
+
|
|
51
|
+
process.communicate()
|
|
52
|
+
print('side {} timed out after {:.0f} s and was killed: {}'.format(side,
|
|
53
|
+
timeout, command), file=sys.stderr)
|
|
54
|
+
sys.exit(4)
|
|
55
|
+
|
|
56
|
+
if process.returncode != 0:
|
|
57
|
+
sys.exit('side {} failed (exit {}): {}\n{}'.format(side,
|
|
58
|
+
process.returncode, command, (err or out)[-2000:]))
|
|
59
|
+
|
|
60
|
+
lines = [line for line in out.splitlines() if line.strip()]
|
|
61
|
+
last = lines[-1] if lines else ''
|
|
62
|
+
numbers = NUMBER.findall(last)
|
|
63
|
+
|
|
64
|
+
if pattern:
|
|
65
|
+
found = re.search(pattern, last)
|
|
66
|
+
numbers = [found.group(1)] if found else []
|
|
67
|
+
|
|
68
|
+
if not numbers:
|
|
69
|
+
sys.exit('side {} printed no number on its last line: {!r}'.format(
|
|
70
|
+
side, lines[-1] if lines else ''))
|
|
71
|
+
|
|
72
|
+
return float(numbers[-1])
|