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,2118 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""The bug report (a GitHub issue) on the original's repository, rendered
|
|
3
|
+
from structured inputs.
|
|
4
|
+
|
|
5
|
+
python3 issue_body.py template DIR > DIR/prose.md
|
|
6
|
+
python3 issue_body.py status DIR [--bin chromap=PATH]
|
|
7
|
+
python3 issue_body.py verify DIR --bin chromap=PATH [--bug N ... | --stale] [--commit REF] [--workdir DIR]
|
|
8
|
+
python3 issue_body.py verify DIR --bin chromap=PATH --manual N --reason TEXT --log FILE
|
|
9
|
+
python3 issue_body.py dupes DIR (--repo OWNER/REPO | --issues FILE)
|
|
10
|
+
python3 issue_body.py file DIR --repo OWNER/REPO [--post [--other-owner]]
|
|
11
|
+
python3 issue_body.py link DIR FILE... [--placeholder P] [--value #N]
|
|
12
|
+
python3 issue_body.py renumber DIR [--only N,N,... | --drop N,N,...] [--dry-run]
|
|
13
|
+
python3 issue_body.py [render] DIR --title 'Bugs found while testing <tool> <commit>' --out DIR/body.md
|
|
14
|
+
|
|
15
|
+
DIR is `$WORK/ship/issue-bugs`. Its inputs come from step 1, which leaves one
|
|
16
|
+
folder per bug in `$WORK/tests/work/bugs/<short-name>/` (what the code does,
|
|
17
|
+
what it should do, a reproducing command, the tests removed); a writer agent
|
|
18
|
+
turns those into the first two files here:
|
|
19
|
+
|
|
20
|
+
bugs.tsv one row per bug, tab-separated, with the header
|
|
21
|
+
number slug title short category severity effect related
|
|
22
|
+
prose.md fields that each start with a line `=== <field>`: opening,
|
|
23
|
+
intro, reading, setup.context, setup, and per bug
|
|
24
|
+
<n>.what, <n>.expected, <n>.cause, <n>.context,
|
|
25
|
+
<n>.reproduction, <n>.output, <n>.varies
|
|
26
|
+
verify.tsv written by `verify`: one row per bug, the reproduction's
|
|
27
|
+
result on one binary, by checksum
|
|
28
|
+
|
|
29
|
+
`render` (the default) computes the summary table, divided by each bug's
|
|
30
|
+
severity, the category sections in the fixed category order, every heading,
|
|
31
|
+
the collapsed blocks and the fences; prose fills them. The body is the first
|
|
32
|
+
paragraph (the `opening` sentence, then attribution.py's fixed sentences:
|
|
33
|
+
many bugs are edge cases, and what the severity levels mean), the severity
|
|
34
|
+
table, which shows all three levels and says `none` for one without a bug,
|
|
35
|
+
the introduction, the shared setup and the bugs. The title goes to `<out stem>.title`. The
|
|
36
|
+
same inputs give the same body, byte for byte. A body over --limit characters
|
|
37
|
+
(62,000) has its longest reproductions moved to `<out stem>.comment-1.md`,
|
|
38
|
+
then `-2.md` and on when one comment is not enough (packed in bug order, none
|
|
39
|
+
split), posted as the issue's comments in
|
|
40
|
+
that order, and stderr says so. Exit 1, every problem listed and nothing
|
|
41
|
+
written, on a missing or unknown field, an unknown category, a bug numbered
|
|
42
|
+
out of the category order, an unknown severity, blunt wording in the prose, a
|
|
43
|
+
bug without a passing or manual verify row for the text and binary shown,
|
|
44
|
+
verify rows from different binaries, a <<FILL placeholder, a heading, a fixed
|
|
45
|
+
sentence in prose, a title attribution.py refuses, words
|
|
46
|
+
lint_text.py refuses, or a body that does not fit even after the move.
|
|
47
|
+
|
|
48
|
+
`renumber` numbers the bugs 1 to N in category order and moves each bug's prose
|
|
49
|
+
fields, verify row and log with it (a bug appended under any unused number is
|
|
50
|
+
slotted in); `--only` and `--drop` keep fewer bugs. The originals go to
|
|
51
|
+
`DIR/before-renumber-<time>/`. Numbers inside sentences are reported, not
|
|
52
|
+
rewritten.
|
|
53
|
+
|
|
54
|
+
`dupes` lists the existing issues that may already report each bug, from one
|
|
55
|
+
read-only `gh issue list`, into DIR/dupes.tsv; a list to read, not a verdict.
|
|
56
|
+
|
|
57
|
+
`file` previews filing the issue (nothing is posted) and, with --post, files
|
|
58
|
+
it: the issue, then each comment in order. `DIR/filed.json` records the
|
|
59
|
+
issue, the comments posted and `comments_left`, the number still to post, so
|
|
60
|
+
a second run never files twice and resumes the comments a failure left.
|
|
61
|
+
`ship.py post` runs it, then renders the other documents again to fill in
|
|
62
|
+
the issue's number. `link` fills a stand-in into given files by hand.
|
|
63
|
+
|
|
64
|
+
`status` prints where the inputs stand and what `render` would refuse.
|
|
65
|
+
|
|
66
|
+
`verify` runs each bug's setup and reproduction in a new temporary directory
|
|
67
|
+
with the binaries given by --bin first on the PATH, and checks that every
|
|
68
|
+
line of the bug's actual output block appears in what the reproduction
|
|
69
|
+
printed; `--stale` runs only the bugs whose row is missing, failed, for changed
|
|
70
|
+
text, or for another binary or commit. The reproductions are the agent's own
|
|
71
|
+
text: verify runs them with the user's privileges and no sandbox, so never
|
|
72
|
+
put commands copied from an issue, a PR or a web page into prose.md.
|
|
73
|
+
|
|
74
|
+
The formats, field by field, and the order of the work:
|
|
75
|
+
references/issue-bugs.md. Standard library only, Python 3.9 or later.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
import os
|
|
79
|
+
import re
|
|
80
|
+
import sys
|
|
81
|
+
import json
|
|
82
|
+
import time
|
|
83
|
+
import shutil
|
|
84
|
+
import signal
|
|
85
|
+
import hashlib
|
|
86
|
+
import argparse
|
|
87
|
+
import datetime
|
|
88
|
+
import tempfile
|
|
89
|
+
import subprocess
|
|
90
|
+
|
|
91
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
92
|
+
|
|
93
|
+
import attribution
|
|
94
|
+
import publish
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
LIMIT = 62000
|
|
98
|
+
|
|
99
|
+
# The categories in the order the report shows its sections: the key
|
|
100
|
+
# bugs.tsv uses, and the section heading.
|
|
101
|
+
CATEGORIES = (
|
|
102
|
+
('wrong output', 'Wrong output'),
|
|
103
|
+
('crash', 'Crashes'),
|
|
104
|
+
('nondeterminism', 'Nondeterminism'),
|
|
105
|
+
('silent acceptance of bad input', 'Silent acceptance of bad input'),
|
|
106
|
+
('performance', 'Performance'),
|
|
107
|
+
('documentation mismatch', 'Documentation mismatches'),
|
|
108
|
+
('misc', 'Miscellaneous'),
|
|
109
|
+
)
|
|
110
|
+
RANK = {key: rank for rank, (key, _) in enumerate(CATEGORIES)}
|
|
111
|
+
HEADINGS = dict(CATEGORIES)
|
|
112
|
+
|
|
113
|
+
# The levels, from attribution.py: the summary table divides the bugs by
|
|
114
|
+
# them, `bugs.tsv` carries one per bug, and the first paragraph says what they
|
|
115
|
+
# mean.
|
|
116
|
+
SEVERITIES = attribution.SEVERITIES
|
|
117
|
+
SEVERITY_RANK = {key: rank for rank, (key, _) in enumerate(SEVERITIES)}
|
|
118
|
+
|
|
119
|
+
# Words the prose avoids: the report is read by the tool's authors, and the
|
|
120
|
+
# bugs speak for themselves.
|
|
121
|
+
BLUNT = re.compile(r'\b(broken|garbage|nonsense|sloppy|terrible|stupid|'
|
|
122
|
+
r'useless|awful|obviously|clearly wrong|simply wrong)\b', re.I)
|
|
123
|
+
|
|
124
|
+
COLUMNS = ('number', 'slug', 'title', 'short', 'category', 'severity',
|
|
125
|
+
'effect', 'related')
|
|
126
|
+
OPTIONAL_COLUMNS = ('short',)
|
|
127
|
+
|
|
128
|
+
# Field: (required, kind, what it holds, as `template` explains it). Kinds:
|
|
129
|
+
# `line` one line, `paragraph` one paragraph, `prose` Markdown, `commands`
|
|
130
|
+
# shell commands without a fence, `output` the expected and actual output,
|
|
131
|
+
# `patterns` regular expressions, one per line.
|
|
132
|
+
FIELDS = {
|
|
133
|
+
'opening': (True, 'line', 'one complete sentence of your own, on one line, '
|
|
134
|
+
'that begins the report: what was being done when the bugs turned up, '
|
|
135
|
+
'e.g. "These bugs turned up while we wrote a test suite for <tool> '
|
|
136
|
+
'(#209)." The renderer follows it with two fixed sentences in the same '
|
|
137
|
+
'paragraph: many of the bugs are likely edge cases, and what the '
|
|
138
|
+
'severity levels mean'),
|
|
139
|
+
'intro': (True, 'prose', 'the version, the commit, the build and the '
|
|
140
|
+
'platform the bugs were reproduced on; which bugs need a special build '
|
|
141
|
+
'or harness; which bugs came from which part of the work'),
|
|
142
|
+
'reading': (False, 'paragraph', 'optional: how to read the report, '
|
|
143
|
+
'appended to the intro\'s last paragraph. Delete the field to use the '
|
|
144
|
+
'default sentence'),
|
|
145
|
+
'setup.context': (False, 'prose', 'optional: what the shared setup needs '
|
|
146
|
+
'and makes, shown before its commands, e.g. "In an empty directory, '
|
|
147
|
+
'with `tool` and `python3` on the PATH."'),
|
|
148
|
+
'setup': (False, 'commands', 'optional: the shell commands every '
|
|
149
|
+
'reproduction starts from, without a code fence; verify runs them '
|
|
150
|
+
'before each bug'),
|
|
151
|
+
}
|
|
152
|
+
BUG_FIELDS = {
|
|
153
|
+
'what': (True, 'paragraph', 'what happens, with the numbers the '
|
|
154
|
+
'reproduction shows, in neutral words; it may end with a semicolon, '
|
|
155
|
+
'colon or comma and run on into `expected`'),
|
|
156
|
+
'expected': (True, 'paragraph', 'what should happen, and where that '
|
|
157
|
+
'expectation comes from (the README, the manual page, `-h`, a '
|
|
158
|
+
'specification, the code\'s own comments)'),
|
|
159
|
+
'cause': (True, 'paragraph', 'the code responsible, with file:line, and '
|
|
160
|
+
'a fix, as suggestions, hedged ("appears to", "we believe", "would '
|
|
161
|
+
'fix it")'),
|
|
162
|
+
'context': (False, 'prose', 'optional: what the reproduction needs beyond '
|
|
163
|
+
'the setup, or where it runs, shown before its commands'),
|
|
164
|
+
'reproduction': (True, 'commands', 'the shell commands, without a code '
|
|
165
|
+
'fence'),
|
|
166
|
+
'output': (True, 'output', 'a paragraph starting "Expected:", then a '
|
|
167
|
+
'paragraph starting "Actual" and a fenced block of the actual output, '
|
|
168
|
+
'cut to the lines that show the bug; a line `...` marks a cut. Other '
|
|
169
|
+
'paragraphs and blocks may come before or after'),
|
|
170
|
+
'varies': (False, 'patterns', 'optional: one regular expression per line '
|
|
171
|
+
'for values that change from run to run (timings); verify masks them in '
|
|
172
|
+
'the actual block and in what the reproduction printed before comparing'),
|
|
173
|
+
}
|
|
174
|
+
COMMAND_KINDS = ('commands', 'patterns')
|
|
175
|
+
|
|
176
|
+
VERIFY_COLUMNS = ('number', 'slug', 'status', 'exit', 'seconds', 'matched',
|
|
177
|
+
'checksum', 'commit', 'text', 'log', 'note', 'date')
|
|
178
|
+
|
|
179
|
+
SETUP_SUMMARY = 'Setup used by the reproductions'
|
|
180
|
+
READING = ('Each section below says what happens, what should happen and '
|
|
181
|
+
'which code we believe is responsible, and its collapsed block holds a '
|
|
182
|
+
'reproduction with the expected and actual output')
|
|
183
|
+
READING_SETUP = ('; the reproductions run in a directory prepared by the setup '
|
|
184
|
+
'block after the table, unless their section says otherwise')
|
|
185
|
+
MANUAL_NOTE = ('Not rerun before filing, unlike the other reproductions: {}; '
|
|
186
|
+
'the output shown is from an earlier run.')
|
|
187
|
+
MOVED_NOTE = ('The reproduction is in {}, moved there to keep this body under '
|
|
188
|
+
'GitHub\'s length limit.')
|
|
189
|
+
ORDINALS = ('first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh',
|
|
190
|
+
'eighth', 'ninth', 'tenth')
|
|
191
|
+
COMMENT_HEAD = ('Reproductions of {}, moved here from the issue body to keep it '
|
|
192
|
+
'under GitHub\'s length limit.')
|
|
193
|
+
|
|
194
|
+
FIELD = re.compile(r'^=== (\S+)[ \t]*$')
|
|
195
|
+
BUG_FIELD = re.compile(r'^(\d+)\.([a-z]+)$')
|
|
196
|
+
FENCE = re.compile(r'^\s{0,3}(```+|~~~+)(.*)$')
|
|
197
|
+
HEADING = re.compile(r'^\s{0,3}#{1,6}(\s|$)')
|
|
198
|
+
LIST_ITEM = re.compile(r'^\s*([-*+]|\d+[.)])\s')
|
|
199
|
+
SLUG = re.compile(r'^[a-z0-9][a-z0-9-]*$')
|
|
200
|
+
REFERENCE = re.compile(r'#\d+|https?://')
|
|
201
|
+
ELISION = ('...', '…')
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
class Problems(list):
|
|
205
|
+
def add(self, text):
|
|
206
|
+
if text not in self:
|
|
207
|
+
self.append(text)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
# Formatting ------------------------------------------------------------------
|
|
211
|
+
|
|
212
|
+
def bugs_named(numbers):
|
|
213
|
+
numbers = list(numbers)
|
|
214
|
+
return '{} {}'.format('bug' if len(numbers) == 1 else 'bugs',
|
|
215
|
+
publish.series(numbers))
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def trim(lines):
|
|
219
|
+
"""A field's text: trailing spaces and the blank lines around it removed,
|
|
220
|
+
indentation kept."""
|
|
221
|
+
|
|
222
|
+
lines = [line.rstrip() for line in lines]
|
|
223
|
+
|
|
224
|
+
while lines and not lines[0]:
|
|
225
|
+
lines.pop(0)
|
|
226
|
+
while lines and not lines[-1]:
|
|
227
|
+
lines.pop()
|
|
228
|
+
|
|
229
|
+
return '\n'.join(lines)
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def blocks(text):
|
|
233
|
+
"""Markdown text as a list of ('para', lines) and ('fence', info, lines,
|
|
234
|
+
opening line, closing line or None when unclosed), in order."""
|
|
235
|
+
|
|
236
|
+
out, para, fence = [], [], None
|
|
237
|
+
|
|
238
|
+
for line in text.split('\n'):
|
|
239
|
+
if fence is not None:
|
|
240
|
+
marker = FENCE.match(line)
|
|
241
|
+
if marker and marker.group(1)[0] == fence[0][0] \
|
|
242
|
+
and len(marker.group(1)) >= len(fence[0]) \
|
|
243
|
+
and not marker.group(2).strip():
|
|
244
|
+
out.append(('fence', fence[1], fence[2], fence[3], line))
|
|
245
|
+
fence = None
|
|
246
|
+
else:
|
|
247
|
+
fence[2].append(line)
|
|
248
|
+
continue
|
|
249
|
+
|
|
250
|
+
marker = FENCE.match(line)
|
|
251
|
+
if marker:
|
|
252
|
+
if para:
|
|
253
|
+
out.append(('para', para))
|
|
254
|
+
para = []
|
|
255
|
+
fence = (marker.group(1), marker.group(2).strip(), [], line)
|
|
256
|
+
continue
|
|
257
|
+
|
|
258
|
+
if not line.strip():
|
|
259
|
+
if para:
|
|
260
|
+
out.append(('para', para))
|
|
261
|
+
para = []
|
|
262
|
+
continue
|
|
263
|
+
|
|
264
|
+
para.append(line)
|
|
265
|
+
|
|
266
|
+
if fence is not None:
|
|
267
|
+
out.append(('fence', fence[1], fence[2], fence[3], None))
|
|
268
|
+
if para:
|
|
269
|
+
out.append(('para', para))
|
|
270
|
+
|
|
271
|
+
return out
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def unwrap_lines(lines):
|
|
275
|
+
"""A paragraph's lines joined: GitHub renders a line break inside an
|
|
276
|
+
issue's paragraph as a break. List items and table rows keep their lines."""
|
|
277
|
+
|
|
278
|
+
out = []
|
|
279
|
+
|
|
280
|
+
for line in lines:
|
|
281
|
+
stripped = line.strip()
|
|
282
|
+
previous = out[-1].lstrip() if out else ''
|
|
283
|
+
|
|
284
|
+
if not out or stripped.startswith('|') or LIST_ITEM.match(line) \
|
|
285
|
+
or previous.startswith('|'):
|
|
286
|
+
out.append(line.rstrip())
|
|
287
|
+
else:
|
|
288
|
+
out[-1] = out[-1].rstrip() + ' ' + stripped
|
|
289
|
+
|
|
290
|
+
return out
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def unwrap(text):
|
|
294
|
+
"""Markdown with each paragraph on one line, fenced blocks kept as they
|
|
295
|
+
are, one blank line between blocks."""
|
|
296
|
+
|
|
297
|
+
parts = []
|
|
298
|
+
|
|
299
|
+
for block in blocks(text):
|
|
300
|
+
if block[0] == 'para':
|
|
301
|
+
parts.append('\n'.join(unwrap_lines(block[1])))
|
|
302
|
+
else:
|
|
303
|
+
_, _, lines, opening, closing = block
|
|
304
|
+
parts.append('\n'.join([opening] + lines + [closing]))
|
|
305
|
+
|
|
306
|
+
return '\n\n'.join(parts)
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def prose_lines(text):
|
|
310
|
+
"""The lines of Markdown text outside fenced blocks."""
|
|
311
|
+
|
|
312
|
+
return [line for block in blocks(text) if block[0] == 'para'
|
|
313
|
+
for line in block[1]]
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def fenced(commands, info='bash'):
|
|
317
|
+
return '```{}\n{}\n```'.format(info, commands)
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
# Reading the inputs ----------------------------------------------------------
|
|
321
|
+
|
|
322
|
+
def read_text(path, problems, what):
|
|
323
|
+
try:
|
|
324
|
+
with open(path, encoding='utf-8') as handle:
|
|
325
|
+
return handle.read()
|
|
326
|
+
except OSError as error:
|
|
327
|
+
problems.add('{}: cannot read {} ({})'.format(what, path, error.strerror))
|
|
328
|
+
return None
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
def read_fields(path, problems):
|
|
332
|
+
"""The `=== <field>` fields of a prose file, in file order."""
|
|
333
|
+
|
|
334
|
+
text = read_text(path, problems, 'prose')
|
|
335
|
+
if text is None:
|
|
336
|
+
return {}
|
|
337
|
+
|
|
338
|
+
fields, name = {}, None
|
|
339
|
+
|
|
340
|
+
for number, line in enumerate(text.split('\n'), 1):
|
|
341
|
+
match = FIELD.match(line)
|
|
342
|
+
|
|
343
|
+
if match:
|
|
344
|
+
name = match.group(1)
|
|
345
|
+
if name in fields:
|
|
346
|
+
problems.add('prose: "=== {}" appears twice'.format(name))
|
|
347
|
+
fields[name] = []
|
|
348
|
+
elif name is not None:
|
|
349
|
+
fields[name].append(line)
|
|
350
|
+
elif line.strip():
|
|
351
|
+
problems.add('prose: line {} comes before the first "=== <field>" '
|
|
352
|
+
'line'.format(number))
|
|
353
|
+
|
|
354
|
+
return {key: trim(value) for key, value in fields.items()}
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
def split_effect(effect):
|
|
358
|
+
"""The terms of an effect cell, split at semicolons outside parentheses,
|
|
359
|
+
each without its parenthesized qualifier."""
|
|
360
|
+
|
|
361
|
+
terms, depth, current = [], 0, ''
|
|
362
|
+
|
|
363
|
+
for char in effect:
|
|
364
|
+
depth += (char == '(') - (char == ')')
|
|
365
|
+
if char == ';' and depth == 0:
|
|
366
|
+
terms.append(current)
|
|
367
|
+
current = ''
|
|
368
|
+
else:
|
|
369
|
+
current += char
|
|
370
|
+
|
|
371
|
+
terms.append(current)
|
|
372
|
+
return [re.sub(r'\s*\(.*\)\s*$', '', term).strip() for term in terms]
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
def check_row(bug, problems):
|
|
376
|
+
where = 'bug {}'.format(bug['number'])
|
|
377
|
+
|
|
378
|
+
if not SLUG.match(bug['slug']):
|
|
379
|
+
problems.add('{}: the slug {!r} must be lower-case letters, digits and '
|
|
380
|
+
'hyphens'.format(where, bug['slug']))
|
|
381
|
+
|
|
382
|
+
for column in ('title', 'short'):
|
|
383
|
+
value = bug.get(column, '-')
|
|
384
|
+
if not value:
|
|
385
|
+
problems.add('{}: the {} is empty{}'.format(where, column,
|
|
386
|
+
' (- uses the title)' if column == 'short' else ''))
|
|
387
|
+
elif value != '-' and value.endswith('.'):
|
|
388
|
+
problems.add('{}: the {} must not end with a period'.format(where,
|
|
389
|
+
column))
|
|
390
|
+
elif re.match(r'^\d+\.\s', value):
|
|
391
|
+
problems.add('{}: the {} must not start with a number; the renderer '
|
|
392
|
+
'numbers the bugs'.format(where, column))
|
|
393
|
+
|
|
394
|
+
if bug.get('severity') not in SEVERITY_RANK:
|
|
395
|
+
problems.add('{}: unknown severity {!r}; the severities are {}'.format(
|
|
396
|
+
where, bug.get('severity'), ', '.join(key for key, _ in
|
|
397
|
+
SEVERITIES)))
|
|
398
|
+
|
|
399
|
+
if bug['category'] not in RANK:
|
|
400
|
+
problems.add('{}: unknown category {!r}; the categories are {}'.format(
|
|
401
|
+
where, bug['category'], ', '.join(key for key, _ in CATEGORIES)))
|
|
402
|
+
else:
|
|
403
|
+
terms = split_effect(bug['effect'])
|
|
404
|
+
odd = [term for term in terms if term not in RANK]
|
|
405
|
+
if odd:
|
|
406
|
+
problems.add('{}: the effect lists {}, which {} not a category; list '
|
|
407
|
+
'categories, each with an optional qualifier in parentheses, '
|
|
408
|
+
'separated by semicolons'.format(where, ', '.join(repr(term)
|
|
409
|
+
for term in odd), 'is' if len(odd) == 1 else 'are'))
|
|
410
|
+
elif terms[0] != bug['category']:
|
|
411
|
+
problems.add('{}: the effect must start with the bug\'s own category, '
|
|
412
|
+
'{!r}'.format(where, bug['category']))
|
|
413
|
+
|
|
414
|
+
if bug['related'] != '-' and not REFERENCE.search(bug['related']):
|
|
415
|
+
problems.add('{}: related must be - or name an issue (#N) or a URL; it '
|
|
416
|
+
'is the text after "Related: "'.format(where))
|
|
417
|
+
|
|
418
|
+
for column, value in bug.items():
|
|
419
|
+
if '<<FILL' in str(value):
|
|
420
|
+
problems.add('{}: the {} holds a <<FILL placeholder'.format(where,
|
|
421
|
+
column))
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
def read_bugs(path, problems, strict=True):
|
|
425
|
+
"""bugs.tsv's rows, checked, in number order. Not strict, the numbers may
|
|
426
|
+
have gaps and be out of category order (`renumber` fixes both), but each
|
|
427
|
+
is still used once."""
|
|
428
|
+
|
|
429
|
+
text = read_text(path, problems, 'bugs.tsv')
|
|
430
|
+
if text is None:
|
|
431
|
+
return []
|
|
432
|
+
|
|
433
|
+
lines = text.rstrip('\n').split('\n')
|
|
434
|
+
header = [name.strip() for name in lines[0].split('\t')]
|
|
435
|
+
unknown = [name for name in header if name not in COLUMNS]
|
|
436
|
+
missing = [name for name in COLUMNS if name not in header
|
|
437
|
+
and name not in OPTIONAL_COLUMNS]
|
|
438
|
+
|
|
439
|
+
if unknown or missing:
|
|
440
|
+
problems.add('bugs.tsv: the header must be the columns {} (short is '
|
|
441
|
+
'optional); {}'.format(' '.join(COLUMNS), '; '.join(filter(None, [
|
|
442
|
+
'unknown: ' + ', '.join(unknown) if unknown else '',
|
|
443
|
+
'missing: ' + ', '.join(missing) if missing else '']))))
|
|
444
|
+
return []
|
|
445
|
+
|
|
446
|
+
bugs = []
|
|
447
|
+
|
|
448
|
+
for row_number, line in enumerate(lines[1:], 2):
|
|
449
|
+
cells = line.split('\t')
|
|
450
|
+
|
|
451
|
+
if len(cells) != len(header):
|
|
452
|
+
problems.add('bugs.tsv line {}: {} cells, the header has {}'.format(
|
|
453
|
+
row_number, len(cells), len(header)))
|
|
454
|
+
continue
|
|
455
|
+
|
|
456
|
+
row = dict(zip(header, (value.strip() for value in cells)))
|
|
457
|
+
|
|
458
|
+
if not row['number'].isdigit() or int(row['number']) < 1:
|
|
459
|
+
problems.add('bugs.tsv line {}: the number {!r} is not a whole number '
|
|
460
|
+
'from 1'.format(row_number, row['number']))
|
|
461
|
+
continue
|
|
462
|
+
|
|
463
|
+
bug = dict(row, number=int(row['number']))
|
|
464
|
+
check_row(bug, problems)
|
|
465
|
+
if bug.get('short', '-') == '-':
|
|
466
|
+
bug['short'] = bug['title']
|
|
467
|
+
bugs.append(bug)
|
|
468
|
+
|
|
469
|
+
numbers = sorted(bug['number'] for bug in bugs)
|
|
470
|
+
if not bugs:
|
|
471
|
+
problems.add('bugs.tsv: no bugs')
|
|
472
|
+
elif strict and numbers != list(range(1, len(bugs) + 1)):
|
|
473
|
+
problems.add('bugs.tsv: the numbers must run from 1 to {} once each; they '
|
|
474
|
+
'are {}'.format(len(bugs), ', '.join(str(n) for n in numbers)))
|
|
475
|
+
elif not strict:
|
|
476
|
+
for number in sorted(set(n for n in numbers if numbers.count(n) > 1)):
|
|
477
|
+
problems.add('bugs.tsv: the number {} is used twice'.format(number))
|
|
478
|
+
|
|
479
|
+
slugs = [bug['slug'] for bug in bugs]
|
|
480
|
+
for slug in sorted(set(s for s in slugs if slugs.count(s) > 1)):
|
|
481
|
+
problems.add('bugs.tsv: the slug {!r} is used twice'.format(slug))
|
|
482
|
+
|
|
483
|
+
bugs.sort(key=lambda bug: bug['number'])
|
|
484
|
+
ranked = [bug for bug in bugs if bug['category'] in RANK]
|
|
485
|
+
for before, after in zip(ranked, ranked[1:] if strict else []):
|
|
486
|
+
if RANK[before['category']] > RANK[after['category']]:
|
|
487
|
+
problems.add('bugs.tsv: number the bugs in the category order ({}): '
|
|
488
|
+
'bug {} ({}) comes before bug {} ({})'.format(', '.join(key
|
|
489
|
+
for key, _ in CATEGORIES), before['number'], before['category'],
|
|
490
|
+
after['number'], after['category']))
|
|
491
|
+
break
|
|
492
|
+
|
|
493
|
+
return bugs
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
def actual_block(output):
|
|
497
|
+
"""The lines of the fenced block after the `Actual` paragraph of a bug's
|
|
498
|
+
output, or None when the output does not have the required shape."""
|
|
499
|
+
|
|
500
|
+
items = blocks(output)
|
|
501
|
+
expected = next((i for i, block in enumerate(items) if block[0] == 'para'
|
|
502
|
+
and block[1][0].startswith('Expected')), None)
|
|
503
|
+
if expected is None:
|
|
504
|
+
return None
|
|
505
|
+
|
|
506
|
+
actual = next((i for i, block in enumerate(items) if i > expected
|
|
507
|
+
and block[0] == 'para' and block[1][0].startswith('Actual')), None)
|
|
508
|
+
if actual is None:
|
|
509
|
+
return None
|
|
510
|
+
|
|
511
|
+
fence = next((block for block in items[actual + 1:] if block[0] == 'fence'),
|
|
512
|
+
None)
|
|
513
|
+
if fence is None or fence[1] not in ('', 'text', 'console'):
|
|
514
|
+
return None
|
|
515
|
+
|
|
516
|
+
return fence[2]
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
def text_hash(fields, number):
|
|
520
|
+
"""What verify ran and compared, as a short hash: the setup, the
|
|
521
|
+
reproduction, the actual block and the masks."""
|
|
522
|
+
|
|
523
|
+
block = actual_block(fields.get('{}.output'.format(number), '')) or []
|
|
524
|
+
text = json.dumps([fields.get('setup', ''), fields.get('{}.reproduction'.format(
|
|
525
|
+
number), ''), block, fields.get('{}.varies'.format(number), '')])
|
|
526
|
+
return hashlib.sha256(text.encode('utf-8')).hexdigest()[:16]
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
def check_field(name, kind, text, problems):
|
|
530
|
+
where = 'prose: "=== {}"'.format(name)
|
|
531
|
+
|
|
532
|
+
if '<<FILL' in text:
|
|
533
|
+
problems.add('{} still holds a <<FILL placeholder'.format(where))
|
|
534
|
+
joined = ' '.join(text.split())
|
|
535
|
+
|
|
536
|
+
for note in attribution.ISSUE_NOTES:
|
|
537
|
+
if note in joined:
|
|
538
|
+
problems.add('{} holds the fixed sentence "{}", which the renderer '
|
|
539
|
+
'writes after the opening'.format(where, note[:60] + '...'))
|
|
540
|
+
|
|
541
|
+
if kind in COMMAND_KINDS:
|
|
542
|
+
if any(FENCE.match(line) for line in text.split('\n')):
|
|
543
|
+
problems.add('{} holds a code fence; it is commands only, and the '
|
|
544
|
+
'renderer adds the fence'.format(where))
|
|
545
|
+
if kind == 'patterns':
|
|
546
|
+
for line in text.split('\n'):
|
|
547
|
+
try:
|
|
548
|
+
re.compile(line)
|
|
549
|
+
except re.error as error:
|
|
550
|
+
problems.add('{}: {!r} is not a regular expression ({})'.format(
|
|
551
|
+
where, line, error))
|
|
552
|
+
return
|
|
553
|
+
|
|
554
|
+
for line in prose_lines(text):
|
|
555
|
+
if kind in ('line', 'prose', 'paragraph') and BLUNT.search(line):
|
|
556
|
+
problems.add('{} uses blunt wording ({!r}); describe what happens '
|
|
557
|
+
'and what was expected, and hedge the cause ("appears to", '
|
|
558
|
+
'"we believe", "would")'.format(where,
|
|
559
|
+
BLUNT.search(line).group(0)))
|
|
560
|
+
if HEADING.match(line):
|
|
561
|
+
problems.add('{} holds a heading ({!r}); the renderer writes every '
|
|
562
|
+
'heading'.format(where, line.strip()))
|
|
563
|
+
if re.search(r'\b(TODO|TBD|FIXME)\b', line):
|
|
564
|
+
problems.add('{} holds a placeholder word ({!r})'.format(where,
|
|
565
|
+
line.strip()))
|
|
566
|
+
|
|
567
|
+
if any(block[0] == 'fence' and block[4] is None for block in blocks(text)):
|
|
568
|
+
problems.add('{} has a code fence that is never closed'.format(where))
|
|
569
|
+
|
|
570
|
+
if kind == 'line' and '\n' in text:
|
|
571
|
+
problems.add('{} must be one line'.format(where))
|
|
572
|
+
elif name == 'opening':
|
|
573
|
+
if not re.match(r'^[`"*_(]*[A-Z0-9]', text):
|
|
574
|
+
problems.add('{} must be a complete sentence that starts with a '
|
|
575
|
+
'capital letter ("These bugs turned up while ...")'.format(where))
|
|
576
|
+
if not re.search(r'[.!?][)"\'`]*$', text):
|
|
577
|
+
problems.add('{} must be a complete sentence that ends with a '
|
|
578
|
+
'period'.format(where))
|
|
579
|
+
|
|
580
|
+
if kind == 'paragraph':
|
|
581
|
+
items = blocks(text)
|
|
582
|
+
if len(items) != 1 or items[0][0] != 'para' \
|
|
583
|
+
or any(LIST_ITEM.match(line) for line in items[0][1]):
|
|
584
|
+
problems.add('{} must be one paragraph, without lists or code '
|
|
585
|
+
'blocks: it is joined with the bug\'s other sentences'.format(where))
|
|
586
|
+
elif name.endswith('.what') and not re.search(r'[.;:,!?][)"\'`]*$', text):
|
|
587
|
+
problems.add('{} must end with a period, or with a semicolon, '
|
|
588
|
+
'colon or comma that runs on into `expected`'.format(where))
|
|
589
|
+
elif name.endswith(('.expected', '.cause')) \
|
|
590
|
+
and not re.search(r'[.!?][)"\'`]*$', text):
|
|
591
|
+
problems.add('{} must end with a period'.format(where))
|
|
592
|
+
|
|
593
|
+
if kind == 'output' and actual_block(text) is None:
|
|
594
|
+
problems.add('{} needs a paragraph starting "Expected", then a paragraph '
|
|
595
|
+
'starting "Actual" followed by a fenced block of the actual '
|
|
596
|
+
'output'.format(where))
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
def check_prose(bugs, fields, problems):
|
|
600
|
+
numbers = {bug['number'] for bug in bugs}
|
|
601
|
+
|
|
602
|
+
for name, text in fields.items():
|
|
603
|
+
match = BUG_FIELD.match(name)
|
|
604
|
+
|
|
605
|
+
if name in FIELDS:
|
|
606
|
+
kind = FIELDS[name][1]
|
|
607
|
+
elif match and match.group(2) in BUG_FIELDS:
|
|
608
|
+
kind = BUG_FIELDS[match.group(2)][1]
|
|
609
|
+
if int(match.group(1)) not in numbers:
|
|
610
|
+
problems.add('prose: "=== {}" is for bug {}, which bugs.tsv does '
|
|
611
|
+
'not have'.format(name, match.group(1)))
|
|
612
|
+
else:
|
|
613
|
+
problems.add('prose: no field is called {!r}; the fields are {}, and '
|
|
614
|
+
'per bug <n>.{}'.format(name, ', '.join(FIELDS),
|
|
615
|
+
', <n>.'.join(BUG_FIELDS)))
|
|
616
|
+
continue
|
|
617
|
+
|
|
618
|
+
check_field(name, kind, text, problems)
|
|
619
|
+
|
|
620
|
+
for name, (required, _, _) in FIELDS.items():
|
|
621
|
+
if required and not fields.get(name):
|
|
622
|
+
problems.add('prose: "=== {}" is missing or empty'.format(name))
|
|
623
|
+
elif name in fields and not fields[name]:
|
|
624
|
+
problems.add('prose: "=== {}" is empty; fill it or delete it'.format(
|
|
625
|
+
name))
|
|
626
|
+
|
|
627
|
+
for bug in bugs:
|
|
628
|
+
for key, (required, _, _) in BUG_FIELDS.items():
|
|
629
|
+
name = '{}.{}'.format(bug['number'], key)
|
|
630
|
+
if required and not fields.get(name):
|
|
631
|
+
problems.add('prose: "=== {}" is missing or empty'.format(name))
|
|
632
|
+
elif name in fields and not fields[name]:
|
|
633
|
+
problems.add('prose: "=== {}" is empty; fill it or delete '
|
|
634
|
+
'it'.format(name))
|
|
635
|
+
|
|
636
|
+
if fields.get('setup.context') and not fields.get('setup'):
|
|
637
|
+
problems.add('prose: "=== setup.context" without "=== setup"')
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
# verify.tsv ------------------------------------------------------------------
|
|
641
|
+
|
|
642
|
+
def read_verify(path, problems):
|
|
643
|
+
"""verify.tsv's rows by bug number; {} when there is no file."""
|
|
644
|
+
|
|
645
|
+
if not os.path.exists(path):
|
|
646
|
+
return {}
|
|
647
|
+
|
|
648
|
+
text = read_text(path, problems, 'verify.tsv') or ''
|
|
649
|
+
lines = text.rstrip('\n').split('\n')
|
|
650
|
+
|
|
651
|
+
if tuple(lines[0].split('\t')) != VERIFY_COLUMNS:
|
|
652
|
+
problems.add('verify.tsv: the header is not {}; it is written by '
|
|
653
|
+
'`issue_body.py verify`'.format(' '.join(VERIFY_COLUMNS)))
|
|
654
|
+
return {}
|
|
655
|
+
|
|
656
|
+
rows = {}
|
|
657
|
+
for line in lines[1:]:
|
|
658
|
+
row = dict(zip(VERIFY_COLUMNS, line.split('\t')))
|
|
659
|
+
if row.get('number', '').isdigit() and len(row) == len(VERIFY_COLUMNS):
|
|
660
|
+
rows[int(row['number'])] = row
|
|
661
|
+
else:
|
|
662
|
+
problems.add('verify.tsv: a malformed row ({!r})'.format(line[:60]))
|
|
663
|
+
|
|
664
|
+
return rows
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
def write_verify(path, rows):
|
|
668
|
+
temporary = path + '.tmp'
|
|
669
|
+
|
|
670
|
+
with open(temporary, 'w', encoding='utf-8', newline='\n') as out:
|
|
671
|
+
out.write('\t'.join(VERIFY_COLUMNS) + '\n')
|
|
672
|
+
for number in sorted(rows):
|
|
673
|
+
out.write('\t'.join(rows[number].get(column, '-')
|
|
674
|
+
for column in VERIFY_COLUMNS) + '\n')
|
|
675
|
+
|
|
676
|
+
os.replace(temporary, path)
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
def tsv_cell(text):
|
|
680
|
+
return re.sub(r'[\t\r\n]+', ' ', text).strip() or '-'
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
def stale_reason(row, fields, number, checksum, commit):
|
|
684
|
+
"""Why a bug's verify row no longer counts, or None: there is no row, it
|
|
685
|
+
did not pass (a manual row counts), the text it ran has changed, or it ran
|
|
686
|
+
another binary or commit than the ones now given."""
|
|
687
|
+
|
|
688
|
+
if row is None:
|
|
689
|
+
return 'never verified'
|
|
690
|
+
if row['text'] != text_hash(fields, number):
|
|
691
|
+
return 'the setup, reproduction, output or masks changed'
|
|
692
|
+
if row['status'] not in ('pass', 'manual'):
|
|
693
|
+
return 'it did not pass ({})'.format(row['status'])
|
|
694
|
+
if checksum and row['checksum'] != checksum:
|
|
695
|
+
return 'it ran another binary'
|
|
696
|
+
if commit and row['commit'] not in ('-', commit):
|
|
697
|
+
return 'it ran commit {}'.format(row['commit'])
|
|
698
|
+
|
|
699
|
+
return None
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
def check_verify(directory, bugs, fields, rows, binary, problems):
|
|
703
|
+
"""Every bug needs a pass or a justified manual row, for the text shown
|
|
704
|
+
now, and every row the same binary."""
|
|
705
|
+
|
|
706
|
+
if not rows:
|
|
707
|
+
problems.add('verify.tsv: missing or empty; run `issue_body.py verify '
|
|
708
|
+
'DIR --bin NAME=PATH` on the base first')
|
|
709
|
+
return
|
|
710
|
+
|
|
711
|
+
checksums, commits = {}, set()
|
|
712
|
+
|
|
713
|
+
for bug in bugs:
|
|
714
|
+
number = bug['number']
|
|
715
|
+
row = rows.get(number)
|
|
716
|
+
where = 'bug {}'.format(number)
|
|
717
|
+
|
|
718
|
+
if row is None:
|
|
719
|
+
problems.add('{}: no verify row; run `issue_body.py verify DIR --bin '
|
|
720
|
+
'NAME=PATH --bug {}`'.format(where, number))
|
|
721
|
+
continue
|
|
722
|
+
|
|
723
|
+
checksums.setdefault(row['checksum'], []).append(number)
|
|
724
|
+
commits.add(row['commit'])
|
|
725
|
+
|
|
726
|
+
if row['status'] == 'manual':
|
|
727
|
+
log = row['log'] if os.path.isabs(row['log']) else os.path.join(
|
|
728
|
+
directory, row['log'])
|
|
729
|
+
if row['note'] in ('', '-'):
|
|
730
|
+
problems.add('{}: marked manual without a reason'.format(where))
|
|
731
|
+
if not os.path.exists(log):
|
|
732
|
+
problems.add('{}: marked manual, but its log {} does not '
|
|
733
|
+
'exist'.format(where, row['log']))
|
|
734
|
+
elif row['status'] != 'pass':
|
|
735
|
+
problems.add('{}: verify gave {} ({}); fix the reproduction or the '
|
|
736
|
+
'output shown, then run verify again'.format(where, row['status'],
|
|
737
|
+
row['note']))
|
|
738
|
+
|
|
739
|
+
if row['text'] != text_hash(fields, number):
|
|
740
|
+
problems.add('{}: the setup, the reproduction, the actual output or '
|
|
741
|
+
'the masks changed since verify ran; run it again{}'.format(where,
|
|
742
|
+
' (or mark it manual again)' if row['status'] == 'manual' else ''))
|
|
743
|
+
|
|
744
|
+
if len(checksums) > 1:
|
|
745
|
+
problems.add('verify.tsv: the rows come from different binaries ({}); '
|
|
746
|
+
'verify every bug on the one the report names'.format('; '.join(
|
|
747
|
+
'{} for {}'.format(checksum[:12], bugs_named(numbers))
|
|
748
|
+
for checksum, numbers in sorted(checksums.items()))))
|
|
749
|
+
elif binary and checksums and list(checksums)[0] != binary:
|
|
750
|
+
problems.add('verify.tsv: the rows are for binary {}, not the one --bin '
|
|
751
|
+
'names ({})'.format(list(checksums)[0][:12], binary[:12]))
|
|
752
|
+
|
|
753
|
+
commits.discard('-')
|
|
754
|
+
if len(commits) > 1:
|
|
755
|
+
problems.add('verify.tsv: the rows name different commits ({})'.format(
|
|
756
|
+
', '.join(sorted(commits))))
|
|
757
|
+
elif commits and list(commits)[0] not in fields.get('intro', ''):
|
|
758
|
+
problems.add('prose: "=== intro" does not name commit {}, which verify '
|
|
759
|
+
'ran'.format(list(commits)[0]))
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
# Rendering -------------------------------------------------------------------
|
|
763
|
+
|
|
764
|
+
def bug_paragraph(bug, fields):
|
|
765
|
+
parts = [' '.join(unwrap_lines(fields['{}.{}'.format(bug['number'],
|
|
766
|
+
key)].split('\n'))) for key in ('what', 'expected', 'cause')]
|
|
767
|
+
related = bug['related']
|
|
768
|
+
|
|
769
|
+
if related != '-':
|
|
770
|
+
parts.append('Related: {}{}'.format(related, '' if related.endswith('.')
|
|
771
|
+
else '.'))
|
|
772
|
+
|
|
773
|
+
return ' '.join(parts)
|
|
774
|
+
|
|
775
|
+
|
|
776
|
+
def reproduction(bug, fields, rows):
|
|
777
|
+
number = bug['number']
|
|
778
|
+
parts = []
|
|
779
|
+
row = rows.get(number, {})
|
|
780
|
+
|
|
781
|
+
if row.get('status') == 'manual':
|
|
782
|
+
parts.append(MANUAL_NOTE.format(row['note'].rstrip('.')))
|
|
783
|
+
|
|
784
|
+
if fields.get('{}.context'.format(number)):
|
|
785
|
+
parts.append(unwrap(fields['{}.context'.format(number)]))
|
|
786
|
+
|
|
787
|
+
parts.append(fenced(fields['{}.reproduction'.format(number)]))
|
|
788
|
+
parts.append(unwrap(fields['{}.output'.format(number)]))
|
|
789
|
+
|
|
790
|
+
return '<details><summary>Reproduction</summary>\n\n{}\n\n</details>'.format(
|
|
791
|
+
'\n\n'.join(parts))
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
def table(bugs):
|
|
795
|
+
"""One table, divided by severity: every level in order, high first, with
|
|
796
|
+
its bugs in number order and its name on its first row, or the word
|
|
797
|
+
`none` when it has no bug."""
|
|
798
|
+
|
|
799
|
+
lines = ['| Severity | # | Bug | Category | Effect |',
|
|
800
|
+
'|---|---:|---|---|---|']
|
|
801
|
+
|
|
802
|
+
for level, _ in SEVERITIES:
|
|
803
|
+
mine = sorted((bug for bug in bugs if bug['severity'] == level),
|
|
804
|
+
key=lambda bug: bug['number'])
|
|
805
|
+
|
|
806
|
+
if not mine:
|
|
807
|
+
lines.append('| **{}** | | none | | |'.format(level))
|
|
808
|
+
|
|
809
|
+
for index, bug in enumerate(mine):
|
|
810
|
+
lines.append('| {} | {} | {} | {} | {} |'.format(
|
|
811
|
+
'**{}**'.format(level) if index == 0 else '', bug['number'],
|
|
812
|
+
publish.cell(bug['short']), publish.cell(bug['category']),
|
|
813
|
+
publish.cell(bug['effect'])))
|
|
814
|
+
|
|
815
|
+
return '\n'.join(lines)
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
def introduction(fields):
|
|
819
|
+
reading = fields.get('reading') or READING + (READING_SETUP
|
|
820
|
+
if fields.get('setup') else '') + '.'
|
|
821
|
+
reading = ' '.join(unwrap_lines(reading.split('\n')))
|
|
822
|
+
intro = unwrap(fields['intro'])
|
|
823
|
+
items = blocks(intro)
|
|
824
|
+
|
|
825
|
+
if items and items[-1][0] == 'para' and not any(LIST_ITEM.match(line)
|
|
826
|
+
or line.lstrip().startswith('|') for line in items[-1][1]):
|
|
827
|
+
return intro + ' ' + reading
|
|
828
|
+
|
|
829
|
+
return intro + '\n\n' + reading
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
def opening_paragraph(fields):
|
|
833
|
+
"""The first paragraph: the writer's `opening` sentence, then the fixed
|
|
834
|
+
sentences of attribution.ISSUE_NOTES."""
|
|
835
|
+
|
|
836
|
+
return ' '.join([fields['opening'].strip()] + list(attribution.ISSUE_NOTES))
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
def comment_name(index):
|
|
840
|
+
"""How the body names comment number `index` (from 1)."""
|
|
841
|
+
|
|
842
|
+
return 'the {} comment'.format(ORDINALS[index - 1]) if index <= len(
|
|
843
|
+
ORDINALS) else 'comment {}'.format(index)
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
def pack(numbers, sections, titles, limit):
|
|
847
|
+
"""The bugs `numbers` split into comments, in number order: each comment
|
|
848
|
+
takes bugs until the next would pass `limit`. A bug whose section alone is
|
|
849
|
+
over the limit gets a comment of its own."""
|
|
850
|
+
|
|
851
|
+
groups = []
|
|
852
|
+
|
|
853
|
+
for number in sorted(numbers):
|
|
854
|
+
if groups and len(comment_text(groups[-1] + [number], sections,
|
|
855
|
+
titles)) <= limit:
|
|
856
|
+
groups[-1].append(number)
|
|
857
|
+
else:
|
|
858
|
+
groups.append([number])
|
|
859
|
+
|
|
860
|
+
return groups
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
def comment_text(numbers, sections, titles):
|
|
864
|
+
return '\n\n'.join([COMMENT_HEAD.format(bugs_named(numbers))]
|
|
865
|
+
+ ['### {}. {}\n\n{}'.format(number, titles[number], sections[number])
|
|
866
|
+
for number in numbers]) + '\n'
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
def render(bugs, fields, rows, limit):
|
|
870
|
+
"""The body, and the comments the moved reproductions fill, as a list of
|
|
871
|
+
(the numbers of the bugs in it, its text)."""
|
|
872
|
+
|
|
873
|
+
head = [opening_paragraph(fields), table(bugs), introduction(fields)]
|
|
874
|
+
|
|
875
|
+
if fields.get('setup'):
|
|
876
|
+
setup = [unwrap(fields['setup.context'])] if fields.get('setup.context') \
|
|
877
|
+
else []
|
|
878
|
+
setup.append(fenced(fields['setup']))
|
|
879
|
+
head.append('<details><summary>{}</summary>\n\n{}\n\n</details>'.format(
|
|
880
|
+
SETUP_SUMMARY, '\n\n'.join(setup)))
|
|
881
|
+
|
|
882
|
+
sections = {bug['number']: reproduction(bug, fields, rows) for bug in bugs}
|
|
883
|
+
titles = {bug['number']: bug['title'] for bug in bugs}
|
|
884
|
+
|
|
885
|
+
def assemble(groups):
|
|
886
|
+
where = {number: index for index, group in enumerate(groups, 1)
|
|
887
|
+
for number in group}
|
|
888
|
+
parts = list(head)
|
|
889
|
+
category = None
|
|
890
|
+
|
|
891
|
+
for bug in bugs:
|
|
892
|
+
if bug['category'] != category:
|
|
893
|
+
category = bug['category']
|
|
894
|
+
parts.append('## ' + HEADINGS[category])
|
|
895
|
+
|
|
896
|
+
parts.append('### {}. {}'.format(bug['number'], bug['title']))
|
|
897
|
+
parts.append(bug_paragraph(bug, fields))
|
|
898
|
+
parts.append(MOVED_NOTE.format(comment_name(where[bug['number']]))
|
|
899
|
+
if bug['number'] in where else sections[bug['number']])
|
|
900
|
+
|
|
901
|
+
return '\n\n'.join(parts) + '\n'
|
|
902
|
+
|
|
903
|
+
moved, groups = [], []
|
|
904
|
+
body = assemble(groups)
|
|
905
|
+
longest = sorted(sections, key=lambda number: (-len(sections[number]), number))
|
|
906
|
+
|
|
907
|
+
while len(body) > limit and len(moved) < len(longest):
|
|
908
|
+
moved.append(longest[len(moved)])
|
|
909
|
+
groups = pack(moved, sections, titles, limit)
|
|
910
|
+
body = assemble(groups)
|
|
911
|
+
|
|
912
|
+
return body, [(group, comment_text(group, sections, titles))
|
|
913
|
+
for group in groups]
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
write = publish.write
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
def refuse(problems, left='nothing written'):
|
|
920
|
+
return publish.refuse('issue_body', problems, left)
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
NO_TITLE = ('--out needs --title: the body is not written without the title '
|
|
924
|
+
'it will be opened with, and none is stored beside it')
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
def render_command(args):
|
|
928
|
+
if not args.dir:
|
|
929
|
+
return refuse(['name the input directory: issue_body.py render DIR '
|
|
930
|
+
'--title TITLE --out DIR/body.md'])
|
|
931
|
+
|
|
932
|
+
problems = Problems()
|
|
933
|
+
fields = read_fields(args.prose or os.path.join(args.dir, 'prose.md'),
|
|
934
|
+
problems)
|
|
935
|
+
bugs = read_bugs(os.path.join(args.dir, 'bugs.tsv'), problems)
|
|
936
|
+
check_prose(bugs, fields, problems)
|
|
937
|
+
rows = read_verify(os.path.join(args.dir, 'verify.tsv'), problems)
|
|
938
|
+
bins = parse_bins(args.bin, problems)
|
|
939
|
+
check_verify(args.dir, bugs, fields, rows, checksum_of(bins) if bins
|
|
940
|
+
else None, problems)
|
|
941
|
+
|
|
942
|
+
title = args.title or publish.stored_title(args.out)
|
|
943
|
+
|
|
944
|
+
if not title:
|
|
945
|
+
problems.add(NO_TITLE)
|
|
946
|
+
|
|
947
|
+
for problem in attribution.title_problems(title) if title else ():
|
|
948
|
+
problems.add('title: ' + problem)
|
|
949
|
+
|
|
950
|
+
if not os.path.isdir(os.path.dirname(os.path.abspath(args.out))):
|
|
951
|
+
problems.add('--out: the directory of {} does not exist'.format(args.out))
|
|
952
|
+
|
|
953
|
+
if problems:
|
|
954
|
+
return refuse(problems)
|
|
955
|
+
|
|
956
|
+
body, comments = render(bugs, fields, rows, args.limit)
|
|
957
|
+
|
|
958
|
+
import lint_text
|
|
959
|
+
|
|
960
|
+
for index, (_, text) in enumerate(comments, 1):
|
|
961
|
+
for problem in lint_text.problems(text, 'comment {}'.format(index)):
|
|
962
|
+
problems.add(problem)
|
|
963
|
+
|
|
964
|
+
if len(body) > args.limit:
|
|
965
|
+
problems.add('the body is {:,} characters with every reproduction moved '
|
|
966
|
+
'to comments, over the limit of {:,}; shorten the prose'.format(
|
|
967
|
+
len(body), args.limit))
|
|
968
|
+
|
|
969
|
+
for numbers, text in comments:
|
|
970
|
+
if len(text) > args.limit:
|
|
971
|
+
problems.add('the comment holding {} would be {:,} characters, over '
|
|
972
|
+
'the limit of {:,}; shorten its reproduction'.format(bugs_named(
|
|
973
|
+
numbers), len(text), args.limit))
|
|
974
|
+
|
|
975
|
+
# The body and its title, after the title and vocabulary checks every
|
|
976
|
+
# posted document gets; a problem from either writes nothing.
|
|
977
|
+
if publish.emit('issue_body', body, problems, title, args.out):
|
|
978
|
+
return 1
|
|
979
|
+
|
|
980
|
+
stem = os.path.splitext(args.out)[0]
|
|
981
|
+
|
|
982
|
+
for index, (numbers, text) in enumerate(comments, 1):
|
|
983
|
+
path = '{}.comment-{}.md'.format(stem, index)
|
|
984
|
+
write(path, text)
|
|
985
|
+
sys.stderr.write('issue_body: {} holds the reproductions of {} ({:,} '
|
|
986
|
+
'characters): it is posted as comment {} right after the issue\n'
|
|
987
|
+
.format(path, bugs_named(numbers), len(text), index))
|
|
988
|
+
|
|
989
|
+
if comments:
|
|
990
|
+
sys.stderr.write('issue_body: the body was over {:,} characters, so the '
|
|
991
|
+
'reproductions moved to {} comment{}, posted in order\n'.format(
|
|
992
|
+
args.limit, len(comments), attribution.plural(len(comments))))
|
|
993
|
+
|
|
994
|
+
for stale in comment_files(stem, len(comments)):
|
|
995
|
+
os.remove(stale)
|
|
996
|
+
sys.stderr.write('issue_body: removed {}, left from an earlier render\n'
|
|
997
|
+
.format(stale))
|
|
998
|
+
|
|
999
|
+
sys.stderr.write('issue_body: the body is {:,} characters\n'.format(len(
|
|
1000
|
+
body)))
|
|
1001
|
+
return 0
|
|
1002
|
+
|
|
1003
|
+
|
|
1004
|
+
def comment_paths(stem):
|
|
1005
|
+
"""The `<stem>.comment-N.md` files that exist, as (N, path) in order."""
|
|
1006
|
+
|
|
1007
|
+
folder = os.path.dirname(os.path.abspath(stem))
|
|
1008
|
+
found = []
|
|
1009
|
+
|
|
1010
|
+
if not os.path.isdir(folder):
|
|
1011
|
+
return found
|
|
1012
|
+
|
|
1013
|
+
for name in os.listdir(folder):
|
|
1014
|
+
match = re.match(r'^{}\.comment-(\d+)\.md$'.format(re.escape(
|
|
1015
|
+
os.path.basename(stem))), name)
|
|
1016
|
+
|
|
1017
|
+
if match:
|
|
1018
|
+
found.append((int(match.group(1)), os.path.join(folder, name)))
|
|
1019
|
+
|
|
1020
|
+
return sorted(found)
|
|
1021
|
+
|
|
1022
|
+
|
|
1023
|
+
def comment_files(stem, keep):
|
|
1024
|
+
"""The `<stem>.comment-N.md` files that exist for N above `keep`."""
|
|
1025
|
+
|
|
1026
|
+
return [path for number, path in comment_paths(stem) if number > keep]
|
|
1027
|
+
|
|
1028
|
+
|
|
1029
|
+
# verify ----------------------------------------------------------------------
|
|
1030
|
+
|
|
1031
|
+
def parse_bins(values, problems):
|
|
1032
|
+
"""`--bin NAME=PATH` (or a bare PATH, named for its file) as (name, path)."""
|
|
1033
|
+
|
|
1034
|
+
bins = []
|
|
1035
|
+
|
|
1036
|
+
for value in values or []:
|
|
1037
|
+
name, separator, path = value.partition('=')
|
|
1038
|
+
if not separator or '/' in name:
|
|
1039
|
+
name, path = os.path.basename(value), value
|
|
1040
|
+
|
|
1041
|
+
path = os.path.abspath(os.path.expanduser(path))
|
|
1042
|
+
if not re.match(r'^[\w.+-]+$', name):
|
|
1043
|
+
problems.add('--bin {}: {!r} is not a program name'.format(value, name))
|
|
1044
|
+
elif not (os.path.isfile(path) and os.access(path, os.X_OK)):
|
|
1045
|
+
problems.add('--bin {}: {} is not an executable file'.format(value, path))
|
|
1046
|
+
else:
|
|
1047
|
+
bins.append((name, path))
|
|
1048
|
+
|
|
1049
|
+
return bins
|
|
1050
|
+
|
|
1051
|
+
|
|
1052
|
+
def sha256(path):
|
|
1053
|
+
digest = hashlib.sha256()
|
|
1054
|
+
|
|
1055
|
+
with open(path, 'rb') as handle:
|
|
1056
|
+
for chunk in iter(lambda: handle.read(1 << 20), b''):
|
|
1057
|
+
digest.update(chunk)
|
|
1058
|
+
|
|
1059
|
+
return digest.hexdigest()
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
def checksum_of(bins):
|
|
1063
|
+
"""The binary's sha256; for several, the sha256 of their names and sums."""
|
|
1064
|
+
|
|
1065
|
+
if len(bins) == 1:
|
|
1066
|
+
return sha256(bins[0][1])
|
|
1067
|
+
|
|
1068
|
+
return hashlib.sha256('\n'.join('{} {}'.format(name, sha256(path))
|
|
1069
|
+
for name, path in sorted(bins)).encode('utf-8')).hexdigest()
|
|
1070
|
+
|
|
1071
|
+
|
|
1072
|
+
def run_script(path, cwd, env, timeout, prefix, log):
|
|
1073
|
+
"""Run a script with bash in its own process group, its output to `log`,
|
|
1074
|
+
and kill the group when it ends. Returns the exit code (None on a
|
|
1075
|
+
timeout) and the seconds."""
|
|
1076
|
+
|
|
1077
|
+
start = time.monotonic()
|
|
1078
|
+
|
|
1079
|
+
with open(log, 'wb') as out:
|
|
1080
|
+
process = subprocess.Popen(prefix + ['bash', path], cwd=cwd, env=env,
|
|
1081
|
+
stdin=subprocess.DEVNULL, stdout=out, stderr=subprocess.STDOUT,
|
|
1082
|
+
start_new_session=True)
|
|
1083
|
+
try:
|
|
1084
|
+
code = process.wait(timeout=timeout)
|
|
1085
|
+
except subprocess.TimeoutExpired:
|
|
1086
|
+
code = None
|
|
1087
|
+
|
|
1088
|
+
try:
|
|
1089
|
+
os.killpg(process.pid, signal.SIGKILL)
|
|
1090
|
+
except OSError:
|
|
1091
|
+
pass
|
|
1092
|
+
process.wait()
|
|
1093
|
+
|
|
1094
|
+
return code, time.monotonic() - start
|
|
1095
|
+
|
|
1096
|
+
|
|
1097
|
+
def read_capped(path, limit=64 << 20):
|
|
1098
|
+
with open(path, 'rb') as handle:
|
|
1099
|
+
return handle.read(limit).decode('utf-8', 'replace')
|
|
1100
|
+
|
|
1101
|
+
|
|
1102
|
+
def compare(shown, printed, masks):
|
|
1103
|
+
"""How many of the actual block's lines appear in the printed output, of
|
|
1104
|
+
how many, and the missing ones. Blank lines and `...` cuts are skipped."""
|
|
1105
|
+
|
|
1106
|
+
def masked(line):
|
|
1107
|
+
for pattern in masks:
|
|
1108
|
+
line = pattern.sub('…', line)
|
|
1109
|
+
return line.rstrip()
|
|
1110
|
+
|
|
1111
|
+
seen = {masked(line) for line in printed.split('\n')}
|
|
1112
|
+
wanted = [line for line in shown if line.strip() and line.strip()
|
|
1113
|
+
not in ELISION]
|
|
1114
|
+
missing = [line for line in wanted if masked(line) not in seen]
|
|
1115
|
+
|
|
1116
|
+
return len(wanted) - len(missing), len(wanted), missing
|
|
1117
|
+
|
|
1118
|
+
|
|
1119
|
+
def verify_one(args, bug, fields, bins, logs):
|
|
1120
|
+
"""Run one bug in a new temporary directory: bin/ holds the binaries,
|
|
1121
|
+
work/ is the current directory, home/ and tmp/ are HOME and TMPDIR."""
|
|
1122
|
+
|
|
1123
|
+
number, slug = bug['number'], bug['slug']
|
|
1124
|
+
base = tempfile.mkdtemp(prefix='verify-{:02d}-{}-'.format(number, slug),
|
|
1125
|
+
dir=args.workdir)
|
|
1126
|
+
folders = {name: os.path.join(base, name) for name in ('bin', 'work', 'home',
|
|
1127
|
+
'tmp')}
|
|
1128
|
+
for folder in folders.values():
|
|
1129
|
+
os.makedirs(folder)
|
|
1130
|
+
for name, path in bins:
|
|
1131
|
+
os.symlink(path, os.path.join(folders['bin'], name))
|
|
1132
|
+
|
|
1133
|
+
env = dict(os.environ, PATH=folders['bin'] + os.pathsep + (args.path
|
|
1134
|
+
or os.environ.get('PATH', '')), HOME=folders['home'],
|
|
1135
|
+
TMPDIR=folders['tmp'])
|
|
1136
|
+
env.pop('BASH_ENV', None)
|
|
1137
|
+
env.pop('ENV', None)
|
|
1138
|
+
prefix = ['taskset', '-c', args.cpus] if args.cpus else []
|
|
1139
|
+
|
|
1140
|
+
report, code, seconds, status, printed = [], None, 0.0, 'pass', ''
|
|
1141
|
+
|
|
1142
|
+
for name, commands in (('setup', fields.get('setup', '')), ('reproduction',
|
|
1143
|
+
fields['{}.reproduction'.format(number)])):
|
|
1144
|
+
if not commands:
|
|
1145
|
+
continue
|
|
1146
|
+
|
|
1147
|
+
script = os.path.join(base, name + '.sh')
|
|
1148
|
+
with open(script, 'w') as out:
|
|
1149
|
+
out.write(commands + '\n')
|
|
1150
|
+
|
|
1151
|
+
output = os.path.join(base, name + '.out')
|
|
1152
|
+
code, seconds = run_script(script, folders['work'], env, args.timeout,
|
|
1153
|
+
prefix, output)
|
|
1154
|
+
printed = read_capped(output)
|
|
1155
|
+
report.append('== {}: {}, {:.2f} s\n{}'.format(name, 'timed out after '
|
|
1156
|
+
'{:g} s'.format(args.timeout) if code is None else 'exit {}'.format(
|
|
1157
|
+
code), seconds, printed))
|
|
1158
|
+
|
|
1159
|
+
if code is None or (name == 'setup' and code != 0):
|
|
1160
|
+
status = 'timeout' if name == 'reproduction' else 'setup-failed'
|
|
1161
|
+
break
|
|
1162
|
+
|
|
1163
|
+
note, matched = '-', '-'
|
|
1164
|
+
if status == 'pass':
|
|
1165
|
+
masks = [re.compile(line) for line in fields.get('{}.varies'.format(
|
|
1166
|
+
number), '').split('\n') if line]
|
|
1167
|
+
found, total, missing = compare(actual_block(fields['{}.output'.format(
|
|
1168
|
+
number)]), printed, masks)
|
|
1169
|
+
matched = '{}/{}'.format(found, total)
|
|
1170
|
+
report.append('== matched {} of {} lines of the actual output{}'.format(
|
|
1171
|
+
found, total, ''.join('\nmissing: ' + line for line in missing)))
|
|
1172
|
+
if missing:
|
|
1173
|
+
status, note = 'fail', 'missing: ' + missing[0]
|
|
1174
|
+
else:
|
|
1175
|
+
note = report[-1].split('\n', 1)[0].lstrip('= ')
|
|
1176
|
+
|
|
1177
|
+
log = os.path.join(logs, '{:02d}-{}.log'.format(number, slug))
|
|
1178
|
+
with open(log, 'w', encoding='utf-8') as out:
|
|
1179
|
+
out.write('# bug {} ({}), {}, in {}\n'.format(number, slug, ', '.join(
|
|
1180
|
+
'{}={}'.format(name, path) for name, path in bins), base))
|
|
1181
|
+
out.write('\n'.join(report) + '\n')
|
|
1182
|
+
|
|
1183
|
+
kept = status != 'pass' or args.keep
|
|
1184
|
+
if not kept:
|
|
1185
|
+
shutil.rmtree(base, ignore_errors=True)
|
|
1186
|
+
|
|
1187
|
+
return {
|
|
1188
|
+
'number': str(number), 'slug': slug, 'status': status,
|
|
1189
|
+
'exit': '-' if code is None else str(code),
|
|
1190
|
+
'seconds': '{:.2f}'.format(seconds), 'matched': matched,
|
|
1191
|
+
'log': os.path.relpath(log, args.dir), 'note': tsv_cell(note),
|
|
1192
|
+
}, base if kept else None
|
|
1193
|
+
|
|
1194
|
+
|
|
1195
|
+
def verify_command(args):
|
|
1196
|
+
problems = Problems()
|
|
1197
|
+
bugs = read_bugs(os.path.join(args.dir, 'bugs.tsv'), problems)
|
|
1198
|
+
fields = read_fields(args.prose or os.path.join(args.dir, 'prose.md'), problems)
|
|
1199
|
+
bins = parse_bins(args.bin, problems)
|
|
1200
|
+
path = os.path.join(args.dir, 'verify.tsv')
|
|
1201
|
+
rows = read_verify(path, problems)
|
|
1202
|
+
by_number = {bug['number']: bug for bug in bugs}
|
|
1203
|
+
|
|
1204
|
+
if not args.bin:
|
|
1205
|
+
problems.add('verify needs --bin NAME=PATH: the binary the report is '
|
|
1206
|
+
'about, put first on the PATH as NAME')
|
|
1207
|
+
|
|
1208
|
+
checksum = checksum_of(bins) if bins else None
|
|
1209
|
+
|
|
1210
|
+
if args.stale and (args.bug or args.manual is not None):
|
|
1211
|
+
problems.add('--stale runs the bugs that need it; it does not go with '
|
|
1212
|
+
'--bug or --manual')
|
|
1213
|
+
|
|
1214
|
+
if args.manual is not None:
|
|
1215
|
+
selected = [args.manual]
|
|
1216
|
+
if not (args.reason or '').strip():
|
|
1217
|
+
problems.add('--manual needs --reason: why the reproduction cannot run '
|
|
1218
|
+
'here, as a clause the body shows')
|
|
1219
|
+
if not args.log or not os.path.isfile(args.log):
|
|
1220
|
+
problems.add('--manual needs --log: an existing file with the output '
|
|
1221
|
+
'of the run that shows the bug')
|
|
1222
|
+
elif args.stale:
|
|
1223
|
+
why = {bug['number']: stale_reason(rows.get(bug['number']), fields,
|
|
1224
|
+
bug['number'], checksum, args.commit) for bug in bugs}
|
|
1225
|
+
selected = [number for number, reason in why.items() if reason and
|
|
1226
|
+
rows.get(number, {}).get('status') != 'manual']
|
|
1227
|
+
for number, reason in why.items():
|
|
1228
|
+
if reason and number not in selected:
|
|
1229
|
+
problems.add('bug {} is marked manual and {}; mark it manual again '
|
|
1230
|
+
'(--manual {} --reason … --log …) or run it'.format(number,
|
|
1231
|
+
reason, number))
|
|
1232
|
+
else:
|
|
1233
|
+
selected = args.bug or [bug['number'] for bug in bugs if rows.get(
|
|
1234
|
+
bug['number'], {}).get('status') != 'manual']
|
|
1235
|
+
if args.reason or args.log:
|
|
1236
|
+
problems.add('--reason and --log go with --manual')
|
|
1237
|
+
|
|
1238
|
+
for number in selected:
|
|
1239
|
+
if number not in by_number:
|
|
1240
|
+
problems.add('bug {}: not in bugs.tsv'.format(number))
|
|
1241
|
+
continue
|
|
1242
|
+
for key in ('reproduction', 'output', 'varies'):
|
|
1243
|
+
name = '{}.{}'.format(number, key)
|
|
1244
|
+
if fields.get(name):
|
|
1245
|
+
check_field(name, BUG_FIELDS[key][1], fields[name], problems)
|
|
1246
|
+
elif BUG_FIELDS[key][0]:
|
|
1247
|
+
problems.add('prose: "=== {}" is missing or empty'.format(name))
|
|
1248
|
+
|
|
1249
|
+
if fields.get('setup'):
|
|
1250
|
+
check_field('setup', 'commands', fields['setup'], problems)
|
|
1251
|
+
if args.workdir and not os.path.isdir(args.workdir):
|
|
1252
|
+
problems.add('--workdir {} is not a directory'.format(args.workdir))
|
|
1253
|
+
if args.cpus and not shutil.which('taskset'):
|
|
1254
|
+
problems.add('--cpus needs taskset on the PATH')
|
|
1255
|
+
|
|
1256
|
+
if problems:
|
|
1257
|
+
sys.stderr.write('issue_body: verify refused, nothing run:\n'
|
|
1258
|
+
+ ''.join(' ' + problem + '\n' for problem in problems))
|
|
1259
|
+
return 1
|
|
1260
|
+
|
|
1261
|
+
if args.stale:
|
|
1262
|
+
print('{} of {} bugs need a run{}'.format(len(selected), len(bugs),
|
|
1263
|
+
''.join('\n bug {} {}: {}'.format(number, by_number[number]['slug'],
|
|
1264
|
+
why[number]) for number in selected)))
|
|
1265
|
+
if not selected:
|
|
1266
|
+
return 0
|
|
1267
|
+
|
|
1268
|
+
common = {'checksum': checksum, 'commit': tsv_cell(args.commit
|
|
1269
|
+
or '-'), 'date': datetime.datetime.now(datetime.timezone.utc).strftime(
|
|
1270
|
+
'%Y-%m-%dT%H:%MZ')}
|
|
1271
|
+
|
|
1272
|
+
if args.manual is not None:
|
|
1273
|
+
number, log = args.manual, os.path.abspath(args.log)
|
|
1274
|
+
inside = os.path.commonpath([log, os.path.abspath(args.dir)]) \
|
|
1275
|
+
== os.path.abspath(args.dir)
|
|
1276
|
+
rows[number] = dict(common, number=str(number),
|
|
1277
|
+
slug=by_number[number]['slug'], status='manual', exit='-', seconds='-',
|
|
1278
|
+
matched='-', text=text_hash(fields, number), log=os.path.relpath(log,
|
|
1279
|
+
args.dir) if inside else log, note=tsv_cell(args.reason.rstrip('.')))
|
|
1280
|
+
write_verify(path, rows)
|
|
1281
|
+
print('bug {} {}: marked manual ({})'.format(number,
|
|
1282
|
+
by_number[number]['slug'], rows[number]['note']))
|
|
1283
|
+
return 0
|
|
1284
|
+
|
|
1285
|
+
logs = os.path.join(args.dir, 'verify-logs')
|
|
1286
|
+
os.makedirs(logs, exist_ok=True)
|
|
1287
|
+
failed = 0
|
|
1288
|
+
|
|
1289
|
+
for number in selected:
|
|
1290
|
+
row, kept = verify_one(args, by_number[number], fields, bins, logs)
|
|
1291
|
+
row.update(common, text=text_hash(fields, number))
|
|
1292
|
+
rows[number] = row
|
|
1293
|
+
write_verify(path, rows)
|
|
1294
|
+
failed += row['status'] != 'pass'
|
|
1295
|
+
print('bug {} {}: {}, exit {}, {} s, {} lines matched{}{}'.format(number,
|
|
1296
|
+
row['slug'], row['status'], row['exit'], row['seconds'], row['matched'],
|
|
1297
|
+
'' if row['note'] == '-' else '; ' + row['note'],
|
|
1298
|
+
'; kept ' + kept if kept else ''))
|
|
1299
|
+
sys.stdout.flush()
|
|
1300
|
+
|
|
1301
|
+
return 1 if failed else 0
|
|
1302
|
+
|
|
1303
|
+
|
|
1304
|
+
# template --------------------------------------------------------------------
|
|
1305
|
+
|
|
1306
|
+
def template_command(args):
|
|
1307
|
+
problems = Problems()
|
|
1308
|
+
path = os.path.join(args.dir, 'bugs.tsv')
|
|
1309
|
+
bugs = read_bugs(path, problems) if os.path.exists(path) else []
|
|
1310
|
+
|
|
1311
|
+
if problems:
|
|
1312
|
+
sys.stderr.write('issue_body: bugs.tsv has problems render will refuse:\n'
|
|
1313
|
+
+ ''.join(' ' + problem + '\n' for problem in problems))
|
|
1314
|
+
if not bugs:
|
|
1315
|
+
sys.stderr.write('issue_body: no bugs.tsv rows, so the skeleton has one '
|
|
1316
|
+
'bug, 1\n')
|
|
1317
|
+
bugs = [{'number': 1, 'title': 'the first bug'}]
|
|
1318
|
+
|
|
1319
|
+
lines = []
|
|
1320
|
+
for name, (_, _, what) in FIELDS.items():
|
|
1321
|
+
lines += ['=== ' + name, '<<FILL: {}>>'.format(what), '']
|
|
1322
|
+
|
|
1323
|
+
for bug in bugs:
|
|
1324
|
+
for key, (_, _, what) in BUG_FIELDS.items():
|
|
1325
|
+
lines += ['=== {}.{}'.format(bug['number'], key), '<<FILL: bug {} ({}): '
|
|
1326
|
+
'{}>>'.format(bug['number'], bug['title'], what), '']
|
|
1327
|
+
|
|
1328
|
+
sys.stdout.write('\n'.join(lines))
|
|
1329
|
+
return 0
|
|
1330
|
+
|
|
1331
|
+
|
|
1332
|
+
# file and link ---------------------------------------------------------------
|
|
1333
|
+
|
|
1334
|
+
FILED = publish.RECORDS['bugs']
|
|
1335
|
+
GITHUB_LIMIT = 65536
|
|
1336
|
+
ISSUE_URL = re.compile(r'https://\S+/issues/(\d+)')
|
|
1337
|
+
|
|
1338
|
+
|
|
1339
|
+
def read_filed(directory, problems):
|
|
1340
|
+
"""What `file --post` recorded in DIR/filed.json (publish.new_record, with
|
|
1341
|
+
`comments`, the URL of each comment posted so far, and `comments_left`,
|
|
1342
|
+
the number still to post), or None before the issue exists. A record that
|
|
1343
|
+
cannot be read is added to `problems`: it stands for an issue already
|
|
1344
|
+
filed, so nothing may file another until it is fixed."""
|
|
1345
|
+
|
|
1346
|
+
path = os.path.join(directory, FILED)
|
|
1347
|
+
|
|
1348
|
+
if not os.path.exists(path):
|
|
1349
|
+
return None
|
|
1350
|
+
|
|
1351
|
+
try:
|
|
1352
|
+
with open(path, encoding='utf-8') as handle:
|
|
1353
|
+
record = json.load(handle)
|
|
1354
|
+
|
|
1355
|
+
if not isinstance(record, dict) or not record.get('url') \
|
|
1356
|
+
or not isinstance(record.get('number'), int):
|
|
1357
|
+
raise ValueError('it names no issue URL and number')
|
|
1358
|
+
except (OSError, ValueError) as error:
|
|
1359
|
+
problems.add('{}: cannot read it ({}); it records an issue already '
|
|
1360
|
+
'filed, so fix it or remove it by hand first'.format(path, error))
|
|
1361
|
+
return None
|
|
1362
|
+
|
|
1363
|
+
record.setdefault('comments', [])
|
|
1364
|
+
return record
|
|
1365
|
+
|
|
1366
|
+
|
|
1367
|
+
def filing_problems(args, body_path, title, body, comments):
|
|
1368
|
+
"""Everything that should stop the issue being filed: the files are
|
|
1369
|
+
missing or not what the inputs render to, the first paragraph or the
|
|
1370
|
+
title is wrong, a stand-in is left, or the text is
|
|
1371
|
+
over GitHub's limit."""
|
|
1372
|
+
|
|
1373
|
+
problems = Problems()
|
|
1374
|
+
|
|
1375
|
+
for problem in attribution.problems('issue', title, body):
|
|
1376
|
+
problems.add(problem)
|
|
1377
|
+
|
|
1378
|
+
for number, text in comments:
|
|
1379
|
+
for problem in attribution.placeholder_problems(text):
|
|
1380
|
+
problems.add('comment {}: {}'.format(number, problem))
|
|
1381
|
+
|
|
1382
|
+
for text, name in [(body, 'the body')] + [(text, 'comment {}'.format(number))
|
|
1383
|
+
for number, text in comments]:
|
|
1384
|
+
if len(text) > GITHUB_LIMIT:
|
|
1385
|
+
problems.add('{} is {:,} characters, over GitHub\'s {:,}'.format(name,
|
|
1386
|
+
len(text), GITHUB_LIMIT))
|
|
1387
|
+
|
|
1388
|
+
numbers = [number for number, _ in comments]
|
|
1389
|
+
|
|
1390
|
+
if numbers != list(range(1, len(numbers) + 1)):
|
|
1391
|
+
problems.add('the comment files are numbered {}; they must run 1 to '
|
|
1392
|
+
'N'.format(', '.join(map(str, numbers))))
|
|
1393
|
+
|
|
1394
|
+
issues = Problems()
|
|
1395
|
+
bugs = read_bugs(os.path.join(args.dir, 'bugs.tsv'), issues)
|
|
1396
|
+
fields = read_fields(args.prose or os.path.join(args.dir, 'prose.md'), issues)
|
|
1397
|
+
check_prose(bugs, fields, issues)
|
|
1398
|
+
rows = read_verify(os.path.join(args.dir, 'verify.tsv'), issues)
|
|
1399
|
+
check_verify(args.dir, bugs, fields, rows, None, issues)
|
|
1400
|
+
|
|
1401
|
+
for problem in issues:
|
|
1402
|
+
problems.add('inputs: ' + problem)
|
|
1403
|
+
|
|
1404
|
+
if not issues:
|
|
1405
|
+
again, extra = render(bugs, fields, rows, args.limit)
|
|
1406
|
+
|
|
1407
|
+
if again != body or [text for _, text in extra] != [text for _, text
|
|
1408
|
+
in comments]:
|
|
1409
|
+
problems.add('{} and its comments are not what the inputs render to '
|
|
1410
|
+
'now (an input changed since the last render, or another --limit '
|
|
1411
|
+
'was used); run render again'.format(body_path))
|
|
1412
|
+
|
|
1413
|
+
return problems
|
|
1414
|
+
|
|
1415
|
+
|
|
1416
|
+
run_gh = publish.run_gh
|
|
1417
|
+
|
|
1418
|
+
|
|
1419
|
+
def file_command(args):
|
|
1420
|
+
"""Show what would be filed; with --post, file it: create the issue, then
|
|
1421
|
+
post each comment in order, recording each step in filed.json. Never
|
|
1422
|
+
posts without --post, never files twice, and a rerun posts only the
|
|
1423
|
+
comments a failure left."""
|
|
1424
|
+
|
|
1425
|
+
body_path = args.body or os.path.join(args.dir, 'body.md')
|
|
1426
|
+
stem = os.path.splitext(body_path)[0]
|
|
1427
|
+
record_path = os.path.join(args.dir, FILED)
|
|
1428
|
+
problems = Problems()
|
|
1429
|
+
body = read_text(body_path, problems, 'body') or ''
|
|
1430
|
+
title = (read_text(stem + '.title', problems, 'title') or '').strip()
|
|
1431
|
+
comments = [(number, read_text(path, problems, 'comment') or '')
|
|
1432
|
+
for number, path in comment_paths(stem)]
|
|
1433
|
+
|
|
1434
|
+
if not problems:
|
|
1435
|
+
problems = filing_problems(args, body_path, title, body, comments)
|
|
1436
|
+
|
|
1437
|
+
filed = read_filed(args.dir, problems)
|
|
1438
|
+
posted = len(filed['comments']) if filed else 0
|
|
1439
|
+
done = bool(filed) and posted >= len(comments) and not filed.get(
|
|
1440
|
+
'comments_left')
|
|
1441
|
+
|
|
1442
|
+
if filed and filed.get('repo') != args.repo:
|
|
1443
|
+
problems.add('{} says this was filed on {}, not {}'.format(FILED,
|
|
1444
|
+
filed.get('repo'), args.repo))
|
|
1445
|
+
|
|
1446
|
+
if filed and not done and filed.get('digest') and filed['digest'] \
|
|
1447
|
+
!= publish.digest(title, body):
|
|
1448
|
+
problems.add('{} was created with another title or body than {} holds '
|
|
1449
|
+
'now, so the comments left would not match it; render the inputs it '
|
|
1450
|
+
'was created from again, or post the rest by hand'.format(
|
|
1451
|
+
filed['url'], body_path))
|
|
1452
|
+
|
|
1453
|
+
if not re.match(r'^[\w.-]+/[\w.-]+$', args.repo):
|
|
1454
|
+
problems.add('--repo must be OWNER/REPO')
|
|
1455
|
+
|
|
1456
|
+
if args.post and not shutil.which('gh'):
|
|
1457
|
+
problems.add('--post needs gh on the PATH')
|
|
1458
|
+
|
|
1459
|
+
if problems:
|
|
1460
|
+
return refuse(problems, 'nothing posted')
|
|
1461
|
+
|
|
1462
|
+
if done:
|
|
1463
|
+
print('already filed: {}\nnothing to post'.format(filed['url']))
|
|
1464
|
+
return 0
|
|
1465
|
+
|
|
1466
|
+
print('repository: {}'.format(args.repo))
|
|
1467
|
+
print('title: {}'.format(title))
|
|
1468
|
+
print('body: {} ({:,} characters)'.format(body_path, len(body)))
|
|
1469
|
+
|
|
1470
|
+
if filed:
|
|
1471
|
+
print('already created: {}; {} of {} comments posted'.format(filed['url'],
|
|
1472
|
+
posted, len(comments)))
|
|
1473
|
+
|
|
1474
|
+
for number, text in comments:
|
|
1475
|
+
bugs_in = re.findall(r'(?m)^### (\d+)\. ', text)
|
|
1476
|
+
print('comment {}: {}.comment-{}.md, bug{} {} ({:,} characters){}'.format(
|
|
1477
|
+
number, stem, number, attribution.plural(len(bugs_in)), ', '.join(
|
|
1478
|
+
bugs_in), len(text), ' (posted)' if number <= posted else ''))
|
|
1479
|
+
|
|
1480
|
+
if not args.post:
|
|
1481
|
+
left = len(comments) - posted
|
|
1482
|
+
print('\n'.join(publish.post_needs(args.repo, 'nothing is pushed; this '
|
|
1483
|
+
+ ('posts the {} comment{} left on {}'.format(left, attribution.plural(
|
|
1484
|
+
left), filed['url']) if filed else 'files an issue on {} and posts {} '
|
|
1485
|
+
'comment{}'.format(args.repo, left, attribution.plural(left))))))
|
|
1486
|
+
print('\npreview only: nothing was posted. Run again with --post, after '
|
|
1487
|
+
'the repository, title and comments have been approved')
|
|
1488
|
+
return 0
|
|
1489
|
+
|
|
1490
|
+
problem = publish.account_problem(args.repo, args.other_owner)
|
|
1491
|
+
|
|
1492
|
+
if problem:
|
|
1493
|
+
return refuse([problem], 'nothing posted')
|
|
1494
|
+
|
|
1495
|
+
if not filed:
|
|
1496
|
+
code, out, err = run_gh(['issue', 'create', '--repo', args.repo, '--title',
|
|
1497
|
+
title, '--body-file', body_path])
|
|
1498
|
+
match = ISSUE_URL.search(out)
|
|
1499
|
+
|
|
1500
|
+
if code != 0 or not match:
|
|
1501
|
+
sys.stderr.write('issue_body: gh issue create failed ({}); nothing '
|
|
1502
|
+
'recorded{}:\n{}\n{}\n'.format(code, '' if code else ', but the '
|
|
1503
|
+
'issue may exist: look at {}\'s issues before running this again'
|
|
1504
|
+
.format(args.repo), out, err))
|
|
1505
|
+
return 1
|
|
1506
|
+
|
|
1507
|
+
filed = publish.new_record(args.repo, match.group(0), None, title, body,
|
|
1508
|
+
comments=[], comments_left=len(comments))
|
|
1509
|
+
publish.write_record(record_path, filed)
|
|
1510
|
+
print('created {}'.format(filed['url']))
|
|
1511
|
+
|
|
1512
|
+
for number, _ in comments[len(filed['comments']):]:
|
|
1513
|
+
path = '{}.comment-{}.md'.format(stem, number)
|
|
1514
|
+
code, out, err = run_gh(['issue', 'comment', str(filed['number']), '--repo',
|
|
1515
|
+
args.repo, '--body-file', path])
|
|
1516
|
+
|
|
1517
|
+
if code != 0:
|
|
1518
|
+
sys.stderr.write('issue_body: gh issue comment failed on comment {} '
|
|
1519
|
+
'({}); {} is recorded in {} with {} comment{} left, so running '
|
|
1520
|
+
'this again posts the rest:\n{}\n{}\n'.format(number, code,
|
|
1521
|
+
filed['url'], FILED, len(comments) - len(filed['comments']),
|
|
1522
|
+
attribution.plural(len(comments) - len(filed['comments'])), out,
|
|
1523
|
+
err))
|
|
1524
|
+
return 1
|
|
1525
|
+
|
|
1526
|
+
filed['comments'].append(out.splitlines()[-1] if out else '-')
|
|
1527
|
+
filed['comments_left'] = len(comments) - len(filed['comments'])
|
|
1528
|
+
publish.write_record(record_path, filed)
|
|
1529
|
+
print('posted comment {}: {}'.format(number, filed['comments'][-1]))
|
|
1530
|
+
|
|
1531
|
+
if filed.get('comments_left', 0) != 0:
|
|
1532
|
+
filed['comments_left'] = 0
|
|
1533
|
+
publish.write_record(record_path, filed)
|
|
1534
|
+
|
|
1535
|
+
print('filed {} with {} comment{}'.format(filed['url'], len(comments),
|
|
1536
|
+
attribution.plural(len(comments))))
|
|
1537
|
+
return 0
|
|
1538
|
+
|
|
1539
|
+
|
|
1540
|
+
def link_command(args):
|
|
1541
|
+
"""Fill a stand-in into the given files: by default the bug report's
|
|
1542
|
+
number, from filed.json."""
|
|
1543
|
+
|
|
1544
|
+
problems = Problems()
|
|
1545
|
+
filed = read_filed(args.dir, problems)
|
|
1546
|
+
placeholder = args.placeholder or attribution.PLACEHOLDERS[0]
|
|
1547
|
+
|
|
1548
|
+
if placeholder not in attribution.PLACEHOLDERS:
|
|
1549
|
+
problems.add('--placeholder is one of {}'.format(', '.join(
|
|
1550
|
+
attribution.PLACEHOLDERS)))
|
|
1551
|
+
|
|
1552
|
+
if args.value:
|
|
1553
|
+
value = args.value
|
|
1554
|
+
elif filed and placeholder == attribution.PLACEHOLDERS[0]:
|
|
1555
|
+
value = '#{}'.format(filed['number'])
|
|
1556
|
+
else:
|
|
1557
|
+
value = None
|
|
1558
|
+
problems.add('give --value: {} is the bug report\'s number only when '
|
|
1559
|
+
'{} says it was filed'.format(placeholder, FILED))
|
|
1560
|
+
|
|
1561
|
+
if value and not re.match(r'^#\d+$|^https://\S+$', value):
|
|
1562
|
+
problems.add('--value must be #N or a URL')
|
|
1563
|
+
|
|
1564
|
+
for path in args.files:
|
|
1565
|
+
if not os.path.exists(path):
|
|
1566
|
+
problems.add('{}: no such file'.format(path))
|
|
1567
|
+
|
|
1568
|
+
if problems:
|
|
1569
|
+
return refuse(problems)
|
|
1570
|
+
|
|
1571
|
+
for path, count in publish.link_files(args.files, placeholder, value).items():
|
|
1572
|
+
print('{}: {} place{} filled with {}'.format(path, count,
|
|
1573
|
+
attribution.plural(count), value))
|
|
1574
|
+
|
|
1575
|
+
return 0
|
|
1576
|
+
|
|
1577
|
+
|
|
1578
|
+
# dupes -----------------------------------------------------------------------
|
|
1579
|
+
|
|
1580
|
+
DUPES_COLUMNS = ('bug', 'slug', 'issue', 'state', 'score', 'title', 'url',
|
|
1581
|
+
'matched')
|
|
1582
|
+
STOPWORDS = frozenset('''about after also because before being between both can
|
|
1583
|
+
could does each else every file files from have into just more most much must
|
|
1584
|
+
never only other output outputs over same should some such than that their
|
|
1585
|
+
then there these they this those through tool under until used uses using
|
|
1586
|
+
want what when where which while with without would write writes written
|
|
1587
|
+
wrong value values input inputs option options default reads read the and for
|
|
1588
|
+
not are but you your was were will has had its one two any all'''.split())
|
|
1589
|
+
|
|
1590
|
+
|
|
1591
|
+
def distinctive(bug, fields):
|
|
1592
|
+
"""The words a bug is told apart by: its backticked spans (options, names
|
|
1593
|
+
of functions), and its other words of four letters or more, from the
|
|
1594
|
+
title and the first paragraph."""
|
|
1595
|
+
|
|
1596
|
+
number = bug['number']
|
|
1597
|
+
text = ' '.join([bug['title']] + [fields.get('{}.{}'.format(number, key), '')
|
|
1598
|
+
for key in ('what', 'cause')])
|
|
1599
|
+
spans = {span.strip().lower() for span in re.findall(r'`([^`]+)`', text)
|
|
1600
|
+
if len(span.strip()) >= 3}
|
|
1601
|
+
plain = re.sub(r'`[^`]*`', ' ', text).lower()
|
|
1602
|
+
words = {word for word in re.findall(r'[a-z][a-z0-9_.-]{3,}', plain)
|
|
1603
|
+
if word not in STOPWORDS}
|
|
1604
|
+
title_words = {word for word in re.findall(r'[a-z][a-z0-9_.-]{3,}', re.sub(
|
|
1605
|
+
r'`[^`]*`', ' ', bug['title']).lower()) if word not in STOPWORDS}
|
|
1606
|
+
|
|
1607
|
+
return spans, words, title_words
|
|
1608
|
+
|
|
1609
|
+
|
|
1610
|
+
def candidates(bug, fields, issues, skip, top, floor):
|
|
1611
|
+
"""The `top` open or closed issues most like a bug, best first, as
|
|
1612
|
+
(score, issue, the words shared): 3 for each backticked span the issue
|
|
1613
|
+
holds, 2 for each word of the bug's title in the issue's title, 1 for each
|
|
1614
|
+
other word in its text up to five."""
|
|
1615
|
+
|
|
1616
|
+
spans, words, title_words = distinctive(bug, fields)
|
|
1617
|
+
found = []
|
|
1618
|
+
|
|
1619
|
+
for issue in issues:
|
|
1620
|
+
if issue['number'] in skip:
|
|
1621
|
+
continue
|
|
1622
|
+
|
|
1623
|
+
title = issue['title'].lower()
|
|
1624
|
+
text = title + ' ' + (issue.get('body') or '').lower()
|
|
1625
|
+
held = sorted(span for span in spans if span in text)
|
|
1626
|
+
in_title = sorted(word for word in title_words if word in title)
|
|
1627
|
+
in_text = sorted(word for word in words - set(in_title) if word in text)
|
|
1628
|
+
score = 3 * len(held) + 2 * len(in_title) + min(len(in_text), 5)
|
|
1629
|
+
|
|
1630
|
+
if score >= floor and (held or len(in_title) >= 2):
|
|
1631
|
+
found.append((score, issue, held + in_title + in_text[:5 - len(
|
|
1632
|
+
in_title)]))
|
|
1633
|
+
|
|
1634
|
+
found.sort(key=lambda item: (-item[0], item[1]['number']))
|
|
1635
|
+
return found[:top]
|
|
1636
|
+
|
|
1637
|
+
|
|
1638
|
+
def dupes_command(args):
|
|
1639
|
+
"""Which existing issues might already report each bug: one `gh issue list`
|
|
1640
|
+
(or --issues FILE, its JSON), matched here by shared words. A list to read,
|
|
1641
|
+
not a verdict; `related` in bugs.tsv is filled by hand from it."""
|
|
1642
|
+
|
|
1643
|
+
problems = Problems()
|
|
1644
|
+
bugs = read_bugs(os.path.join(args.dir, 'bugs.tsv'), problems)
|
|
1645
|
+
fields = read_fields(args.prose or os.path.join(args.dir, 'prose.md'), problems)
|
|
1646
|
+
|
|
1647
|
+
if args.issues:
|
|
1648
|
+
text = read_text(args.issues, problems, '--issues')
|
|
1649
|
+
elif not shutil.which('gh'):
|
|
1650
|
+
text = None
|
|
1651
|
+
problems.add('dupes needs gh on the PATH, or --issues FILE (the JSON of '
|
|
1652
|
+
'`gh issue list --state all --json number,title,state,url,body`)')
|
|
1653
|
+
else:
|
|
1654
|
+
text = None
|
|
1655
|
+
|
|
1656
|
+
if not args.issues and not args.repo:
|
|
1657
|
+
problems.add('give --repo OWNER/REPO, or --issues FILE')
|
|
1658
|
+
|
|
1659
|
+
filed = read_filed(args.dir, problems)
|
|
1660
|
+
|
|
1661
|
+
if problems:
|
|
1662
|
+
return refuse(problems)
|
|
1663
|
+
|
|
1664
|
+
if text is None:
|
|
1665
|
+
code, text, err = run_gh(['issue', 'list', '--repo', args.repo, '--state',
|
|
1666
|
+
'all', '--limit', str(args.max_issues), '--json',
|
|
1667
|
+
'number,title,state,url,body'])
|
|
1668
|
+
|
|
1669
|
+
if code != 0:
|
|
1670
|
+
sys.stderr.write('issue_body: gh issue list failed ({}):\n{}\n'.format(
|
|
1671
|
+
code, err))
|
|
1672
|
+
return 1
|
|
1673
|
+
|
|
1674
|
+
try:
|
|
1675
|
+
issues = json.loads(text)
|
|
1676
|
+
issues = [dict(issue, number=int(issue['number']), title=issue['title'],
|
|
1677
|
+
state=str(issue.get('state', '')).lower(), url=issue.get('url', '-'))
|
|
1678
|
+
for issue in issues]
|
|
1679
|
+
except (ValueError, KeyError, TypeError) as error:
|
|
1680
|
+
return refuse(['the issue list is not the JSON `gh issue list --json '
|
|
1681
|
+
'number,title,state,url,body` prints ({!r})'.format(error)])
|
|
1682
|
+
|
|
1683
|
+
skip = {filed['number']} if filed else set()
|
|
1684
|
+
lines = ['\t'.join(DUPES_COLUMNS)]
|
|
1685
|
+
|
|
1686
|
+
print('{} issues read'.format(len(issues)))
|
|
1687
|
+
for bug in bugs:
|
|
1688
|
+
found = candidates(bug, fields, issues, skip, args.top, args.min_score)
|
|
1689
|
+
print('bug {} {}:{}'.format(bug['number'], bug['slug'], '' if found
|
|
1690
|
+
else ' none'))
|
|
1691
|
+
|
|
1692
|
+
for score, issue, shared in found:
|
|
1693
|
+
print(' #{} ({}, score {}) {}'.format(issue['number'], issue['state'],
|
|
1694
|
+
score, issue['title']))
|
|
1695
|
+
lines.append('\t'.join([str(bug['number']), bug['slug'], str(issue[
|
|
1696
|
+
'number']), issue['state'], str(score), tsv_cell(issue['title']),
|
|
1697
|
+
issue['url'], tsv_cell(', '.join(shared))]))
|
|
1698
|
+
|
|
1699
|
+
write(os.path.join(args.dir, 'dupes.tsv'), '\n'.join(lines) + '\n')
|
|
1700
|
+
print('wrote {}; read each candidate, then fill `related` in bugs.tsv for '
|
|
1701
|
+
'the ones that are the same bug or close to it'.format(os.path.join(
|
|
1702
|
+
args.dir, 'dupes.tsv')))
|
|
1703
|
+
return 0
|
|
1704
|
+
|
|
1705
|
+
|
|
1706
|
+
# status ----------------------------------------------------------------------
|
|
1707
|
+
|
|
1708
|
+
def status_command(args):
|
|
1709
|
+
"""Where the inputs stand: one line per bug, the counts, the size of the
|
|
1710
|
+
body and its comments, and every problem `render` would refuse for."""
|
|
1711
|
+
|
|
1712
|
+
problems = Problems()
|
|
1713
|
+
bugs = read_bugs(os.path.join(args.dir, 'bugs.tsv'), problems)
|
|
1714
|
+
fields = read_fields(args.prose or os.path.join(args.dir, 'prose.md'), problems)
|
|
1715
|
+
check_prose(bugs, fields, problems)
|
|
1716
|
+
rows = read_verify(os.path.join(args.dir, 'verify.tsv'), problems)
|
|
1717
|
+
bins = parse_bins(args.bin, problems)
|
|
1718
|
+
checksum = checksum_of(bins) if bins else None
|
|
1719
|
+
check_verify(args.dir, bugs, fields, rows, checksum, problems)
|
|
1720
|
+
|
|
1721
|
+
lines = [('#', 'severity', 'category', 'slug', 'prose', 'verify')]
|
|
1722
|
+
|
|
1723
|
+
for bug in bugs:
|
|
1724
|
+
number = bug['number']
|
|
1725
|
+
names = {key: '{}.{}'.format(number, key) for key in BUG_FIELDS}
|
|
1726
|
+
missing = [key for key, (required, _, _) in BUG_FIELDS.items()
|
|
1727
|
+
if required and not fields.get(names[key])]
|
|
1728
|
+
filling = [key for key in BUG_FIELDS if '<<FILL' in fields.get(names[
|
|
1729
|
+
key], '')]
|
|
1730
|
+
row = rows.get(number)
|
|
1731
|
+
reason = stale_reason(row, fields, number, checksum, None)
|
|
1732
|
+
|
|
1733
|
+
lines.append((str(number), bug['severity'], bug['category'], bug['slug'],
|
|
1734
|
+
'missing ' + ','.join(missing) if missing else 'fill ' + ','.join(
|
|
1735
|
+
filling) if filling else 'ok', reason or row['status']))
|
|
1736
|
+
|
|
1737
|
+
widths = [max(len(line[i]) for line in lines) for i in range(6)]
|
|
1738
|
+
for line in lines:
|
|
1739
|
+
print(' '.join(cell.ljust(widths[i]) for i, cell in enumerate(line)).rstrip())
|
|
1740
|
+
|
|
1741
|
+
print('')
|
|
1742
|
+
for title, key, order in (('severity', 'severity', [k for k, _ in SEVERITIES]),
|
|
1743
|
+
('category', 'category', [k for k, _ in CATEGORIES])):
|
|
1744
|
+
print('{}: {}'.format(title, ', '.join('{} {}'.format(sum(
|
|
1745
|
+
bug[key] == value for bug in bugs), value) for value in order)))
|
|
1746
|
+
|
|
1747
|
+
sound = not any(problem.startswith(('bugs.tsv', 'prose')) for problem in
|
|
1748
|
+
problems)
|
|
1749
|
+
|
|
1750
|
+
if sound and bugs:
|
|
1751
|
+
body, comments = render(bugs, fields, rows, args.limit)
|
|
1752
|
+
print('body: {:,} of {:,} characters; {}'.format(len(body), args.limit,
|
|
1753
|
+
'no comments' if not comments else '{} comment{}: {}'.format(len(
|
|
1754
|
+
comments), '' if len(comments) == 1 else 's', '; '.join(
|
|
1755
|
+
'{} ({:,} characters)'.format(bugs_named(numbers), len(text))
|
|
1756
|
+
for numbers, text in comments))))
|
|
1757
|
+
|
|
1758
|
+
filed = read_filed(args.dir, problems)
|
|
1759
|
+
|
|
1760
|
+
if filed:
|
|
1761
|
+
posted = len(filed['comments'])
|
|
1762
|
+
print('filed: {} ({} of {} comment{} posted)'.format(filed['url'],
|
|
1763
|
+
posted, posted + int(filed.get('comments_left') or 0),
|
|
1764
|
+
attribution.plural(posted + int(filed.get('comments_left') or 0))))
|
|
1765
|
+
|
|
1766
|
+
if problems:
|
|
1767
|
+
print('\nrender would refuse:')
|
|
1768
|
+
for problem in problems:
|
|
1769
|
+
print(' ' + problem)
|
|
1770
|
+
return 1
|
|
1771
|
+
|
|
1772
|
+
print('\nready to render')
|
|
1773
|
+
return 0
|
|
1774
|
+
|
|
1775
|
+
|
|
1776
|
+
# renumber --------------------------------------------------------------------
|
|
1777
|
+
|
|
1778
|
+
MENTION = re.compile(r'\bbugs?\s+(\d+(?:(?:,\s*|\s+and\s+|\s*-\s*)\d+)*)')
|
|
1779
|
+
|
|
1780
|
+
|
|
1781
|
+
def prose_blocks(text):
|
|
1782
|
+
"""A prose file as the lines before its first field and a list of (field
|
|
1783
|
+
name, its lines from the `=== name` line on)."""
|
|
1784
|
+
|
|
1785
|
+
before, fields = [], []
|
|
1786
|
+
|
|
1787
|
+
for line in text.split('\n'):
|
|
1788
|
+
match = FIELD.match(line)
|
|
1789
|
+
|
|
1790
|
+
if match:
|
|
1791
|
+
fields.append((match.group(1), [line]))
|
|
1792
|
+
elif fields:
|
|
1793
|
+
fields[-1][1].append(line)
|
|
1794
|
+
else:
|
|
1795
|
+
before.append(line)
|
|
1796
|
+
|
|
1797
|
+
return before, fields
|
|
1798
|
+
|
|
1799
|
+
|
|
1800
|
+
def renumbered_prose(text, mapping):
|
|
1801
|
+
"""The prose with each bug's fields under its new number, general fields
|
|
1802
|
+
first and bug fields in the new number order, the fields of a bug not in
|
|
1803
|
+
`mapping` dropped."""
|
|
1804
|
+
|
|
1805
|
+
before, fields = prose_blocks(text)
|
|
1806
|
+
general, per_bug = [], []
|
|
1807
|
+
|
|
1808
|
+
for name, lines in fields:
|
|
1809
|
+
match = BUG_FIELD.match(name)
|
|
1810
|
+
|
|
1811
|
+
if not match or match.group(2) not in BUG_FIELDS:
|
|
1812
|
+
general.append(lines)
|
|
1813
|
+
elif int(match.group(1)) in mapping:
|
|
1814
|
+
new = mapping[int(match.group(1))]
|
|
1815
|
+
per_bug.append((new, '=== {}.{}'.format(new, match.group(2)), lines))
|
|
1816
|
+
|
|
1817
|
+
per_bug.sort(key=lambda item: item[0])
|
|
1818
|
+
blocks_out = [[line for line in before]] if any(line.strip()
|
|
1819
|
+
for line in before) else []
|
|
1820
|
+
blocks_out += general + [[head] + lines[1:] for _, head, lines in per_bug]
|
|
1821
|
+
|
|
1822
|
+
return '\n\n'.join('\n'.join(lines).strip('\n') for lines in blocks_out) + '\n'
|
|
1823
|
+
|
|
1824
|
+
|
|
1825
|
+
def mentions(text, mapping, known):
|
|
1826
|
+
"""The lines of the prose that name one of the bugs `known` by number, with
|
|
1827
|
+
the numbers that change or go away: (line number, line, [(old, new or
|
|
1828
|
+
None)]). A number that is no bug of this report, like "bug 18" of another
|
|
1829
|
+
one, is left alone."""
|
|
1830
|
+
|
|
1831
|
+
found = []
|
|
1832
|
+
|
|
1833
|
+
for number, line in enumerate(text.split('\n'), 1):
|
|
1834
|
+
for match in MENTION.finditer(line):
|
|
1835
|
+
named = [int(n) for n in re.findall(r'\d+', match.group(1))]
|
|
1836
|
+
moves = [(old, mapping.get(old)) for old in named
|
|
1837
|
+
if old in known and mapping.get(old) != old]
|
|
1838
|
+
if moves:
|
|
1839
|
+
found.append((number, line.strip(), moves))
|
|
1840
|
+
break
|
|
1841
|
+
|
|
1842
|
+
return found
|
|
1843
|
+
|
|
1844
|
+
|
|
1845
|
+
def renumber_command(args):
|
|
1846
|
+
"""Put bugs.tsv in category order, numbered 1 to N, and move everything
|
|
1847
|
+
that carries a number with it; with --only or --drop, keep fewer bugs."""
|
|
1848
|
+
|
|
1849
|
+
problems = Problems()
|
|
1850
|
+
path = os.path.join(args.dir, 'bugs.tsv')
|
|
1851
|
+
bugs = read_bugs(path, problems, strict=False)
|
|
1852
|
+
prose_path = args.prose or os.path.join(args.dir, 'prose.md')
|
|
1853
|
+
prose = read_text(prose_path, problems, 'prose') or ''
|
|
1854
|
+
verify_path = os.path.join(args.dir, 'verify.tsv')
|
|
1855
|
+
rows = read_verify(verify_path, problems)
|
|
1856
|
+
numbers = {bug['number'] for bug in bugs}
|
|
1857
|
+
|
|
1858
|
+
only = {int(n) for n in args.only.split(',')} if args.only else None
|
|
1859
|
+
drop = {int(n) for n in args.drop.split(',')} if args.drop else set()
|
|
1860
|
+
if args.only and args.drop:
|
|
1861
|
+
problems.add('--only and --drop are alternatives')
|
|
1862
|
+
for number in sorted((only or set()) | drop):
|
|
1863
|
+
if number not in numbers:
|
|
1864
|
+
problems.add('bug {}: not in bugs.tsv'.format(number))
|
|
1865
|
+
|
|
1866
|
+
if problems:
|
|
1867
|
+
return refuse(problems)
|
|
1868
|
+
|
|
1869
|
+
kept = [bug for bug in bugs if (only is None or bug['number'] in only)
|
|
1870
|
+
and bug['number'] not in drop]
|
|
1871
|
+
if not kept:
|
|
1872
|
+
return refuse(['no bug would be left'])
|
|
1873
|
+
|
|
1874
|
+
kept.sort(key=lambda bug: (RANK[bug['category']], bug['number']))
|
|
1875
|
+
mapping = {bug['number']: new for new, bug in enumerate(kept, 1)}
|
|
1876
|
+
dropped = sorted(numbers - set(mapping))
|
|
1877
|
+
moved = [bug for bug in kept if mapping[bug['number']] != bug['number']]
|
|
1878
|
+
|
|
1879
|
+
for bug in moved:
|
|
1880
|
+
print('{} -> {} {}'.format(bug['number'], mapping[bug['number']],
|
|
1881
|
+
bug['slug']))
|
|
1882
|
+
for number in dropped:
|
|
1883
|
+
print('{} dropped {}'.format(number, next(bug['slug'] for bug in bugs
|
|
1884
|
+
if bug['number'] == number)))
|
|
1885
|
+
|
|
1886
|
+
if not moved and not dropped:
|
|
1887
|
+
print('the {} bugs are numbered 1 to {} in category order already'.format(
|
|
1888
|
+
len(bugs), len(bugs)))
|
|
1889
|
+
return 0
|
|
1890
|
+
|
|
1891
|
+
new_prose = renumbered_prose(prose, mapping)
|
|
1892
|
+
for number, line, moves in mentions(new_prose, mapping, numbers):
|
|
1893
|
+
sys.stderr.write('issue_body: line {} of the renumbered prose names {}: '
|
|
1894
|
+
'{!r}; edit it by hand\n'.format(number, '; '.join('bug {} as {}'
|
|
1895
|
+
.format(old, 'bug {}'.format(new) if new else 'a dropped bug')
|
|
1896
|
+
for old, new in moves), line))
|
|
1897
|
+
|
|
1898
|
+
if args.dry_run:
|
|
1899
|
+
print('dry run: nothing written')
|
|
1900
|
+
return 0
|
|
1901
|
+
|
|
1902
|
+
stamp = datetime.datetime.now().strftime('%Y%m%dT%H%M%S')
|
|
1903
|
+
backup = os.path.join(args.dir, 'before-renumber-' + stamp)
|
|
1904
|
+
os.makedirs(backup)
|
|
1905
|
+
for name in ('bugs.tsv', 'prose.md', 'verify.tsv', 'verify-logs'):
|
|
1906
|
+
source = os.path.join(args.dir, name) if name != 'prose.md' else prose_path
|
|
1907
|
+
if os.path.isdir(source):
|
|
1908
|
+
shutil.copytree(source, os.path.join(backup, name))
|
|
1909
|
+
elif os.path.exists(source):
|
|
1910
|
+
shutil.copy(source, os.path.join(backup, name))
|
|
1911
|
+
|
|
1912
|
+
with open(path, encoding='utf-8') as handle:
|
|
1913
|
+
lines = handle.read().rstrip('\n').split('\n')
|
|
1914
|
+
header = [name.strip() for name in lines[0].split('\t')]
|
|
1915
|
+
raw = {}
|
|
1916
|
+
for line in lines[1:]:
|
|
1917
|
+
cells = dict(zip(header, (value.strip() for value in line.split('\t'))))
|
|
1918
|
+
raw[int(cells['number'])] = cells
|
|
1919
|
+
out = ['\t'.join(header)]
|
|
1920
|
+
|
|
1921
|
+
for bug in kept:
|
|
1922
|
+
cells = dict(raw[bug['number']], number=str(mapping[bug['number']]))
|
|
1923
|
+
out.append('\t'.join(cells[name] for name in header))
|
|
1924
|
+
|
|
1925
|
+
write(path, '\n'.join(out) + '\n')
|
|
1926
|
+
write(prose_path, new_prose)
|
|
1927
|
+
|
|
1928
|
+
logs = os.path.join(args.dir, 'verify-logs')
|
|
1929
|
+
if rows:
|
|
1930
|
+
fresh, renames = {}, []
|
|
1931
|
+
|
|
1932
|
+
for old, row in rows.items():
|
|
1933
|
+
if old not in mapping:
|
|
1934
|
+
continue
|
|
1935
|
+
|
|
1936
|
+
new = mapping[old]
|
|
1937
|
+
was = 'verify-logs/{:02d}-{}.log'.format(old, row['slug'])
|
|
1938
|
+
now = 'verify-logs/{:02d}-{}.log'.format(new, row['slug'])
|
|
1939
|
+
if row['log'] == was and old != new:
|
|
1940
|
+
renames.append((was, now))
|
|
1941
|
+
row = dict(row, log=now)
|
|
1942
|
+
fresh[new] = dict(row, number=str(new))
|
|
1943
|
+
|
|
1944
|
+
for old in dropped:
|
|
1945
|
+
if old in rows:
|
|
1946
|
+
name = os.path.basename(rows[old]['log'])
|
|
1947
|
+
if rows[old]['log'] == 'verify-logs/' + name and os.path.exists(
|
|
1948
|
+
os.path.join(logs, name)):
|
|
1949
|
+
os.remove(os.path.join(logs, name))
|
|
1950
|
+
|
|
1951
|
+
for was, now in renames:
|
|
1952
|
+
if os.path.exists(os.path.join(args.dir, was)):
|
|
1953
|
+
os.replace(os.path.join(args.dir, was), os.path.join(args.dir,
|
|
1954
|
+
now + '.moving'))
|
|
1955
|
+
for _, now in renames:
|
|
1956
|
+
if os.path.exists(os.path.join(args.dir, now + '.moving')):
|
|
1957
|
+
os.replace(os.path.join(args.dir, now + '.moving'),
|
|
1958
|
+
os.path.join(args.dir, now))
|
|
1959
|
+
|
|
1960
|
+
write_verify(verify_path, fresh)
|
|
1961
|
+
|
|
1962
|
+
print('renumbered {} bugs ({} moved, {} dropped); the originals are in '
|
|
1963
|
+
'{}'.format(len(kept), len(moved), len(dropped), backup))
|
|
1964
|
+
return 0
|
|
1965
|
+
|
|
1966
|
+
|
|
1967
|
+
# The command line ------------------------------------------------------------
|
|
1968
|
+
|
|
1969
|
+
DIR_HELP = 'the input directory, normally $WORK/ship/issue-bugs'
|
|
1970
|
+
|
|
1971
|
+
|
|
1972
|
+
def main(argv=None):
|
|
1973
|
+
argv = list(sys.argv[1:] if argv is None else argv)
|
|
1974
|
+
if not argv or argv[0] not in ('render', 'verify', 'template', 'renumber',
|
|
1975
|
+
'status', 'file', 'link', 'dupes', '-h', '--help'):
|
|
1976
|
+
argv.insert(0, 'render')
|
|
1977
|
+
|
|
1978
|
+
parser = argparse.ArgumentParser(description=__doc__,
|
|
1979
|
+
formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
1980
|
+
sub = parser.add_subparsers(dest='command', required=True)
|
|
1981
|
+
|
|
1982
|
+
render_parser = sub.add_parser('render', help='write the body (the default)')
|
|
1983
|
+
render_parser.add_argument('dir', nargs='?', help=DIR_HELP)
|
|
1984
|
+
render_parser.add_argument('--title', help='the issue\'s title, checked by '
|
|
1985
|
+
'attribution.py: a capital letter first, no closing period, at most '
|
|
1986
|
+
'{} characters (default: the one stored beside --out)'.format(
|
|
1987
|
+
attribution.TITLE_LIMIT))
|
|
1988
|
+
render_parser.add_argument('--out', required=True, help='the body, '
|
|
1989
|
+
'normally DIR/body.md; the title goes to <out stem>.title, comments to '
|
|
1990
|
+
'<out stem>.comment-N.md')
|
|
1991
|
+
render_parser.add_argument('--prose', help='the prose file (default '
|
|
1992
|
+
'DIR/prose.md)')
|
|
1993
|
+
render_parser.add_argument('--bin', action='append', metavar='NAME=PATH',
|
|
1994
|
+
help='refuse unless verify.tsv is for this binary')
|
|
1995
|
+
render_parser.add_argument('--limit', type=int, default=LIMIT, help='the '
|
|
1996
|
+
'most characters the body and each comment may have (default '
|
|
1997
|
+
'%(default)s)')
|
|
1998
|
+
|
|
1999
|
+
verify_parser = sub.add_parser('verify', help='run the reproductions and '
|
|
2000
|
+
'write verify.tsv')
|
|
2001
|
+
verify_parser.add_argument('dir', help=DIR_HELP)
|
|
2002
|
+
verify_parser.add_argument('--bin', action='append', metavar='NAME=PATH',
|
|
2003
|
+
help='a binary the reproductions call as NAME, first on the PATH; '
|
|
2004
|
+
'repeatable')
|
|
2005
|
+
verify_parser.add_argument('--bug', type=int, action='append', help='only '
|
|
2006
|
+
'this bug; repeatable (default: every bug not marked manual)')
|
|
2007
|
+
verify_parser.add_argument('--prose', help='the prose file (default '
|
|
2008
|
+
'DIR/prose.md)')
|
|
2009
|
+
verify_parser.add_argument('--commit', help='the commit the binary was '
|
|
2010
|
+
'built from, recorded in each row; render requires the intro to name it')
|
|
2011
|
+
verify_parser.add_argument('--timeout', type=float, default=600, help='seconds '
|
|
2012
|
+
'for the setup and for the reproduction, each (default %(default)s)')
|
|
2013
|
+
verify_parser.add_argument('--workdir', help='where the temporary '
|
|
2014
|
+
'directories go (default: the system\'s)')
|
|
2015
|
+
verify_parser.add_argument('--path', help='the PATH after the binaries\' '
|
|
2016
|
+
'directory (default: this process\'s)')
|
|
2017
|
+
verify_parser.add_argument('--cpus', help='run under taskset -c CPUS')
|
|
2018
|
+
verify_parser.add_argument('--stale', action='store_true', help='run only '
|
|
2019
|
+
'the bugs with no row, a failed row, a row for text that has changed, or '
|
|
2020
|
+
'a row for another binary or --commit; a stale manual row is reported')
|
|
2021
|
+
verify_parser.add_argument('--keep', action='store_true', help='keep the '
|
|
2022
|
+
'temporary directory of a bug that passed')
|
|
2023
|
+
verify_parser.add_argument('--manual', type=int, metavar='N', help='mark bug '
|
|
2024
|
+
'N manual instead of running it: it needs a build or harness verify '
|
|
2025
|
+
'cannot provide')
|
|
2026
|
+
verify_parser.add_argument('--reason', help='with --manual: why, as a clause '
|
|
2027
|
+
'the body shows ("it needs a clang++/libomp build")')
|
|
2028
|
+
verify_parser.add_argument('--log', help='with --manual: the output of the '
|
|
2029
|
+
'run that shows the bug')
|
|
2030
|
+
|
|
2031
|
+
template_parser = sub.add_parser('template', help='print a prose skeleton '
|
|
2032
|
+
'for DIR/bugs.tsv')
|
|
2033
|
+
template_parser.add_argument('dir', help=DIR_HELP)
|
|
2034
|
+
|
|
2035
|
+
renumber_parser = sub.add_parser('renumber', help='number the bugs 1 to N in '
|
|
2036
|
+
'category order and move their prose, verify rows and logs with them')
|
|
2037
|
+
renumber_parser.add_argument('dir', help=DIR_HELP)
|
|
2038
|
+
renumber_parser.add_argument('--only', metavar='N,N,…', help='keep only '
|
|
2039
|
+
'these bugs')
|
|
2040
|
+
renumber_parser.add_argument('--drop', metavar='N,N,…', help='remove these '
|
|
2041
|
+
'bugs')
|
|
2042
|
+
renumber_parser.add_argument('--prose', help='the prose file (default '
|
|
2043
|
+
'DIR/prose.md)')
|
|
2044
|
+
renumber_parser.add_argument('--dry-run', action='store_true', help='print '
|
|
2045
|
+
'the new numbers and the prose lines to edit; write nothing')
|
|
2046
|
+
|
|
2047
|
+
status_parser = sub.add_parser('status', help='where the inputs stand, and '
|
|
2048
|
+
'what render would refuse')
|
|
2049
|
+
status_parser.add_argument('dir', help=DIR_HELP)
|
|
2050
|
+
status_parser.add_argument('--bin', action='append', metavar='NAME=PATH',
|
|
2051
|
+
help='also report rows for another binary than this one as stale')
|
|
2052
|
+
status_parser.add_argument('--prose', help='the prose file (default '
|
|
2053
|
+
'DIR/prose.md)')
|
|
2054
|
+
status_parser.add_argument('--limit', type=int, default=LIMIT, help='the '
|
|
2055
|
+
'size limit to plan the comments for (default %(default)s)')
|
|
2056
|
+
|
|
2057
|
+
file_parser = sub.add_parser('file', help='preview filing the issue; with '
|
|
2058
|
+
'--post, file it and its comments')
|
|
2059
|
+
file_parser.add_argument('dir', help=DIR_HELP)
|
|
2060
|
+
file_parser.add_argument('--repo', required=True, metavar='OWNER/REPO')
|
|
2061
|
+
file_parser.add_argument('--post', action='store_true', help='create the '
|
|
2062
|
+
'issue and post the comments; without it nothing is filed')
|
|
2063
|
+
file_parser.add_argument('--body', help='the rendered body (default '
|
|
2064
|
+
'DIR/body.md; its title and comments sit beside it)')
|
|
2065
|
+
file_parser.add_argument('--other-owner', action='store_true', help='with '
|
|
2066
|
+
'--post: the user has confirmed filing on a repository the account gh is '
|
|
2067
|
+
'logged in as does not own')
|
|
2068
|
+
file_parser.add_argument('--prose', help='the prose file (default '
|
|
2069
|
+
'DIR/prose.md)')
|
|
2070
|
+
file_parser.add_argument('--limit', type=int, default=LIMIT, help='the limit '
|
|
2071
|
+
'the body was rendered with (default %(default)s)')
|
|
2072
|
+
|
|
2073
|
+
link_parser = sub.add_parser('link', help='fill a stand-in number in '
|
|
2074
|
+
'documents')
|
|
2075
|
+
link_parser.add_argument('dir', help=DIR_HELP + ', which holds filed.json')
|
|
2076
|
+
link_parser.add_argument('files', nargs='+', metavar='FILE')
|
|
2077
|
+
link_parser.add_argument('--placeholder', help='one of {} (default the '
|
|
2078
|
+
'first)'.format(', '.join(attribution.PLACEHOLDERS)))
|
|
2079
|
+
link_parser.add_argument('--value', help='#N or a URL (default the issue '
|
|
2080
|
+
'number in filed.json)')
|
|
2081
|
+
|
|
2082
|
+
dupes_parser = sub.add_parser('dupes', help='list existing issues that may '
|
|
2083
|
+
'already report each bug')
|
|
2084
|
+
dupes_parser.add_argument('dir', help=DIR_HELP)
|
|
2085
|
+
dupes_parser.add_argument('--repo', metavar='OWNER/REPO')
|
|
2086
|
+
dupes_parser.add_argument('--issues', metavar='FILE', help='the JSON of `gh '
|
|
2087
|
+
'issue list --state all --json number,title,state,url,body`, instead of '
|
|
2088
|
+
'asking gh')
|
|
2089
|
+
dupes_parser.add_argument('--top', type=int, default=3, help='candidates per '
|
|
2090
|
+
'bug (default %(default)s)')
|
|
2091
|
+
dupes_parser.add_argument('--min-score', type=int, default=4, help='the '
|
|
2092
|
+
'lowest score listed (default %(default)s)')
|
|
2093
|
+
dupes_parser.add_argument('--max-issues', type=int, default=2000, help='how '
|
|
2094
|
+
'many issues to read (default %(default)s)')
|
|
2095
|
+
dupes_parser.add_argument('--prose', help='the prose file (default '
|
|
2096
|
+
'DIR/prose.md)')
|
|
2097
|
+
|
|
2098
|
+
args = parser.parse_args(argv)
|
|
2099
|
+
|
|
2100
|
+
if args.command == 'dupes':
|
|
2101
|
+
return dupes_command(args)
|
|
2102
|
+
if args.command == 'file':
|
|
2103
|
+
return file_command(args)
|
|
2104
|
+
if args.command == 'link':
|
|
2105
|
+
return link_command(args)
|
|
2106
|
+
if args.command == 'status':
|
|
2107
|
+
return status_command(args)
|
|
2108
|
+
if args.command == 'renumber':
|
|
2109
|
+
return renumber_command(args)
|
|
2110
|
+
if args.command == 'verify':
|
|
2111
|
+
return verify_command(args)
|
|
2112
|
+
if args.command == 'template':
|
|
2113
|
+
return template_command(args)
|
|
2114
|
+
return render_command(args)
|
|
2115
|
+
|
|
2116
|
+
|
|
2117
|
+
if __name__ == '__main__':
|
|
2118
|
+
raise SystemExit(main())
|