lean-pkg 0.25.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.
- lean_pkg/__init__.py +3 -0
- lean_pkg/adapters/__init__.py +148 -0
- lean_pkg/adapters/github.py +65 -0
- lean_pkg/adapters/leansearch.py +68 -0
- lean_pkg/adapters/loogle.py +45 -0
- lean_pkg/adapters/palomar.py +170 -0
- lean_pkg/adapters/reservoir.py +127 -0
- lean_pkg/anchor.py +678 -0
- lean_pkg/audit.py +716 -0
- lean_pkg/binding_file.py +446 -0
- lean_pkg/blueprint.py +213 -0
- lean_pkg/build_scope.py +282 -0
- lean_pkg/ci_github.py +917 -0
- lean_pkg/claim_axioms.py +421 -0
- lean_pkg/claims.py +1155 -0
- lean_pkg/claims_mark.py +197 -0
- lean_pkg/cli.py +5208 -0
- lean_pkg/cli_parser.py +768 -0
- lean_pkg/command_tree.py +615 -0
- lean_pkg/comparator_config.py +990 -0
- lean_pkg/comparator_contracts.py +382 -0
- lean_pkg/comparator_receipt.py +2854 -0
- lean_pkg/comparator_stage.py +623 -0
- lean_pkg/comparator_types.py +830 -0
- lean_pkg/container.py +172 -0
- lean_pkg/core.py +1570 -0
- lean_pkg/coverage.py +1278 -0
- lean_pkg/data/stacks/lts-2026.10.yaml +73 -0
- lean_pkg/data/toolchain-advisories.yaml +77 -0
- lean_pkg/data/upgrade-breaking.yaml +20 -0
- lean_pkg/data/verify-workflow-pins.yaml +14 -0
- lean_pkg/deps_closure.py +512 -0
- lean_pkg/deps_fill.py +445 -0
- lean_pkg/dup_constants.py +448 -0
- lean_pkg/exercise.py +828 -0
- lean_pkg/exercise_forbid.py +288 -0
- lean_pkg/export_paths.py +77 -0
- lean_pkg/extract.py +1172 -0
- lean_pkg/extract_decls.py +501 -0
- lean_pkg/extract_ledger.py +1408 -0
- lean_pkg/extract_summary.py +132 -0
- lean_pkg/extract_types.py +502 -0
- lean_pkg/extract_write.py +138 -0
- lean_pkg/formalization.py +1078 -0
- lean_pkg/formalization_kept.py +182 -0
- lean_pkg/fresh_repo.py +709 -0
- lean_pkg/gate.py +2141 -0
- lean_pkg/headline.py +211 -0
- lean_pkg/help_topics.py +442 -0
- lean_pkg/holes.py +289 -0
- lean_pkg/host_routes.py +376 -0
- lean_pkg/hypotheses.py +788 -0
- lean_pkg/index.py +1749 -0
- lean_pkg/json_stdout.py +48 -0
- lean_pkg/lake_hygiene.py +289 -0
- lean_pkg/lean_diag.py +280 -0
- lean_pkg/lean_scan.py +1300 -0
- lean_pkg/ledger.py +582 -0
- lean_pkg/next_step.py +510 -0
- lean_pkg/page.py +1831 -0
- lean_pkg/page_html.py +153 -0
- lean_pkg/palomar.py +316 -0
- lean_pkg/palomar_check.py +1027 -0
- lean_pkg/port_modules.py +677 -0
- lean_pkg/prior_art.py +286 -0
- lean_pkg/producer.py +212 -0
- lean_pkg/producer_skew.py +208 -0
- lean_pkg/public_safety.py +1487 -0
- lean_pkg/publish.py +402 -0
- lean_pkg/rebase.py +984 -0
- lean_pkg/receipt.py +2385 -0
- lean_pkg/receipt_check.py +1064 -0
- lean_pkg/receipt_ci.py +660 -0
- lean_pkg/receipt_systemd.py +890 -0
- lean_pkg/recommended.py +232 -0
- lean_pkg/report.py +727 -0
- lean_pkg/reservoir.py +203 -0
- lean_pkg/scaffold.py +588 -0
- lean_pkg/schemas/formalization-0.4.schema.json +344 -0
- lean_pkg/schemas/formalization-0.4.schema.source.txt +15 -0
- lean_pkg/scripts/ClaimAxioms.lean +47 -0
- lean_pkg/scripts/ContractsOnly.lean +300 -0
- lean_pkg/scripts/DupConstants.lean +149 -0
- lean_pkg/scripts/HypProbe.lean +257 -0
- lean_pkg/scripts/comparator-check.sh +396 -0
- lean_pkg/scripts/verify-comparator.sh +135 -0
- lean_pkg/seal_bundle.py +647 -0
- lean_pkg/search.py +865 -0
- lean_pkg/site_profiles/easley.yaml +10 -0
- lean_pkg/site_profiles/github-actions.yaml +12 -0
- lean_pkg/sites.py +225 -0
- lean_pkg/stacks.py +373 -0
- lean_pkg/statements_module.py +217 -0
- lean_pkg/templates/Apache-2.0.txt +202 -0
- lean_pkg/toolchain_advisories.py +225 -0
- lean_pkg/upgrade.py +706 -0
- lean_pkg/verify.py +495 -0
- lean_pkg-0.25.0.dist-info/METADATA +93 -0
- lean_pkg-0.25.0.dist-info/RECORD +103 -0
- lean_pkg-0.25.0.dist-info/WHEEL +5 -0
- lean_pkg-0.25.0.dist-info/entry_points.txt +5 -0
- lean_pkg-0.25.0.dist-info/licenses/LICENSE +202 -0
- lean_pkg-0.25.0.dist-info/top_level.txt +1 -0
lean_pkg/coverage.py
ADDED
|
@@ -0,0 +1,1278 @@
|
|
|
1
|
+
# lean-pkg coverage -- the coverage file (coverage/1: a paper's results, or a library's) and its checker
|
|
2
|
+
"""`lean-pkg coverage check NAME [--file PATH] [--allow-private-manuscript]`, and the offline form
|
|
3
|
+
`lean-pkg coverage check --file PATH [--claims PATH] [--comparator PATH ...] [--allow-private-manuscript]` (#328:
|
|
4
|
+
no registry record, no receipt; offline_check, which verify's preflight also runs at HEAD).
|
|
5
|
+
|
|
6
|
+
`claims.yaml` is declaration-centric: one row per Lean result. `coverage.yaml` (schema `coverage/1`, in
|
|
7
|
+
the package directory) is paper-centric: one row per numbered result of a citable manuscript, saying how
|
|
8
|
+
the formalization relates to it. `lean-pkg page` renders the README's paper-to-Lean map, the "Not
|
|
9
|
+
formalized" list and the status capsule from it; this module only parses and validates.
|
|
10
|
+
|
|
11
|
+
schema: coverage/1
|
|
12
|
+
package: NAME
|
|
13
|
+
manuscript:
|
|
14
|
+
title: TEXT
|
|
15
|
+
version: "arXiv:<id>v<N>" # or {repo: https://..., commit: 40hex, sha256: 64hex}
|
|
16
|
+
# or "unposted" (needs --allow-private-manuscript)
|
|
17
|
+
eprint_sha256: 64hex # optional, with an arXiv version: the e-print's SHA-256
|
|
18
|
+
# (`formalization anchor` writes it and its source baseline)
|
|
19
|
+
summary: ONE SENTENCE # the capsule's hand-written sentence
|
|
20
|
+
rows:
|
|
21
|
+
- paper: {number: "Theorem 1.2", title: "Main estimate", label: "T:main"} # label optional
|
|
22
|
+
# paper.statement (optional): the result as the paper states it, in TeX, at most 2000 characters
|
|
23
|
+
class: same-assumptions | inputs-supplied | outside
|
|
24
|
+
claims: [NAME/claim-id, ...] # ids in claims.yaml at HEAD; none for outside
|
|
25
|
+
inputs: [TEXT, ...] # required for inputs-supplied; none otherwise; an entry
|
|
26
|
+
# may be {hypothesis: Name, text: TEXT} (proposal 0003): an
|
|
27
|
+
# assumption in the hypotheses of a claim the row names
|
|
28
|
+
note: TEXT # optional
|
|
29
|
+
nothing_excluded: {reason: TEXT} # only when no row is outside
|
|
30
|
+
compute: # optional: where the gates ran
|
|
31
|
+
- cluster: easley
|
|
32
|
+
jobs: [slurm-12345] # each a Slurm receipt tracked under .lean-receipts/
|
|
33
|
+
lean_pkg_version: {version: 0.7.52, doi: 10.5281/zenodo.N} # optional: the exact version credited
|
|
34
|
+
kind: paper # optional; paper is the default
|
|
35
|
+
stack: lts-2026.10 # optional: the LTS stack the package is on (proposal 0004);
|
|
36
|
+
# doctor NAME, verify and page check the pins against it
|
|
37
|
+
|
|
38
|
+
A reusable library with no manuscript of its own is `kind: library`: no `manuscript` and no
|
|
39
|
+
`nothing_excluded` (refused, so a library page never claims a paper), and each row is one of the library's
|
|
40
|
+
main results, named by its Lean declarations:
|
|
41
|
+
|
|
42
|
+
schema: coverage/1
|
|
43
|
+
package: NAME
|
|
44
|
+
kind: library
|
|
45
|
+
summary: ONE SENTENCE
|
|
46
|
+
rows:
|
|
47
|
+
- title: "Main estimate" # one line, unique in the file
|
|
48
|
+
claims: [NAME/claim-id, ...] # at least one id in claims.yaml at HEAD
|
|
49
|
+
note: TEXT # optional
|
|
50
|
+
statement: TEX # optional: the result in mathematical words
|
|
51
|
+
compute: ... # as above (the Easley rule is the same)
|
|
52
|
+
lean_pkg_version: ... # as above
|
|
53
|
+
stack: ... # as above
|
|
54
|
+
|
|
55
|
+
Strict: unknown or missing keys, values outside the closed enums and duplicate mapping keys are
|
|
56
|
+
refused. Classes: `same-assumptions` (the Lean statement carries the paper's hypotheses),
|
|
57
|
+
`inputs-supplied` (it takes the named `inputs` as hypotheses), `outside` (no Lean counterpart).
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
from __future__ import annotations
|
|
61
|
+
|
|
62
|
+
import json
|
|
63
|
+
import pathlib
|
|
64
|
+
import re
|
|
65
|
+
|
|
66
|
+
import yaml
|
|
67
|
+
|
|
68
|
+
from . import cli, gate as gate_mod
|
|
69
|
+
from . import core
|
|
70
|
+
from . import sites
|
|
71
|
+
from .holes import SIDECAR
|
|
72
|
+
|
|
73
|
+
COVERAGE_SCHEMA = "coverage/1"
|
|
74
|
+
DEFAULT_COVERAGE_FILE = "coverage.yaml"
|
|
75
|
+
TOP_REQUIRED = ("schema", "package", "manuscript", "summary", "rows")
|
|
76
|
+
TOP_OPTIONAL = ("nothing_excluded", "compute", "lean_pkg_version", "kind", "stack")
|
|
77
|
+
KINDS = ("paper", "library")
|
|
78
|
+
LIBRARY_TOP_REQUIRED = ("schema", "package", "kind", "summary", "rows")
|
|
79
|
+
LIBRARY_TOP_OPTIONAL = ("compute", "lean_pkg_version", "stack")
|
|
80
|
+
STACK_NAME_RE = re.compile(r"^lts-\d{4}\.(?:04|10)$") # proposal 0004: lts-YYYY.MM, cut in April and October
|
|
81
|
+
LIBRARY_ROW_REQUIRED = ("title", "claims")
|
|
82
|
+
LIBRARY_ROW_OPTIONAL = ("note", "statement")
|
|
83
|
+
# keys of a paper coverage that a library refuses by name: each would state a manuscript, or a relation to one
|
|
84
|
+
LIBRARY_NO_PAPER = {
|
|
85
|
+
"manuscript": "manuscript: a library coverage names no manuscript (kind: library); a package that formalizes "
|
|
86
|
+
"results of a paper is kind paper (the default) and pins the paper's posted version",
|
|
87
|
+
"nothing_excluded": "nothing_excluded: states that nothing of a manuscript is excluded, and a library "
|
|
88
|
+
"coverage (kind: library) has no manuscript; drop it",
|
|
89
|
+
}
|
|
90
|
+
LIBRARY_ROW_NO_PAPER = ("paper", "class", "inputs")
|
|
91
|
+
ROW_REQUIRED = ("paper", "class")
|
|
92
|
+
ROW_OPTIONAL = ("claims", "inputs", "note")
|
|
93
|
+
INPUT_KEYS = ("hypothesis", "text") # an inputs entry that names a hypothesis (proposal 0003, H2)
|
|
94
|
+
PAPER_REQUIRED = ("number", "title")
|
|
95
|
+
PAPER_OPTIONAL = ("label", "statement")
|
|
96
|
+
CLASSES = ("same-assumptions", "inputs-supplied", "outside")
|
|
97
|
+
CLASS_GLOSS = {"same-assumptions": "Same assumptions", "inputs-supplied": "Inputs supplied",
|
|
98
|
+
"outside": "Outside this formalization"}
|
|
99
|
+
CLUSTERS = sites.names() # the built-in site profiles; a package may add its own (sites.py)
|
|
100
|
+
UNPOSTED = "unposted"
|
|
101
|
+
ARXIV_VERSION_RE = re.compile(r"^arXiv:(?:\d{4}\.\d{4,5}|[a-z-]+(?:\.[A-Z]{2})?/\d{7})v\d+$")
|
|
102
|
+
HEX40 = re.compile(r"^[0-9a-f]{40}$")
|
|
103
|
+
HEX64 = re.compile(r"^[0-9a-f]{64}$")
|
|
104
|
+
HTTPS_URL_RE = re.compile(r"^https://[A-Za-z0-9.-]+(?::\d+)?/[A-Za-z0-9._~/%+-]+$")
|
|
105
|
+
SLURM_JOB_RE = sites.SLURM.job_re
|
|
106
|
+
VERSION_RE = re.compile(r"^\d+\.\d+\.\d+$")
|
|
107
|
+
ZENODO_DOI_RE = re.compile(r"^10\.5281/zenodo\.\d+$")
|
|
108
|
+
TEXT_MAX = 400
|
|
109
|
+
STATEMENT_MAX = 2000 # paper.statement / a library row's statement: TeX, may span lines
|
|
110
|
+
# lean-scope-page R4: a placeholder never reaches a public page (FILL-ME is the lab template's marker)
|
|
111
|
+
PLACEHOLDER_RE = re.compile(r"(?<![A-Za-z0-9])(?:FILL-ME|TODO|TBD|FIXME|XXX)(?![A-Za-z0-9])")
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class _StrictLoader(yaml.SafeLoader):
|
|
115
|
+
"""safe_load, but a mapping that repeats a key is an error (PyYAML keeps the last one silently)."""
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _no_duplicates(loader, node, deep=False):
|
|
119
|
+
seen = set()
|
|
120
|
+
for key_node, _value in node.value:
|
|
121
|
+
key = loader.construct_object(key_node, deep=deep)
|
|
122
|
+
try:
|
|
123
|
+
dup = key in seen
|
|
124
|
+
except TypeError:
|
|
125
|
+
dup = False
|
|
126
|
+
if dup:
|
|
127
|
+
raise yaml.constructor.ConstructorError(
|
|
128
|
+
None, None, f"duplicate key {key!r}", key_node.start_mark)
|
|
129
|
+
try:
|
|
130
|
+
seen.add(key)
|
|
131
|
+
except TypeError:
|
|
132
|
+
pass
|
|
133
|
+
return yaml.SafeLoader.construct_mapping(loader, node, deep)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
_StrictLoader.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, _no_duplicates)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def load_text(text: str, where: str) -> dict:
|
|
140
|
+
try:
|
|
141
|
+
data = yaml.load(text, Loader=_StrictLoader)
|
|
142
|
+
except yaml.YAMLError as e:
|
|
143
|
+
raise core.Fail(f"{where}: not valid YAML: {' '.join(str(e).split())}") from e
|
|
144
|
+
if not isinstance(data, dict):
|
|
145
|
+
raise core.Fail(f"{where}: top level is not a mapping")
|
|
146
|
+
return data
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def _text(v, limit: int = TEXT_MAX) -> bool:
|
|
150
|
+
return isinstance(v, str) and bool(v.strip()) and "\n" not in v.strip() and len(v) <= limit
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _keys(obj, required, optional, where: str, errors: list[str]) -> bool:
|
|
154
|
+
if not isinstance(obj, dict):
|
|
155
|
+
errors.append(f"{where}: must be a mapping")
|
|
156
|
+
return False
|
|
157
|
+
unknown = [str(k) for k in obj if k not in required and k not in optional]
|
|
158
|
+
missing = [k for k in required if k not in obj]
|
|
159
|
+
if unknown:
|
|
160
|
+
errors.append(f"{where}: unknown key(s) {', '.join(sorted(unknown))} "
|
|
161
|
+
f"(allowed: {', '.join(tuple(required) + tuple(optional))})")
|
|
162
|
+
if missing:
|
|
163
|
+
errors.append(f"{where}: missing key(s) {', '.join(missing)}")
|
|
164
|
+
return not unknown and not missing
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _str_list(v, where: str, errors: list[str]) -> list[str]:
|
|
168
|
+
if v is None:
|
|
169
|
+
return []
|
|
170
|
+
if not isinstance(v, list) or not all(_text(x) for x in v):
|
|
171
|
+
errors.append(f"{where}: must be a list of one-line strings (at most {TEXT_MAX} characters each)")
|
|
172
|
+
return []
|
|
173
|
+
if len(set(v)) != len(v):
|
|
174
|
+
errors.append(f"{where}: repeats an entry")
|
|
175
|
+
return list(v)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def _inputs_list(v, where: str, errors: list[str]) -> list:
|
|
179
|
+
"""A row's inputs: each a one-line string (as before) or {hypothesis: Name, text: one line} with exactly
|
|
180
|
+
those keys (proposal 0003); no string twice and no hypothesis twice."""
|
|
181
|
+
from . import lean_scan
|
|
182
|
+
if v is None:
|
|
183
|
+
return []
|
|
184
|
+
if not isinstance(v, list):
|
|
185
|
+
errors.append(f"{where}: must be a list of one-line strings (at most {TEXT_MAX} characters each) or "
|
|
186
|
+
f"{{hypothesis, text}} mappings")
|
|
187
|
+
return []
|
|
188
|
+
ok = True
|
|
189
|
+
for j, x in enumerate(v):
|
|
190
|
+
w = f"{where}[{j}]"
|
|
191
|
+
if isinstance(x, dict):
|
|
192
|
+
if not _keys(x, INPUT_KEYS, (), w, errors):
|
|
193
|
+
ok = False
|
|
194
|
+
continue
|
|
195
|
+
h = x["hypothesis"]
|
|
196
|
+
if not (isinstance(h, str) and lean_scan.is_name(h)) or h == "TODO":
|
|
197
|
+
errors.append(f"{w}.hypothesis: must be the fully qualified Lean name of an assumption (a name "
|
|
198
|
+
f"in the hypotheses of a claim the row names), got {h!r}")
|
|
199
|
+
ok = False
|
|
200
|
+
if not _text(x["text"]):
|
|
201
|
+
errors.append(f"{w}.text: must be one line of at most {TEXT_MAX} characters")
|
|
202
|
+
ok = False
|
|
203
|
+
elif not _text(x):
|
|
204
|
+
errors.append(f"{w}: must be a one-line string (at most {TEXT_MAX} characters) or a mapping "
|
|
205
|
+
f"{{hypothesis, text}}")
|
|
206
|
+
ok = False
|
|
207
|
+
if not ok:
|
|
208
|
+
return []
|
|
209
|
+
texts = [x for x in v if isinstance(x, str)]
|
|
210
|
+
if len(set(texts)) != len(texts):
|
|
211
|
+
errors.append(f"{where}: repeats an entry")
|
|
212
|
+
hyps = [x["hypothesis"] for x in v if isinstance(x, dict)]
|
|
213
|
+
dups = sorted({h for h in hyps if hyps.count(h) > 1})
|
|
214
|
+
if dups:
|
|
215
|
+
errors.append(f"{where}: names hypothesis {', '.join(dups)} more than once")
|
|
216
|
+
return list(v)
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def input_hypothesis_problems(doc: dict, claims: dict[str, dict], where: str) -> list[str]:
|
|
220
|
+
"""Each {hypothesis, text} input names a hypothesis of some claim its row names (claims.yaml `hypotheses`,
|
|
221
|
+
read from `where`)."""
|
|
222
|
+
errors: list[str] = []
|
|
223
|
+
for i, r in enumerate(doc.get("rows") or []):
|
|
224
|
+
ids = [cid for cid in r.get("claims") or [] if cid in claims]
|
|
225
|
+
have = {h for cid in ids for h in (claims[cid].get("hypotheses") or []) if isinstance(h, str)}
|
|
226
|
+
for j, x in enumerate(r.get("inputs") or []):
|
|
227
|
+
if isinstance(x, dict) and x.get("hypothesis") not in have:
|
|
228
|
+
errors.append(f"rows[{i}].inputs[{j}].hypothesis: {x.get('hypothesis')!r} is not in the hypotheses "
|
|
229
|
+
f"of any claim the row names ({', '.join(ids) or 'none'}) in {where}; list it under "
|
|
230
|
+
f"hypotheses of the claim whose declaration takes it, or write the input as text")
|
|
231
|
+
return errors
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
UNLISTED_ASSUMPTION_KINDS = ("def",) # open question 7: a binder headed by a `Prop` def of the package
|
|
235
|
+
UNLISTED_ASSUMPTION_CLASSES = ("same-assumptions", "inputs-supplied")
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def unlisted_assumption_warnings(doc: dict, claims: dict[str, dict], repo: pathlib.Path, receipt, rel
|
|
239
|
+
) -> list[str]:
|
|
240
|
+
"""Proposal 0003, open question 7: a warning, never an error, for each assumption a mapped theorem takes
|
|
241
|
+
that is not listed: an explicit-or-not binder of the claim's declaration, as the hyp-decl lines of the
|
|
242
|
+
hyp-probe/1 section of the lower-tier receipt's sealed verify log (`receipt`, at `rel`; hash-checked by
|
|
243
|
+
gate.sealed_log_text) show it, whose head is a `Prop` def declared in a module of the package (its file is
|
|
244
|
+
committed at HEAD), and that neither the claim's `hypotheses` nor a {hypothesis, text} input of the row
|
|
245
|
+
names. Paper rows of class same-assumptions or inputs-supplied only (a library row is its Lean statement).
|
|
246
|
+
[] when there is no receipt, no readable log or no complete section: no data, no warning."""
|
|
247
|
+
from . import hypotheses as hyp
|
|
248
|
+
from . import lean_scan
|
|
249
|
+
rows = [(i, r) for i, r in enumerate(doc.get("rows") or [])
|
|
250
|
+
if isinstance(r, dict) and r.get("class") in UNLISTED_ASSUMPTION_CLASSES and r.get("claims")]
|
|
251
|
+
if doc_kind(doc) != "paper" or not rows or not isinstance(receipt, dict) or not rel:
|
|
252
|
+
return []
|
|
253
|
+
fx = hyp.facts(gate_mod.sealed_log_text(repo, receipt, rel))
|
|
254
|
+
if not fx.get("ok"):
|
|
255
|
+
return []
|
|
256
|
+
in_package: dict[str, bool] = {}
|
|
257
|
+
|
|
258
|
+
def _ours(module: str) -> bool:
|
|
259
|
+
if module not in in_package:
|
|
260
|
+
f = lean_scan.module_file(module) if module else None
|
|
261
|
+
in_package[module] = bool(f) and core.tracked_at(repo, f)
|
|
262
|
+
return in_package[module]
|
|
263
|
+
|
|
264
|
+
out: list[str] = []
|
|
265
|
+
for i, r in rows:
|
|
266
|
+
named = {x.get("hypothesis") for x in r.get("inputs") or [] if isinstance(x, dict)}
|
|
267
|
+
for cid in r["claims"]:
|
|
268
|
+
c = claims.get(cid)
|
|
269
|
+
obj = fx["decls"].get(str((c or {}).get("decl") or ""))
|
|
270
|
+
if obj is None:
|
|
271
|
+
continue
|
|
272
|
+
listed = named | {h for h in c.get("hypotheses") or [] if isinstance(h, str)}
|
|
273
|
+
heads = list(dict.fromkeys(b["head"] for b in obj["binders"]
|
|
274
|
+
if b["kind"] in UNLISTED_ASSUMPTION_KINDS and b["head"] not in listed
|
|
275
|
+
and _ours(b["module"])))
|
|
276
|
+
for h in heads:
|
|
277
|
+
module = next(b["module"] for b in obj["binders"] if b["head"] == h)
|
|
278
|
+
out.append(f"rows[{i}] ({r['paper'].get('number')}, {r['class']}): claim {cid} ({obj['theorem']}) "
|
|
279
|
+
f"takes the assumption {h}, a Prop def of the package ({module}), that neither the "
|
|
280
|
+
f"claim's hypotheses nor the row's inputs name (the gate receipt's sealed verify log): "
|
|
281
|
+
f"the claims ledger calls it verified without it. List it under hypotheses of {cid} "
|
|
282
|
+
f"and name it in the row's inputs (class inputs-supplied), or make it part of the "
|
|
283
|
+
f"statement (proposal 0003, open question 7)")
|
|
284
|
+
return out
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def _strings(obj, where: str):
|
|
288
|
+
"""(path, string) for every string value of a document, in document order."""
|
|
289
|
+
if isinstance(obj, str):
|
|
290
|
+
yield where, obj
|
|
291
|
+
elif isinstance(obj, dict):
|
|
292
|
+
for k, v in obj.items():
|
|
293
|
+
yield from _strings(v, f"{where}.{k}" if where else str(k))
|
|
294
|
+
elif isinstance(obj, list):
|
|
295
|
+
for i, v in enumerate(obj):
|
|
296
|
+
yield from _strings(v, f"{where}[{i}]")
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def _statement_errors(v, where: str, errors: list[str]) -> None:
|
|
300
|
+
"""An optional statement: TeX text a reader compares with the Lean statement; several lines allowed.
|
|
301
|
+
A line that opens a code fence is refused: the page shows the text inside one."""
|
|
302
|
+
if not (isinstance(v, str) and v.strip() and len(v) <= STATEMENT_MAX):
|
|
303
|
+
errors.append(f"{where}: must be a non-empty string of at most {STATEMENT_MAX} characters (TeX)")
|
|
304
|
+
elif any(x.lstrip().startswith(("```", "~~~")) for x in v.splitlines()):
|
|
305
|
+
errors.append(f"{where}: a line may not start with ``` or ~~~ (the page shows the statement in a "
|
|
306
|
+
f"code block)")
|
|
307
|
+
elif "lean-pkg:page:" in v:
|
|
308
|
+
errors.append(f"{where}: may not contain the page markers (lean-pkg:page:...), which delimit the "
|
|
309
|
+
f"README block")
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def doc_kind(doc) -> str:
|
|
313
|
+
"""'paper' or 'library' (kind is optional; paper is the default)."""
|
|
314
|
+
return "library" if isinstance(doc, dict) and doc.get("kind") == "library" else "paper"
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def manuscript_kind(version) -> str:
|
|
318
|
+
"""'arxiv', 'commit' or 'unposted' (assumes a validated version)."""
|
|
319
|
+
if isinstance(version, dict):
|
|
320
|
+
return "commit"
|
|
321
|
+
return "unposted" if version == UNPOSTED else "arxiv"
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def _manuscript_errors(m, errors: list[str]) -> None:
|
|
325
|
+
if not _keys(m, ("title", "version"), ("eprint_sha256",), "manuscript", errors):
|
|
326
|
+
return
|
|
327
|
+
if "eprint_sha256" in m: # additive (formalization anchor): only beside an arXiv version
|
|
328
|
+
if not (isinstance(m["eprint_sha256"], str) and HEX64.match(m["eprint_sha256"])):
|
|
329
|
+
errors.append("manuscript.eprint_sha256: must be the 64-hex SHA-256 of the arXiv e-print")
|
|
330
|
+
if not (isinstance(m["version"], str) and ARXIV_VERSION_RE.match(m["version"])):
|
|
331
|
+
errors.append("manuscript.eprint_sha256: goes with an arXiv version (arXiv:<id>v<N>)")
|
|
332
|
+
if not _text(m["title"]):
|
|
333
|
+
errors.append("manuscript.title: must be a one-line string")
|
|
334
|
+
v = m["version"]
|
|
335
|
+
if isinstance(v, str):
|
|
336
|
+
if v != UNPOSTED and not ARXIV_VERSION_RE.match(v):
|
|
337
|
+
errors.append(f"manuscript.version: must be an arXiv id with its version (arXiv:<id>v<N>), "
|
|
338
|
+
f"a mapping {{repo, commit, sha256}}, or {UNPOSTED!r}; got {v!r}")
|
|
339
|
+
elif isinstance(v, dict):
|
|
340
|
+
if _keys(v, ("repo", "commit", "sha256"), (), "manuscript.version", errors):
|
|
341
|
+
if not (isinstance(v["repo"], str) and HTTPS_URL_RE.match(v["repo"])):
|
|
342
|
+
errors.append("manuscript.version.repo: must be a public https URL")
|
|
343
|
+
if not (isinstance(v["commit"], str) and HEX40.match(v["commit"])):
|
|
344
|
+
errors.append("manuscript.version.commit: must be a full 40-hex commit")
|
|
345
|
+
if not (isinstance(v["sha256"], str) and HEX64.match(v["sha256"])):
|
|
346
|
+
errors.append("manuscript.version.sha256: must be the 64-hex SHA-256 of the manuscript file")
|
|
347
|
+
else:
|
|
348
|
+
errors.append("manuscript.version: must be a string or a mapping {repo, commit, sha256}")
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
def validate(doc, package: str | None = None, profiles: dict | None = None, placeholders: bool = True) -> list[str]:
|
|
352
|
+
"""Schema errors of a coverage/1 document (claim ids and receipts are checked by check_against).
|
|
353
|
+
profiles: the site profiles compute may name (sites.for_repo); None: the built-in ones. placeholders:
|
|
354
|
+
false leaves out the placeholder rule (placeholder_problems), which verify's preflight reports apart."""
|
|
355
|
+
errors: list[str] = []
|
|
356
|
+
if not isinstance(doc, dict):
|
|
357
|
+
_keys(doc, TOP_REQUIRED, TOP_OPTIONAL, "<root>", errors)
|
|
358
|
+
return errors
|
|
359
|
+
if "kind" in doc and doc["kind"] not in KINDS:
|
|
360
|
+
errors.append(f"kind: must be one of {', '.join(KINDS)}, got {doc['kind']!r}")
|
|
361
|
+
library = doc_kind(doc) == "library"
|
|
362
|
+
if library:
|
|
363
|
+
_library_keys(doc, errors)
|
|
364
|
+
else:
|
|
365
|
+
_keys(doc, TOP_REQUIRED, TOP_OPTIONAL, "<root>", errors)
|
|
366
|
+
_identity_errors(doc, package, errors)
|
|
367
|
+
if not library and "manuscript" in doc:
|
|
368
|
+
_manuscript_errors(doc["manuscript"], errors)
|
|
369
|
+
if "summary" in doc and not _text(doc["summary"]):
|
|
370
|
+
errors.append(f"summary: must be one line of at most {TEXT_MAX} characters")
|
|
371
|
+
if library:
|
|
372
|
+
_library_rows_errors(doc, errors)
|
|
373
|
+
else:
|
|
374
|
+
_paper_rows_errors(doc, errors)
|
|
375
|
+
_tail_errors(doc, errors, sites.builtin() if profiles is None else profiles, placeholders)
|
|
376
|
+
return errors
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
def _identity_errors(doc: dict, package: str | None, errors: list[str]) -> None:
|
|
380
|
+
if doc.get("schema") != COVERAGE_SCHEMA:
|
|
381
|
+
errors.append(f"schema: must be {COVERAGE_SCHEMA!r}, got {doc.get('schema')!r}")
|
|
382
|
+
if "package" in doc and not (isinstance(doc["package"], str) and doc["package"].strip()):
|
|
383
|
+
errors.append("package: must be the package name")
|
|
384
|
+
elif package and "package" in doc and doc["package"] != package:
|
|
385
|
+
errors.append(f"package: {doc['package']!r} is not {package!r}")
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
def placeholder_problems(doc) -> list[str]:
|
|
389
|
+
"""lean-scope-page R4: each string of the document that carries a placeholder marker."""
|
|
390
|
+
return [f"{where or '<root>'}: carries the placeholder {PLACEHOLDER_RE.search(s).group(0)!r}; "
|
|
391
|
+
f"write the text (a placeholder never reaches the page)"
|
|
392
|
+
for where, s in _strings(doc, "") if PLACEHOLDER_RE.search(s)]
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
def _tail_errors(doc: dict, errors: list[str], profiles: dict, placeholders: bool = True) -> None:
|
|
396
|
+
"""compute, placeholders (unless `placeholders` is false), lean_pkg_version and stack: the same for both
|
|
397
|
+
kinds."""
|
|
398
|
+
comp = doc.get("compute")
|
|
399
|
+
if "compute" in doc:
|
|
400
|
+
if not isinstance(comp, list) or not comp:
|
|
401
|
+
errors.append("compute: must be a non-empty list of {cluster, jobs}")
|
|
402
|
+
else:
|
|
403
|
+
seen = set()
|
|
404
|
+
for i, c in enumerate(comp):
|
|
405
|
+
w = f"compute[{i}]"
|
|
406
|
+
if not _keys(c, ("cluster", "jobs"), (), w, errors):
|
|
407
|
+
continue
|
|
408
|
+
if c["cluster"] not in profiles:
|
|
409
|
+
errors.append(f"{w}.cluster: must be one of {', '.join(profiles)}, got {c['cluster']!r}")
|
|
410
|
+
elif c["cluster"] in seen:
|
|
411
|
+
errors.append(f"{w}.cluster: {c['cluster']!r} is listed twice")
|
|
412
|
+
seen.add(c["cluster"])
|
|
413
|
+
# an unknown cluster is refused above; its jobs are still read as Slurm ids, as before
|
|
414
|
+
sched = sites.scheduler_of(profiles[c["cluster"]]) if c["cluster"] in profiles else sites.SLURM
|
|
415
|
+
jobs = c["jobs"]
|
|
416
|
+
if not isinstance(jobs, list) or not jobs or not all(
|
|
417
|
+
isinstance(j, str) and sched.job_re.match(j) for j in jobs):
|
|
418
|
+
errors.append(f"{w}.jobs: must be a non-empty list of {sched.label} job ids ({sched.example})")
|
|
419
|
+
elif len(set(jobs)) != len(jobs):
|
|
420
|
+
errors.append(f"{w}.jobs: repeats a job id")
|
|
421
|
+
if placeholders:
|
|
422
|
+
errors += placeholder_problems(doc)
|
|
423
|
+
lv = doc.get("lean_pkg_version")
|
|
424
|
+
if "lean_pkg_version" in doc and _keys(lv, ("version", "doi"), (), "lean_pkg_version", errors):
|
|
425
|
+
if not (isinstance(lv["version"], str) and VERSION_RE.match(lv["version"])):
|
|
426
|
+
errors.append("lean_pkg_version.version: must be a release version such as 0.7.52")
|
|
427
|
+
if not (isinstance(lv["doi"], str) and ZENODO_DOI_RE.match(lv["doi"])):
|
|
428
|
+
errors.append("lean_pkg_version.doi: must be a Zenodo version DOI (10.5281/zenodo.N)")
|
|
429
|
+
# the name's shape only: a stack declared by a newer lean-pkg is not an error here (doctor and verify say
|
|
430
|
+
# whether this lean-pkg declares it, and check the pins against it; it never fails a check)
|
|
431
|
+
if "stack" in doc and not (isinstance(doc["stack"], str) and STACK_NAME_RE.match(doc["stack"])):
|
|
432
|
+
errors.append(f"stack: must be an LTS stack name lts-YYYY.04 or lts-YYYY.10 (docs/stacks/), got "
|
|
433
|
+
f"{doc['stack']!r}")
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
def _paper_rows_errors(doc: dict, errors: list[str]) -> None:
|
|
437
|
+
"""The rows and nothing_excluded of a kind: paper document."""
|
|
438
|
+
rows = doc.get("rows")
|
|
439
|
+
numbers: dict[str, int] = {}
|
|
440
|
+
n_outside = 0
|
|
441
|
+
if "rows" in doc and (not isinstance(rows, list) or not rows):
|
|
442
|
+
errors.append("rows: must be a non-empty list")
|
|
443
|
+
rows = []
|
|
444
|
+
for i, r in enumerate(rows or []):
|
|
445
|
+
w = f"rows[{i}]"
|
|
446
|
+
if not _keys(r, ROW_REQUIRED, ROW_OPTIONAL, w, errors):
|
|
447
|
+
continue
|
|
448
|
+
p = r["paper"]
|
|
449
|
+
if _keys(p, PAPER_REQUIRED, PAPER_OPTIONAL, f"{w}.paper", errors):
|
|
450
|
+
for k in ("number", "title") + (("label",) if "label" in p else ()):
|
|
451
|
+
if not _text(p[k], 200):
|
|
452
|
+
errors.append(f"{w}.paper.{k}: must be a one-line string")
|
|
453
|
+
if "statement" in p:
|
|
454
|
+
_statement_errors(p["statement"], f"{w}.paper.statement", errors)
|
|
455
|
+
num = p.get("number")
|
|
456
|
+
if isinstance(num, str):
|
|
457
|
+
if num in numbers:
|
|
458
|
+
errors.append(f"{w}.paper.number: {num!r} repeats rows[{numbers[num]}]")
|
|
459
|
+
numbers.setdefault(num, i)
|
|
460
|
+
cls = r["class"]
|
|
461
|
+
if cls not in CLASSES:
|
|
462
|
+
errors.append(f"{w}.class: must be one of {', '.join(CLASSES)}, got {cls!r}")
|
|
463
|
+
continue
|
|
464
|
+
claims = _str_list(r.get("claims"), f"{w}.claims", errors)
|
|
465
|
+
inputs = _inputs_list(r.get("inputs"), f"{w}.inputs", errors)
|
|
466
|
+
if "note" in r and not _text(r["note"]):
|
|
467
|
+
errors.append(f"{w}.note: must be one line of at most {TEXT_MAX} characters")
|
|
468
|
+
if cls == "outside":
|
|
469
|
+
n_outside += 1
|
|
470
|
+
if claims:
|
|
471
|
+
errors.append(f"{w}: an outside row names no claims (a row with a Lean counterpart is "
|
|
472
|
+
f"same-assumptions or inputs-supplied)")
|
|
473
|
+
if inputs:
|
|
474
|
+
errors.append(f"{w}: an outside row has no inputs")
|
|
475
|
+
else:
|
|
476
|
+
if not claims:
|
|
477
|
+
errors.append(f"{w}: a {cls} row names at least one claim id (claims.yaml)")
|
|
478
|
+
if cls == "inputs-supplied" and not inputs:
|
|
479
|
+
errors.append(f"{w}: an inputs-supplied row names its inputs (the hypotheses the Lean "
|
|
480
|
+
f"statement takes that the paper proves or assumes elsewhere)")
|
|
481
|
+
if cls == "same-assumptions" and inputs:
|
|
482
|
+
errors.append(f"{w}: a same-assumptions row has no inputs (use inputs-supplied)")
|
|
483
|
+
ne = doc.get("nothing_excluded")
|
|
484
|
+
if "nothing_excluded" in doc:
|
|
485
|
+
if _keys(ne, ("reason",), (), "nothing_excluded", errors) and not _text(ne["reason"]):
|
|
486
|
+
errors.append("nothing_excluded.reason: must be one line saying why nothing is excluded")
|
|
487
|
+
if n_outside:
|
|
488
|
+
errors.append("nothing_excluded: contradicts the outside row(s); drop one or the other")
|
|
489
|
+
elif rows and not n_outside:
|
|
490
|
+
errors.append("rows: no outside row: list what is not formalized (class outside), or state "
|
|
491
|
+
"nothing_excluded: {reason: ...}")
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
def _library_keys(doc: dict, errors: list[str]) -> None:
|
|
495
|
+
"""The top-level keys of a kind: library document; a paper key is refused by name."""
|
|
496
|
+
for key, why in LIBRARY_NO_PAPER.items():
|
|
497
|
+
if key in doc:
|
|
498
|
+
errors.append(why)
|
|
499
|
+
_keys({k: v for k, v in doc.items() if k not in LIBRARY_NO_PAPER}, LIBRARY_TOP_REQUIRED,
|
|
500
|
+
LIBRARY_TOP_OPTIONAL, "<root>", errors)
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
def _library_rows_errors(doc: dict, errors: list[str]) -> None:
|
|
504
|
+
"""The rows of a kind: library document: one main result each, named by its claims."""
|
|
505
|
+
rows = doc.get("rows")
|
|
506
|
+
if "rows" in doc and (not isinstance(rows, list) or not rows):
|
|
507
|
+
errors.append("rows: must be a non-empty list")
|
|
508
|
+
return
|
|
509
|
+
titles: dict[str, int] = {}
|
|
510
|
+
for i, r in enumerate(rows or []):
|
|
511
|
+
w = f"rows[{i}]"
|
|
512
|
+
if isinstance(r, dict) and any(k in r for k in LIBRARY_ROW_NO_PAPER):
|
|
513
|
+
errors.append(f"{w}: a library row is a main result of the library (title, claims, note), not a "
|
|
514
|
+
f"paper result: drop {', '.join(k for k in LIBRARY_ROW_NO_PAPER if k in r)} (the Lean "
|
|
515
|
+
f"statement is the result; a library coverage has no manuscript to correspond to)")
|
|
516
|
+
r = {k: v for k, v in r.items() if k not in LIBRARY_ROW_NO_PAPER}
|
|
517
|
+
if not _keys(r, LIBRARY_ROW_REQUIRED, LIBRARY_ROW_OPTIONAL, w, errors):
|
|
518
|
+
continue
|
|
519
|
+
if not _text(r["title"], 200):
|
|
520
|
+
errors.append(f"{w}.title: must be a one-line string")
|
|
521
|
+
elif r["title"] in titles:
|
|
522
|
+
errors.append(f"{w}.title: {r['title']!r} repeats rows[{titles[r['title']]}]")
|
|
523
|
+
else:
|
|
524
|
+
titles[r["title"]] = i
|
|
525
|
+
if r["claims"] is None or r["claims"] == []:
|
|
526
|
+
errors.append(f"{w}: a library row names at least one claim id (claims.yaml)")
|
|
527
|
+
else:
|
|
528
|
+
_str_list(r["claims"], f"{w}.claims", errors)
|
|
529
|
+
if "note" in r and not _text(r["note"]):
|
|
530
|
+
errors.append(f"{w}.note: must be one line of at most {TEXT_MAX} characters")
|
|
531
|
+
if "statement" in r:
|
|
532
|
+
_statement_errors(r["statement"], f"{w}.statement", errors)
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
# --------------------------------------------------------------------------
|
|
536
|
+
# joins with the package: claims.yaml, receipts, lean-pkg's own CITATION.cff
|
|
537
|
+
|
|
538
|
+
def claims_at_head(pkg: dict, repo: pathlib.Path) -> tuple[dict[str, dict], str]:
|
|
539
|
+
"""{id: claim} from the claims file committed at HEAD, and its path; refuses when absent or invalid."""
|
|
540
|
+
from . import claims as claims_mod
|
|
541
|
+
rel = pkg.get("claims_file") or claims_mod.DEFAULT_CLAIMS_FILE
|
|
542
|
+
raw = core.git_show_bytes(repo, rel)
|
|
543
|
+
if raw is None:
|
|
544
|
+
raise core.Fail(f"{pkg['name']}: {rel} is not committed at HEAD; coverage rows name claim ids from it")
|
|
545
|
+
doc = claims_mod.load_claims_text(raw.decode("utf-8", errors="replace"), f"{rel} at HEAD")
|
|
546
|
+
errors = claims_mod.validate_claims(doc, pkg["name"])
|
|
547
|
+
if errors:
|
|
548
|
+
raise core.Fail(f"{rel} at HEAD is not a valid claims/1 file:\n " + "\n ".join(errors[:10]))
|
|
549
|
+
return {str(c.get("id")): c for c in doc.get("claims") or [] if isinstance(c, dict)}, rel
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
BUNDLE_SUFFIX = ".sigstore.json" # ci_github.BUNDLE_SUFFIX (a leaf constant here)
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
def tracked_receipts(repo: pathlib.Path) -> list[str]:
|
|
556
|
+
"""Receipt JSON files tracked at HEAD directly under .lean-receipts/ (package-relative, sorted). A Sigstore
|
|
557
|
+
bundle beside a GitHub Actions receipt (<c12>-gha-R-A.sigstore.json, the receipt's ci.attestation) is evidence
|
|
558
|
+
for the receipt, not a receipt, and is not listed."""
|
|
559
|
+
p = core.git(repo, "ls-tree", "-z", "--name-only", "HEAD", "--", ".lean-receipts/")
|
|
560
|
+
if p.returncode != 0:
|
|
561
|
+
return []
|
|
562
|
+
out = [x for x in p.stdout.split("\0") if x.endswith(".json") and not x.endswith(BUNDLE_SUFFIX)
|
|
563
|
+
and x.count("/") == 1]
|
|
564
|
+
return sorted(out)
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
def receipt_at_head(repo: pathlib.Path, rel: str) -> tuple[dict | None, bytes | None]:
|
|
568
|
+
raw = core.git_show_bytes(repo, rel)
|
|
569
|
+
if raw is None:
|
|
570
|
+
return None, None
|
|
571
|
+
try:
|
|
572
|
+
data = json.loads(raw)
|
|
573
|
+
except ValueError:
|
|
574
|
+
return None, raw
|
|
575
|
+
return (data if isinstance(data, dict) else None), raw
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
def slurm_job_of(rec: dict, repo: pathlib.Path | None = None) -> str | None:
|
|
579
|
+
"""The receipt's Slurm job as `slurm-<J>`, or None when the receipt does not show a Slurm run: a
|
|
580
|
+
lower-tier receipt whose job_id is `slurm-<J>` (what `receipt slurm` writes after sacct), or a comparator
|
|
581
|
+
receipt whose claim (job_id J, host_policy `Slurm job J ...`, from SLURM_JOB_ID, which any shell can set)
|
|
582
|
+
is corroborated by its sacct seal committed at HEAD of `repo` (receipt.sacct_seal_problem). Without
|
|
583
|
+
`repo`, or without a valid seal, a comparator receipt shows no Slurm run. Other job ids (systemd units,
|
|
584
|
+
local runs) carry host labels and are never copied."""
|
|
585
|
+
job = rec.get("job_id")
|
|
586
|
+
if isinstance(job, str) and SLURM_JOB_RE.match(job):
|
|
587
|
+
return job
|
|
588
|
+
if rec.get("schema") in core.COMPARATOR_SCHEMAS and repo is not None and unsealed_comparator_job(rec, repo) is None \
|
|
589
|
+
and receipt_mod().comparator_slurm_job(rec):
|
|
590
|
+
return f"slurm-{job}"
|
|
591
|
+
return None
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
def receipt_mod():
|
|
595
|
+
from . import receipt
|
|
596
|
+
return receipt
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
def unsealed_comparator_job(rec: dict, repo: pathlib.Path) -> str | None:
|
|
600
|
+
"""Why a comparator receipt's Slurm claim is not corroborated (receipt.sacct_seal_problem against the
|
|
601
|
+
seal file committed at HEAD), or None when it is; also a reason when it claims no Slurm job."""
|
|
602
|
+
return receipt_mod().committed_sacct_seal_problem(repo, rec)
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
def slurm_jobs_at_head(repo: pathlib.Path) -> dict[str, str]:
|
|
606
|
+
"""{slurm-<J>: receipt path} for every receipt tracked at HEAD that shows a Slurm run."""
|
|
607
|
+
out: dict[str, str] = {}
|
|
608
|
+
for rel in tracked_receipts(repo):
|
|
609
|
+
rec, _raw = receipt_at_head(repo, rel)
|
|
610
|
+
job = slurm_job_of(rec, repo) if rec else None
|
|
611
|
+
if job:
|
|
612
|
+
out.setdefault(job, rel)
|
|
613
|
+
return out
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
def unsealed_comparator_receipts(repo: pathlib.Path) -> dict[str, tuple[str, str]]:
|
|
617
|
+
"""{slurm-<J>: (receipt path, why)} for each comparator receipt tracked at HEAD that claims Slurm job J
|
|
618
|
+
but whose claim no sacct seal corroborates: a near miss to name in a refusal, never backing."""
|
|
619
|
+
out: dict[str, tuple[str, str]] = {}
|
|
620
|
+
for rel in tracked_receipts(repo):
|
|
621
|
+
rec, _raw = receipt_at_head(repo, rel)
|
|
622
|
+
if rec and rec.get("schema") in core.COMPARATOR_SCHEMAS and receipt_mod().comparator_slurm_job(rec):
|
|
623
|
+
why = unsealed_comparator_job(rec, repo)
|
|
624
|
+
if why:
|
|
625
|
+
out.setdefault(f"slurm-{rec['job_id']}", (rel, why))
|
|
626
|
+
return out
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
def bare_job_receipts(repo: pathlib.Path) -> dict[str, str]:
|
|
630
|
+
"""{slurm-<J>: receipt path} for each receipt tracked at HEAD whose job_id is the bare number J and that
|
|
631
|
+
slurm_job_of does not accept: a near miss to name in a refusal, never backing. A bare number says
|
|
632
|
+
nothing about where it ran (a process id is a number too); `receipt slurm` writes `slurm-<J>` only
|
|
633
|
+
after sacct shows the job COMPLETED."""
|
|
634
|
+
out: dict[str, str] = {}
|
|
635
|
+
for rel in tracked_receipts(repo):
|
|
636
|
+
rec, _raw = receipt_at_head(repo, rel)
|
|
637
|
+
job = rec.get("job_id") if rec else None
|
|
638
|
+
if isinstance(job, str) and re.fullmatch(r"\d+(?:_\d+)?", job) and not slurm_job_of(rec, repo) \
|
|
639
|
+
and rec.get("schema") not in core.COMPARATOR_SCHEMAS: # unsealed comparator: its own hint
|
|
640
|
+
out.setdefault(f"slurm-{job}", rel)
|
|
641
|
+
return out
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
def slurm_near_misses(repo: pathlib.Path, missing: list[str]) -> str:
|
|
645
|
+
"""The refusal's hint for listed Slurm jobs no receipt backs: a bare job number (`receipt slurm` writes
|
|
646
|
+
`slurm-<J>`), or a comparator receipt whose Slurm claim no sacct seal corroborates."""
|
|
647
|
+
near = bare_job_receipts(repo)
|
|
648
|
+
hint = "".join(
|
|
649
|
+
f"; {near[j]} has job_id {j.removeprefix('slurm-')!r}, a bare number, which is not accepted as a "
|
|
650
|
+
f"Slurm job: write the receipt with `lean-pkg receipt slurm --job {j.removeprefix('slurm-')}` "
|
|
651
|
+
f"(it checks sacct and writes job_id {j})" for j in missing if j in near)
|
|
652
|
+
unsealed = unsealed_comparator_receipts(repo)
|
|
653
|
+
hint += "".join(f"; {unsealed[j][0]} claims Slurm job {j.removeprefix('slurm-')} but does not back "
|
|
654
|
+
f"it: {unsealed[j][1]}" for j in missing if j in unsealed)
|
|
655
|
+
return hint
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
def _gha_jobs_at_head(repo: pathlib.Path) -> dict[str, str]:
|
|
659
|
+
from . import ci_github
|
|
660
|
+
return ci_github.jobs_at_head(repo)
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
def _gha_near_misses(repo: pathlib.Path, missing: list[str]) -> str:
|
|
664
|
+
from . import ci_github
|
|
665
|
+
return ci_github.near_misses(repo, missing)
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
# scheduler name -> {job id: receipt path} for the receipts tracked at HEAD that show a run under it
|
|
669
|
+
JOB_INDEX = {sites.SLURM.name: slurm_jobs_at_head, sites.GITHUB_ACTIONS.name: _gha_jobs_at_head}
|
|
670
|
+
# scheduler name -> the hint naming near misses (a receipt with the job's id that does not back it)
|
|
671
|
+
NEAR_MISSES = {sites.SLURM.name: slurm_near_misses, sites.GITHUB_ACTIONS.name: _gha_near_misses}
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
def compute_backing(doc: dict, repo: pathlib.Path, profiles: dict | None = None
|
|
675
|
+
) -> tuple[dict[str, list[str]], list[str]]:
|
|
676
|
+
"""({cluster: [backed job ids]}, problems): every listed job must be the job of a receipt tracked at HEAD,
|
|
677
|
+
of the scheduler the cluster's site profile names (sites.py)."""
|
|
678
|
+
profiles = sites.for_repo(repo) if profiles is None else profiles
|
|
679
|
+
index: dict[str, dict[str, str]] = {}
|
|
680
|
+
backed: dict[str, list[str]] = {}
|
|
681
|
+
problems: list[str] = []
|
|
682
|
+
for c in doc.get("compute") or []:
|
|
683
|
+
sched = sites.scheduler_of(profiles[c["cluster"]])
|
|
684
|
+
if sched.name not in index:
|
|
685
|
+
index[sched.name] = JOB_INDEX[sched.name](repo)
|
|
686
|
+
jobs = index[sched.name]
|
|
687
|
+
missing = [j for j in c["jobs"] if j not in jobs]
|
|
688
|
+
if missing:
|
|
689
|
+
hint = NEAR_MISSES[sched.name](repo, missing) # each scheduler names its own near misses
|
|
690
|
+
problems.append(f"compute ({c['cluster']}): no {sched.label} receipt tracked at HEAD under .lean-receipts/ "
|
|
691
|
+
f"has job_id {', '.join(missing)} (commit the receipt, or drop the job){hint}")
|
|
692
|
+
else:
|
|
693
|
+
backed[c["cluster"]] = list(c["jobs"])
|
|
694
|
+
return backed, problems
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+
def own_citation() -> dict | None:
|
|
698
|
+
"""lean-pkg's own CITATION.cff (a source checkout only; an installed wheel has none), parsed."""
|
|
699
|
+
p = pathlib.Path(__file__).resolve().parents[2] / "CITATION.cff"
|
|
700
|
+
try:
|
|
701
|
+
data = yaml.safe_load(p.read_text())
|
|
702
|
+
except (OSError, yaml.YAMLError):
|
|
703
|
+
return None
|
|
704
|
+
return data if isinstance(data, dict) else None
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
def own_version_dois(cff: dict | None) -> dict[str, str]:
|
|
708
|
+
"""{version: version DOI} from lean-pkg's CITATION.cff identifiers ("Version DOI for X.Y.Z")."""
|
|
709
|
+
out: dict[str, str] = {}
|
|
710
|
+
for ident in (cff or {}).get("identifiers") or []:
|
|
711
|
+
if isinstance(ident, dict):
|
|
712
|
+
m = re.fullmatch(r"Version DOI for (\d+\.\d+\.\d+)", str(ident.get("description") or ""))
|
|
713
|
+
if m and ident.get("value"):
|
|
714
|
+
out[m.group(1)] = str(ident["value"])
|
|
715
|
+
return out
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
def version_doi_problems(doc: dict, cff: dict | None = None) -> tuple[list[str], list[str]]:
|
|
719
|
+
"""(problems, warnings) for lean_pkg_version: when lean-pkg's own CITATION.cff is readable it must
|
|
720
|
+
list that version with exactly that DOI (a version DOI is never guessed)."""
|
|
721
|
+
lv = doc.get("lean_pkg_version")
|
|
722
|
+
if not lv:
|
|
723
|
+
return [], []
|
|
724
|
+
cff = own_citation() if cff is None else cff
|
|
725
|
+
if cff is None:
|
|
726
|
+
return [], ["lean_pkg_version: lean-pkg's own CITATION.cff is not readable here (an installed copy); "
|
|
727
|
+
"the version DOI is used as written"]
|
|
728
|
+
known = own_version_dois(cff)
|
|
729
|
+
if lv["version"] not in known:
|
|
730
|
+
return [f"lean_pkg_version: lean-pkg's CITATION.cff lists no version DOI for {lv['version']} "
|
|
731
|
+
f"(omit the key, or name a version that has one)"], []
|
|
732
|
+
if known[lv["version"]] != lv["doi"]:
|
|
733
|
+
return [f"lean_pkg_version: lean-pkg's CITATION.cff gives {known[lv['version']]} for "
|
|
734
|
+
f"{lv['version']}, not {lv['doi']}"], []
|
|
735
|
+
return [], []
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
def claim_id_problems(doc: dict, claims: dict[str, dict], where: str) -> list[str]:
|
|
739
|
+
"""Each claim id a row names is a claim of `claims` (read from `where`) and is not superseded."""
|
|
740
|
+
errors: list[str] = []
|
|
741
|
+
for i, r in enumerate(doc["rows"]):
|
|
742
|
+
for cid in r.get("claims") or []:
|
|
743
|
+
c = claims.get(cid)
|
|
744
|
+
if c is None:
|
|
745
|
+
errors.append(f"rows[{i}].claims: {cid!r} is not a claim id in {where}")
|
|
746
|
+
elif c.get("status") == "superseded":
|
|
747
|
+
errors.append(f"rows[{i}].claims: {cid!r} is superseded (by {c.get('superseded_by')!r}); "
|
|
748
|
+
f"name its successor")
|
|
749
|
+
return errors
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
def check_against(doc: dict, claims: dict[str, dict], claims_rel: str, repo: pathlib.Path | None
|
|
753
|
+
) -> tuple[list[str], list[str]]:
|
|
754
|
+
"""(errors, warnings) of a schema-valid document against the package: claim ids, receipts, versions."""
|
|
755
|
+
errors = claim_id_problems(doc, claims, f"{claims_rel} at HEAD")
|
|
756
|
+
errors += input_hypothesis_problems(doc, claims, f"{claims_rel} at HEAD")
|
|
757
|
+
warnings: list[str] = []
|
|
758
|
+
if repo is not None:
|
|
759
|
+
_backed, problems = compute_backing(doc, repo)
|
|
760
|
+
errors += problems
|
|
761
|
+
from .anchor import baseline_problems
|
|
762
|
+
e, w = baseline_problems(doc, repo)
|
|
763
|
+
errors, warnings = errors + e, warnings + w
|
|
764
|
+
p, w = version_doi_problems(doc)
|
|
765
|
+
return errors + p, warnings + w
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
def theorem_mapping_problems(doc: dict, claims: dict[str, dict], configs: list[dict], smoke, read_file,
|
|
769
|
+
source: str) -> list[str]:
|
|
770
|
+
"""R10/R11: every theorem of `configs` ({path, theorem_names} each) is the declaration of a claim some row
|
|
771
|
+
names, unless its configuration is a declared smoke check (its path in `smoke`), whose theorems must then
|
|
772
|
+
name no claim a row names. `read_file(rel)` reads the claims' Lean files (a decl counts only when its file
|
|
773
|
+
declares it: comparator_config.qualified_decls); `source` says where the configurations came from."""
|
|
774
|
+
from . import comparator_config as cc
|
|
775
|
+
errors: list[str] = []
|
|
776
|
+
named = [(i, cid) for i, r in enumerate(doc["rows"]) for cid in r.get("claims") or [] if cid in claims]
|
|
777
|
+
row_claims = [claims[cid] for _i, cid in named]
|
|
778
|
+
qualified = cc.qualified_decls(read_file, row_claims)
|
|
779
|
+
decls = [(str(c.get("decl") or ""), str(c.get("decl") or "") in qualified) for c in row_claims]
|
|
780
|
+
mapped = cc.mapped_names(list(claims.values())) # a judged_as name judges its own claim only (#CM)
|
|
781
|
+
for c in configs:
|
|
782
|
+
where = c.get("path") or "?"
|
|
783
|
+
if where in smoke: # a declared smoke check: accounted for as such
|
|
784
|
+
for t in c.get("theorem_names") or []:
|
|
785
|
+
hit = [cid for (_i, cid), rc in zip(named, row_claims, strict=False)
|
|
786
|
+
if isinstance(t, str) and cc.claim_covered({t}, rc, qualified, mapped)]
|
|
787
|
+
if hit:
|
|
788
|
+
errors.append(f"comparator theorem {t!r} ({where}) is in a configuration {SIDECAR} "
|
|
789
|
+
f"marks as a smoke check, but it is the declaration of claim {hit[0]!r}, which a "
|
|
790
|
+
f"row names: a smoke check verifies no result, so move the theorem to a "
|
|
791
|
+
f"configuration of its own, or drop the smoke mark")
|
|
792
|
+
continue
|
|
793
|
+
for t in c.get("theorem_names") or []:
|
|
794
|
+
if isinstance(t, str) and not any(cc.claim_covered({t}, rc, qualified, mapped) for rc in row_claims):
|
|
795
|
+
near = cc.name_hints([t], decls) # #6: a root-namespace near miss, named, never credited
|
|
796
|
+
errors.append(f"comparator theorem {t!r} ({where}, {source}) is the declaration "
|
|
797
|
+
f"of no claim a row names: map it to its paper result (a row's claims), or drop it "
|
|
798
|
+
f"from the configuration" + (f"; hint: {near[0]['hint']}" if near else ""))
|
|
799
|
+
return errors
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
def scope_problems(pkg: dict, doc: dict, claims: dict[str, dict], repo: pathlib.Path) -> list[str]:
|
|
803
|
+
"""The lab's lean-scope-page rules that apply to a rendered page (docs/page.md#from-lean-scope-page):
|
|
804
|
+
R8/R9, every claim a row names has its `file` committed at HEAD (the page links the declaration
|
|
805
|
+
there); R10/R11, every theorem the recorded comparator receipt compares is the declaration of a claim
|
|
806
|
+
some row names (the page says how many theorems were compared, so each must be accounted for), unless
|
|
807
|
+
its configuration is a declared smoke check (lean-pkg-signoff.json `smoke`, at the receipt's commit or
|
|
808
|
+
HEAD), which the page shows as such and whose theorems must then name no claim a row names;
|
|
809
|
+
R12, every comparator configuration with definition holes carries a sign-off reviewer (the page names
|
|
810
|
+
who judged the bodies): the receipt's `signoff` copy of lean-pkg-signoff.json, else its deprecated
|
|
811
|
+
`judged_as` copy (holes.receipt_judged)."""
|
|
812
|
+
from .holes import receipt_judged
|
|
813
|
+
from . import claims as claims_mod
|
|
814
|
+
from . import comparator_config as cc
|
|
815
|
+
errors: list[str] = []
|
|
816
|
+
named = [(i, cid) for i, r in enumerate(doc["rows"]) for cid in r.get("claims") or [] if cid in claims]
|
|
817
|
+
for i, cid in named:
|
|
818
|
+
rel = claims[cid].get("file")
|
|
819
|
+
if rel and not core.tracked_at(repo, str(rel)):
|
|
820
|
+
errors.append(f"rows[{i}].claims: {cid!r} names file {rel!r}, which is not committed at HEAD "
|
|
821
|
+
f"(the page links the declaration there)")
|
|
822
|
+
rel = (pkg.get("gate") or {}).get("comparator")
|
|
823
|
+
comp, _raw = receipt_at_head(repo, rel) if rel else (None, None)
|
|
824
|
+
configs = [c for c in (comp or {}).get("configs") or [] if isinstance(c, dict)]
|
|
825
|
+
if not configs:
|
|
826
|
+
return errors
|
|
827
|
+
smoke = cc.smoke_configs(repo, str(comp.get("commit") or "") if core._HEX40.fullmatch(
|
|
828
|
+
str(comp.get("commit") or "")) else None, "HEAD")
|
|
829
|
+
errors += theorem_mapping_problems(doc, claims, configs, smoke, claims_mod._reader(repo, "HEAD"),
|
|
830
|
+
"recorded comparator receipt")
|
|
831
|
+
for c in configs:
|
|
832
|
+
where = c.get("path") or "?"
|
|
833
|
+
if where in smoke:
|
|
834
|
+
continue
|
|
835
|
+
judged = receipt_judged(c)
|
|
836
|
+
if c.get("definition_names") and not str(judged.get("reviewer") or "").strip():
|
|
837
|
+
errors.append(f"comparator configuration {where} (recorded comparator receipt) has definition holes "
|
|
838
|
+
f"{', '.join(map(str, c['definition_names']))} without a sign-off reviewer (signoff, from "
|
|
839
|
+
f"lean-pkg-signoff.json; or the deprecated judged_as.reviewer): comparator never compares "
|
|
840
|
+
f"a hole's body, so the page must name the human who did")
|
|
841
|
+
return errors
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
def read_doc(pkg: dict, repo: pathlib.Path, file: str | None = None) -> tuple[dict, str]:
|
|
845
|
+
"""(document, where): --file PATH from disk, else coverage.yaml committed at HEAD."""
|
|
846
|
+
if file is not None:
|
|
847
|
+
path = pathlib.Path(file)
|
|
848
|
+
if not path.is_file():
|
|
849
|
+
raise core.Fail(f"{file}: no such file")
|
|
850
|
+
return load_text(path.read_text(encoding="utf-8", errors="replace"), file), file
|
|
851
|
+
raw = core.git_show_bytes(repo, DEFAULT_COVERAGE_FILE)
|
|
852
|
+
if raw is None:
|
|
853
|
+
raise core.Fail(f"{pkg['name']}: {DEFAULT_COVERAGE_FILE} is not committed at HEAD (write one: "
|
|
854
|
+
f"docs/page.md#coverageyaml, then commit it)")
|
|
855
|
+
where = f"{DEFAULT_COVERAGE_FILE} at HEAD"
|
|
856
|
+
return load_text(raw.decode("utf-8", errors="replace"), where), where
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
def load_checked(pkg: dict, repo: pathlib.Path, file: str | None = None, allow_private: bool = False
|
|
860
|
+
) -> tuple[dict, dict[str, dict], list[str]]:
|
|
861
|
+
"""(document, claims by id, warnings) of a fully valid coverage file; any problem refuses."""
|
|
862
|
+
doc, where = read_doc(pkg, repo, file)
|
|
863
|
+
errors = validate(doc, pkg["name"], sites.for_repo(repo))
|
|
864
|
+
if errors:
|
|
865
|
+
raise core.Fail(f"{where} is not a valid {COVERAGE_SCHEMA} file:\n " + "\n ".join(errors))
|
|
866
|
+
claims, claims_rel = claims_at_head(pkg, repo)
|
|
867
|
+
errors, warnings = check_against(doc, claims, claims_rel, repo)
|
|
868
|
+
errors += scope_problems(pkg, doc, claims, repo)
|
|
869
|
+
if doc_kind(doc) == "paper" and manuscript_kind(doc["manuscript"]["version"]) == "unposted" \
|
|
870
|
+
and not allow_private:
|
|
871
|
+
errors.append("manuscript.version: unposted: theorem numbers of a private draft are not checkable by a "
|
|
872
|
+
"reader; pin a posted version (arXiv:IDvN or {repo, commit, sha256}), or pass "
|
|
873
|
+
"--allow-private-manuscript (the output is then marked)")
|
|
874
|
+
if errors:
|
|
875
|
+
raise core.Fail(f"{where}: {len(errors)} problem(s):\n " + "\n ".join(errors))
|
|
876
|
+
return doc, claims, warnings
|
|
877
|
+
|
|
878
|
+
|
|
879
|
+
# --------------------------------------------------------------------------
|
|
880
|
+
# the offline check (#328): no registry record, no receipt
|
|
881
|
+
|
|
882
|
+
# the checks of the registered mode that need the registry record, the checkout at HEAD or a receipt
|
|
883
|
+
OFFLINE_SKIPPED = (
|
|
884
|
+
("compute receipts", "each compute job is a receipt committed under .lean-receipts/: needs the receipts at "
|
|
885
|
+
"HEAD"),
|
|
886
|
+
("claim files at HEAD", "each named claim's file is committed at HEAD (R8/R9): needs the package checkout"),
|
|
887
|
+
("definition sign-off", "each comparator configuration with definition holes names a sign-off reviewer "
|
|
888
|
+
"(R12): needs the recorded comparator receipt"),
|
|
889
|
+
("e-print baseline", "manuscript.eprint_sha256 against the source-baseline record committed at HEAD: needs "
|
|
890
|
+
"the package checkout"),
|
|
891
|
+
)
|
|
892
|
+
UNPOSTED_PROBLEM = ("manuscript.version: unposted: theorem numbers of a private draft are not checkable by a "
|
|
893
|
+
"reader; pin a posted version (arXiv:IDvN or {repo, commit, sha256}), or pass "
|
|
894
|
+
"--allow-private-manuscript (the output is then marked)")
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
def offline_check(text: str, where: str, *, claims_text: str | None = None, claims_where: str = "claims.yaml",
|
|
898
|
+
configs: dict[str, bytes] | None = None, sidecar: dict | None = None, read_file=None,
|
|
899
|
+
profiles: dict | None = None, allow_private: bool = False, draft: bool = False) -> dict:
|
|
900
|
+
"""Every check of `coverage check` that needs no registry record and no receipt, on the coverage file's
|
|
901
|
+
text: the coverage/1 schema and its length limits, the manuscript version, lean_pkg_version; with the
|
|
902
|
+
claims file's text, its claims/1 schema, each row's claim ids (present, not superseded) and a warning for
|
|
903
|
+
each reusable claim no row names; with comparator configurations ({path: bytes}), R10/R11 (each theorem
|
|
904
|
+
the declaration of a claim a row names; `sidecar` marks smoke configurations; `read_file(rel)` reads the
|
|
905
|
+
claims' Lean files, skipped when one is unreadable). draft (verify's preflight): placeholder text and an
|
|
906
|
+
unposted manuscript are warnings, not problems (`coverage check` and `page` still refuse them).
|
|
907
|
+
{doc, errors, warnings, checks[{check, status pass|fail|warn|skipped, detail}], skipped[]}."""
|
|
908
|
+
from . import claims as claims_mod
|
|
909
|
+
out: dict = {"doc": None, "errors": [], "warnings": [], "checks": [], "skipped": []}
|
|
910
|
+
|
|
911
|
+
def _add(check: str, status: str, detail: str, problems=(), warnings=()) -> None:
|
|
912
|
+
out["checks"].append({"check": check, "status": status, "detail": detail})
|
|
913
|
+
out["errors"].extend(problems)
|
|
914
|
+
out["warnings"].extend(warnings)
|
|
915
|
+
if status == "skipped":
|
|
916
|
+
out["skipped"].append(check)
|
|
917
|
+
|
|
918
|
+
# the claims file first: its package is the one the coverage file must name
|
|
919
|
+
claims: dict[str, dict] | None = None
|
|
920
|
+
claims_pkg = None
|
|
921
|
+
claims_entry = None
|
|
922
|
+
if claims_text is None:
|
|
923
|
+
claims_entry = ("claims file", "skipped", "no claims file given (--claims PATH)", [])
|
|
924
|
+
else:
|
|
925
|
+
try:
|
|
926
|
+
cdoc = claims_mod.load_claims_text(claims_text, claims_where)
|
|
927
|
+
cerr = [f"{claims_where}: {e}" for e in claims_mod.validate_claims(cdoc, None)]
|
|
928
|
+
except core.Fail as e:
|
|
929
|
+
cdoc, cerr = None, [str(e)]
|
|
930
|
+
if cerr:
|
|
931
|
+
claims_entry = ("claims file", "fail", f"{claims_where} is not a valid claims/1 file", cerr)
|
|
932
|
+
else:
|
|
933
|
+
claims = {str(c.get("id")): c for c in cdoc.get("claims") or [] if isinstance(c, dict)}
|
|
934
|
+
claims_pkg = cdoc.get("package") if isinstance(cdoc.get("package"), str) else None
|
|
935
|
+
claims_entry = ("claims file", "pass", f"{claims_where}: claims/1 schema ok ({len(claims)} claim(s))", [])
|
|
936
|
+
try:
|
|
937
|
+
doc = load_text(text, where)
|
|
938
|
+
except core.Fail as e:
|
|
939
|
+
doc = None
|
|
940
|
+
_add("schema", "fail", f"{where} does not load", [str(e)])
|
|
941
|
+
valid = False
|
|
942
|
+
if doc is not None:
|
|
943
|
+
errs = validate(doc, claims_pkg, profiles, placeholders=not draft)
|
|
944
|
+
held = placeholder_problems(doc) if draft else []
|
|
945
|
+
_add("schema", "fail" if errs else ("warn" if held else "pass"),
|
|
946
|
+
f"{COVERAGE_SCHEMA} schema and length limits" + (f" ({len(errs)} problem(s))" if errs else ""),
|
|
947
|
+
errs, held)
|
|
948
|
+
valid = not errs
|
|
949
|
+
out["doc"] = doc if valid else None
|
|
950
|
+
why_not = f"{where} is not a valid {COVERAGE_SCHEMA} file"
|
|
951
|
+
if not valid:
|
|
952
|
+
_add("manuscript", "skipped", why_not)
|
|
953
|
+
elif doc_kind(doc) == "library":
|
|
954
|
+
_add("manuscript", "pass", "kind library: no manuscript")
|
|
955
|
+
else:
|
|
956
|
+
kind = manuscript_kind(doc["manuscript"]["version"])
|
|
957
|
+
if kind == "unposted" and not allow_private:
|
|
958
|
+
if draft:
|
|
959
|
+
_add("manuscript", "warn", "manuscript unposted", (), [UNPOSTED_PROBLEM])
|
|
960
|
+
else:
|
|
961
|
+
_add("manuscript", "fail", "manuscript unposted", [UNPOSTED_PROBLEM])
|
|
962
|
+
else:
|
|
963
|
+
_add("manuscript", "pass", f"manuscript {kind}"
|
|
964
|
+
+ (" (PRIVATE DRAFT, --allow-private-manuscript)" if kind == "unposted" else ""))
|
|
965
|
+
if not valid:
|
|
966
|
+
_add("lean_pkg_version", "skipped", why_not)
|
|
967
|
+
elif "lean_pkg_version" not in doc:
|
|
968
|
+
_add("lean_pkg_version", "pass", "not set")
|
|
969
|
+
else:
|
|
970
|
+
p, w = version_doi_problems(doc)
|
|
971
|
+
_add("lean_pkg_version", "fail" if p else "pass", f"lean-pkg {doc['lean_pkg_version']['version']}", p, w)
|
|
972
|
+
_add(*claims_entry)
|
|
973
|
+
if claims is None or not valid:
|
|
974
|
+
why = why_not if not valid else ("no claims file given (--claims PATH)" if claims_text is None
|
|
975
|
+
else f"{claims_where} is not a valid claims/1 file")
|
|
976
|
+
_add("claim ids", "skipped", why)
|
|
977
|
+
if valid and any(isinstance(x, dict) for r in doc["rows"] for x in r.get("inputs") or []):
|
|
978
|
+
_add("input hypotheses", "skipped", why)
|
|
979
|
+
_add("reusable claims", "skipped", why)
|
|
980
|
+
else:
|
|
981
|
+
p = claim_id_problems(doc, claims, claims_where)
|
|
982
|
+
_add("claim ids", "fail" if p else "pass", f"each row's claim ids are claims of {claims_where}", p)
|
|
983
|
+
if any(isinstance(x, dict) for r in doc["rows"] for x in r.get("inputs") or []):
|
|
984
|
+
p = input_hypothesis_problems(doc, claims, claims_where) # only when an input names a hypothesis
|
|
985
|
+
_add("input hypotheses", "fail" if p else "pass",
|
|
986
|
+
"each {hypothesis, text} input is a hypothesis of a claim its row names", p)
|
|
987
|
+
named = {cid for r in doc["rows"] for cid in r.get("claims") or []}
|
|
988
|
+
unnamed = [cid for cid, c in claims.items() if c.get("status") == "reusable" and cid not in named]
|
|
989
|
+
if unnamed:
|
|
990
|
+
_add("reusable claims", "warn", f"{len(unnamed)} reusable claim(s) named by no row", (),
|
|
991
|
+
[f"{len(unnamed)} reusable claim(s) of {claims_where} named by no row: "
|
|
992
|
+
+ ", ".join(unnamed[:10]) + (f" (+{len(unnamed) - 10} more)" if len(unnamed) > 10 else "")
|
|
993
|
+
+ " (the page shows only what a row names: add each to the row of the result it formalizes)"])
|
|
994
|
+
else:
|
|
995
|
+
_add("reusable claims", "pass", "every reusable claim is named by a row")
|
|
996
|
+
_offline_comparator(_add, doc if valid else None, claims, configs, sidecar, read_file,
|
|
997
|
+
why_not if not valid else None, claims_text is None)
|
|
998
|
+
for check, why in OFFLINE_SKIPPED:
|
|
999
|
+
_add(check, "skipped", why)
|
|
1000
|
+
return out
|
|
1001
|
+
|
|
1002
|
+
|
|
1003
|
+
def _offline_comparator(_add, doc, claims, configs, sidecar, read_file, invalid: str | None,
|
|
1004
|
+
no_claims: bool) -> None:
|
|
1005
|
+
"""The R10/R11 entry of offline_check."""
|
|
1006
|
+
from . import holes
|
|
1007
|
+
check = "comparator theorems"
|
|
1008
|
+
if configs is None:
|
|
1009
|
+
_add(check, "skipped", "no comparator configuration given (--comparator PATH)")
|
|
1010
|
+
return
|
|
1011
|
+
parsed, problems = [], []
|
|
1012
|
+
for path, blob in configs.items():
|
|
1013
|
+
try:
|
|
1014
|
+
cfg = json.loads(blob or b"")
|
|
1015
|
+
except ValueError as e:
|
|
1016
|
+
problems.append(f"{path}: not valid JSON ({e})")
|
|
1017
|
+
continue
|
|
1018
|
+
names = cfg.get("theorem_names", []) if isinstance(cfg, dict) else None
|
|
1019
|
+
if not isinstance(names, list) or not all(isinstance(n, str) for n in names):
|
|
1020
|
+
problems.append(f"{path}: not a JSON object whose theorem_names is a list of strings")
|
|
1021
|
+
continue
|
|
1022
|
+
parsed.append({"path": path, "theorem_names": names})
|
|
1023
|
+
if problems:
|
|
1024
|
+
_add(check, "fail", "a comparator configuration does not load", problems)
|
|
1025
|
+
return
|
|
1026
|
+
if invalid or claims is None:
|
|
1027
|
+
_add(check, "skipped", invalid or ("no claims file given (--claims PATH)" if no_claims
|
|
1028
|
+
else "the claims file is not a valid claims/1 file"))
|
|
1029
|
+
return
|
|
1030
|
+
files = sorted({str(claims[cid].get("file") or "") for r in doc["rows"] for cid in r.get("claims") or []
|
|
1031
|
+
if cid in claims})
|
|
1032
|
+
unreadable = [f for f in files if not f or read_file is None or read_file(f) is None]
|
|
1033
|
+
if unreadable:
|
|
1034
|
+
_add(check, "skipped", "the Lean file(s) of the named claims are not readable here ("
|
|
1035
|
+
+ ", ".join(unreadable[:5]) + "): a decl counts only when its file declares it")
|
|
1036
|
+
return
|
|
1037
|
+
p = theorem_mapping_problems(doc, claims, parsed, holes.smoke_paths(sidecar), read_file,
|
|
1038
|
+
"comparator configuration")
|
|
1039
|
+
n = sum(len(c["theorem_names"]) for c in parsed)
|
|
1040
|
+
_add(check, "fail" if p else "pass", f"each of {n} theorem(s) in {len(parsed)} configuration(s) is the "
|
|
1041
|
+
f"declaration of a claim a row names (R11)", p)
|
|
1042
|
+
|
|
1043
|
+
|
|
1044
|
+
def _offline_reader(root: pathlib.Path):
|
|
1045
|
+
"""read(rel) -> text of root/rel, or None: a package-relative path only (no absolute path, no ..)."""
|
|
1046
|
+
def read(rel: str) -> str | None:
|
|
1047
|
+
pp = pathlib.PurePosixPath(str(rel))
|
|
1048
|
+
if pp.is_absolute() or ".." in pp.parts:
|
|
1049
|
+
return None
|
|
1050
|
+
p = root / pp
|
|
1051
|
+
return p.read_text(encoding="utf-8", errors="replace") if p.is_file() else None
|
|
1052
|
+
return read
|
|
1053
|
+
|
|
1054
|
+
|
|
1055
|
+
def offline_payload(rep: dict, name, file: str, claims_file, comparator: list[str]) -> dict:
|
|
1056
|
+
doc = rep["doc"]
|
|
1057
|
+
kind = doc_kind(doc) if doc else None
|
|
1058
|
+
counts = {c: sum(r["class"] == c for r in doc["rows"]) for c in CLASSES} if kind == "paper" else None
|
|
1059
|
+
mkind = manuscript_kind(doc["manuscript"]["version"]) if kind == "paper" else None
|
|
1060
|
+
return {"ok": not rep["errors"], "name": name, "file": file, "kind": kind,
|
|
1061
|
+
"rows": len(doc["rows"]) if doc else None, "counts": counts, "manuscript": mkind,
|
|
1062
|
+
"private_manuscript": (mkind == "unposted") if doc else None, "errors": rep["errors"],
|
|
1063
|
+
"warnings": rep["warnings"], "offline": True, "claims_file": claims_file, "comparator": comparator,
|
|
1064
|
+
"checks": rep["checks"], "skipped": rep["skipped"]}
|
|
1065
|
+
|
|
1066
|
+
|
|
1067
|
+
def offline_lines(rep: dict, payload: dict, where: str) -> list[str]:
|
|
1068
|
+
"""Verdict first and last (AGENTS.md "Verdict first"), then the problems, warnings and every check."""
|
|
1069
|
+
n_skip = len(rep["skipped"])
|
|
1070
|
+
if rep["errors"]:
|
|
1071
|
+
verdict = f"{where}: coverage: INVALID ({len(rep['errors'])} problem(s); offline, {n_skip} check(s) skipped)"
|
|
1072
|
+
else:
|
|
1073
|
+
doc = rep["doc"]
|
|
1074
|
+
what = (f"library; {len(doc['rows'])} main result(s)" if payload["kind"] == "library" else
|
|
1075
|
+
f"{len(doc['rows'])} row(s): " + ", ".join(f"{n} {c}" for c, n in payload["counts"].items())
|
|
1076
|
+
+ f"; manuscript {payload['manuscript']}")
|
|
1077
|
+
verdict = f"{where}: coverage: OK; {what}; offline, {n_skip} check(s) skipped"
|
|
1078
|
+
lines = [verdict] + [f" {e}" for e in rep["errors"]] + [f" warning: {w}" for w in rep["warnings"]]
|
|
1079
|
+
lines += [f" {c['status']}: {c['check']}: {c['detail']}" for c in rep["checks"]]
|
|
1080
|
+
if n_skip:
|
|
1081
|
+
lines.append(" the skipped checks need the registry record, the checkout at HEAD or a receipt: "
|
|
1082
|
+
"`lean-pkg coverage check NAME` runs them once the package is registered and committed")
|
|
1083
|
+
return lines + [verdict]
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
def do_coverage_check_file(file: str, claims_path: str | None, comparator_paths: list[str] | None,
|
|
1087
|
+
allow_private: bool) -> tuple[list[str], dict, int]:
|
|
1088
|
+
"""`coverage check --file PATH` without NAME: the offline check (offline_check) on working-copy files;
|
|
1089
|
+
reads no registry. The Lean files, lean-pkg-signoff.json and the site profiles are read from the coverage
|
|
1090
|
+
file's directory (the package directory)."""
|
|
1091
|
+
p = pathlib.Path(str(file)).expanduser()
|
|
1092
|
+
if not p.is_file():
|
|
1093
|
+
payload = {"ok": False, "name": None, "file": str(p), "kind": None, "rows": None, "counts": None,
|
|
1094
|
+
"manuscript": None, "private_manuscript": None, "errors": [f"{p}: no such file"],
|
|
1095
|
+
"warnings": [], "offline": True, "claims_file": claims_path, "comparator": comparator_paths or [],
|
|
1096
|
+
"checks": [], "skipped": []}
|
|
1097
|
+
verdict = f"{p}: coverage: INVALID (1 problem(s); offline)"
|
|
1098
|
+
return [verdict, f" {p}: no such file", verdict], payload, 1
|
|
1099
|
+
root = p.resolve().parent
|
|
1100
|
+
claims_text = None
|
|
1101
|
+
if claims_path is not None:
|
|
1102
|
+
cp = pathlib.Path(str(claims_path)).expanduser()
|
|
1103
|
+
if not cp.is_file():
|
|
1104
|
+
raise core.Fail(f"claims file not found: {cp}")
|
|
1105
|
+
claims_text = cp.read_text(encoding="utf-8", errors="replace")
|
|
1106
|
+
configs = None
|
|
1107
|
+
if comparator_paths:
|
|
1108
|
+
configs = {}
|
|
1109
|
+
for c in comparator_paths:
|
|
1110
|
+
cp = pathlib.Path(str(c)).expanduser()
|
|
1111
|
+
if not cp.is_file():
|
|
1112
|
+
raise core.Fail(f"comparator configuration not found: {cp}")
|
|
1113
|
+
try:
|
|
1114
|
+
key = cp.resolve().relative_to(root).as_posix()
|
|
1115
|
+
except ValueError:
|
|
1116
|
+
key = str(c)
|
|
1117
|
+
configs[key] = cp.read_bytes()
|
|
1118
|
+
side = root / SIDECAR
|
|
1119
|
+
try:
|
|
1120
|
+
sidecar = cli.parse_sidecar(side.read_bytes() if side.is_file() else None, str(side))
|
|
1121
|
+
except ValueError as e:
|
|
1122
|
+
raise core.Fail(str(e)) from e
|
|
1123
|
+
rep = offline_check(p.read_text(encoding="utf-8", errors="replace"), str(p), claims_text=claims_text,
|
|
1124
|
+
claims_where=str(claims_path) if claims_path else "claims.yaml", configs=configs,
|
|
1125
|
+
sidecar=sidecar, read_file=_offline_reader(root), profiles=sites.for_repo(root),
|
|
1126
|
+
allow_private=allow_private)
|
|
1127
|
+
doc = rep["doc"]
|
|
1128
|
+
name = doc.get("package") if doc else None
|
|
1129
|
+
payload = offline_payload(rep, name, str(p), claims_path, list(comparator_paths or []))
|
|
1130
|
+
return offline_lines(rep, payload, str(p)), payload, (1 if rep["errors"] else 0)
|
|
1131
|
+
|
|
1132
|
+
|
|
1133
|
+
def preflight_at_head(name: str, pkg: dict, repo: pathlib.Path) -> dict:
|
|
1134
|
+
"""verify's step 0 (#325): at HEAD, the claims/1 check `claims check --file` runs on the claims file
|
|
1135
|
+
(refused: its errors), and, when coverage.yaml is committed, offline_check in draft mode against that
|
|
1136
|
+
claims file and the comparator configurations committed at HEAD. Reads only HEAD, never the working tree.
|
|
1137
|
+
{ok, claims {file, present, claims, errors[]}, coverage {file, present, ...offline_check} , lines[]}."""
|
|
1138
|
+
from . import claims as claims_mod
|
|
1139
|
+
from . import comparator_config as cc
|
|
1140
|
+
head = core.git_head(repo) or "HEAD"
|
|
1141
|
+
c12 = head[:12]
|
|
1142
|
+
rel = pkg.get("claims_file") or claims_mod.DEFAULT_CLAIMS_FILE
|
|
1143
|
+
raw = core.git_show_bytes(repo, rel)
|
|
1144
|
+
lines: list[str] = []
|
|
1145
|
+
res: dict = {"ok": True, "claims": {"file": rel, "present": raw is not None, "claims": None, "errors": []},
|
|
1146
|
+
"coverage": {"file": DEFAULT_COVERAGE_FILE, "present": False, "errors": [], "warnings": [],
|
|
1147
|
+
"checks": [], "skipped": []}}
|
|
1148
|
+
claims_text = None
|
|
1149
|
+
if raw is None:
|
|
1150
|
+
lines.append(f"{rel} at {c12}: not committed; no claims/1 check")
|
|
1151
|
+
else:
|
|
1152
|
+
claims_text = raw.decode("utf-8", errors="replace")
|
|
1153
|
+
out, payload, rc = claims_mod.do_claims_check_text(claims_text, f"{rel} at {c12}", name)
|
|
1154
|
+
res["claims"].update(claims=payload["claims"], errors=payload["errors"])
|
|
1155
|
+
lines += out
|
|
1156
|
+
if rc:
|
|
1157
|
+
res["ok"] = False
|
|
1158
|
+
res["lines"] = lines
|
|
1159
|
+
return res
|
|
1160
|
+
craw = core.git_show_bytes(repo, DEFAULT_COVERAGE_FILE)
|
|
1161
|
+
if craw is None:
|
|
1162
|
+
lines.append(f"{DEFAULT_COVERAGE_FILE} at {c12}: not committed; no coverage check")
|
|
1163
|
+
res["lines"] = lines
|
|
1164
|
+
return res
|
|
1165
|
+
where = f"{DEFAULT_COVERAGE_FILE} at {c12}"
|
|
1166
|
+
try:
|
|
1167
|
+
sidecar = gate_mod.sidecar_at(repo, "HEAD")
|
|
1168
|
+
profiles = sites.for_repo(repo)
|
|
1169
|
+
except (ValueError, core.Fail) as e:
|
|
1170
|
+
res["ok"] = False
|
|
1171
|
+
res["coverage"].update(present=True, errors=[str(e)])
|
|
1172
|
+
verdict = f"{where}: coverage: INVALID (1 problem(s); offline)"
|
|
1173
|
+
res["lines"] = lines + [verdict, f" {e}", verdict]
|
|
1174
|
+
return res
|
|
1175
|
+
rep = offline_check(craw.decode("utf-8", errors="replace"), where, claims_text=claims_text,
|
|
1176
|
+
claims_where=f"{rel} at {c12}", configs=cc._configs_at(repo, "HEAD"), sidecar=sidecar,
|
|
1177
|
+
read_file=claims_mod._reader(repo, "HEAD"), profiles=profiles, draft=True)
|
|
1178
|
+
res["coverage"].update(present=True, errors=rep["errors"], warnings=rep["warnings"], checks=rep["checks"],
|
|
1179
|
+
skipped=rep["skipped"])
|
|
1180
|
+
payload = offline_payload(rep, name, where, rel if claims_text is not None else None,
|
|
1181
|
+
sorted(cc._configs_at(repo, "HEAD")))
|
|
1182
|
+
lines += offline_lines(rep, payload, where)
|
|
1183
|
+
res["ok"] = not rep["errors"]
|
|
1184
|
+
res["lines"] = lines
|
|
1185
|
+
return res
|
|
1186
|
+
|
|
1187
|
+
|
|
1188
|
+
def package_checkout(reg: dict, name: str) -> tuple[dict, pathlib.Path]:
|
|
1189
|
+
pkg = core.get_pkg(reg, name)
|
|
1190
|
+
repo = core.repo_path(pkg)
|
|
1191
|
+
if not repo.is_dir():
|
|
1192
|
+
raise core.Fail(f"{name}: local_path does not exist: {repo}")
|
|
1193
|
+
if core.git_head(repo) is None:
|
|
1194
|
+
raise core.Fail(f"{name}: {repo} is not a git checkout with a commit")
|
|
1195
|
+
return pkg, repo
|
|
1196
|
+
|
|
1197
|
+
|
|
1198
|
+
def do_coverage_check(reg: dict, name: str, file: str | None, allow_private: bool) -> tuple[list[str], dict, int]:
|
|
1199
|
+
pkg, repo = package_checkout(reg, name)
|
|
1200
|
+
try:
|
|
1201
|
+
doc, claims, warnings = load_checked(pkg, repo, file, allow_private)
|
|
1202
|
+
except core.Fail as e:
|
|
1203
|
+
lines = str(e).split("\n")
|
|
1204
|
+
problems = [x.strip() for x in lines[1:]] or [lines[0]]
|
|
1205
|
+
payload = {"ok": False, "name": name, "file": file or DEFAULT_COVERAGE_FILE, "kind": None, "rows": None,
|
|
1206
|
+
"counts": None, "manuscript": None, "private_manuscript": None,
|
|
1207
|
+
"errors": problems, "warnings": []}
|
|
1208
|
+
return [f"{name}: coverage: INVALID ({len(problems)} problem(s))", f" {lines[0]}"] + \
|
|
1209
|
+
[f" {x}" for x in problems if x != lines[0]], payload, 1
|
|
1210
|
+
rel = (pkg.get("gate") or {}).get("receipt")
|
|
1211
|
+
warnings = warnings + unlisted_assumption_warnings(doc, claims, repo, receipt_at_head(repo, rel)[0] if rel
|
|
1212
|
+
else None, rel)
|
|
1213
|
+
if doc_kind(doc) == "library":
|
|
1214
|
+
payload = {"ok": True, "name": name, "file": file or DEFAULT_COVERAGE_FILE, "kind": "library",
|
|
1215
|
+
"rows": len(doc["rows"]), "counts": None, "manuscript": None, "private_manuscript": False,
|
|
1216
|
+
"errors": [], "warnings": warnings}
|
|
1217
|
+
line = f"{name}: coverage: OK; library; {len(doc['rows'])} main result(s); no manuscript"
|
|
1218
|
+
return [line] + [f" warning: {w}" for w in warnings], payload, 0
|
|
1219
|
+
counts = {c: sum(r["class"] == c for r in doc["rows"]) for c in CLASSES}
|
|
1220
|
+
kind = manuscript_kind(doc["manuscript"]["version"])
|
|
1221
|
+
payload = {"ok": True, "name": name, "file": file or DEFAULT_COVERAGE_FILE, "kind": "paper",
|
|
1222
|
+
"rows": len(doc["rows"]), "counts": counts, "manuscript": kind, "private_manuscript": kind == "unposted",
|
|
1223
|
+
"errors": [], "warnings": warnings}
|
|
1224
|
+
line = (f"{name}: coverage: OK; {len(doc['rows'])} row(s): " + ", ".join(f"{n} {c}" for c, n in counts.items())
|
|
1225
|
+
+ f"; manuscript {kind}" + (" (PRIVATE DRAFT, --allow-private-manuscript)" if kind == "unposted" else ""))
|
|
1226
|
+
return [line] + [f" warning: {w}" for w in warnings], payload, 0
|
|
1227
|
+
|
|
1228
|
+
|
|
1229
|
+
def run_check(args) -> int:
|
|
1230
|
+
if args.name is None:
|
|
1231
|
+
if args.file is None:
|
|
1232
|
+
raise core.UsageError("coverage check takes a package NAME (the registered package), or --file PATH "
|
|
1233
|
+
"without NAME (the offline check: no registry, no receipts)")
|
|
1234
|
+
out, payload, rc = do_coverage_check_file(args.file, args.claims, args.comparator,
|
|
1235
|
+
args.allow_private_manuscript)
|
|
1236
|
+
else:
|
|
1237
|
+
if args.claims is not None or args.comparator:
|
|
1238
|
+
raise core.UsageError("--claims and --comparator go with the offline form, `coverage check --file PATH` "
|
|
1239
|
+
"without NAME; with NAME the claims are read at HEAD and the configurations from "
|
|
1240
|
+
"the recorded comparator receipt")
|
|
1241
|
+
out, payload, rc = do_coverage_check(core.load_registry(core.registry_path(args)), args.name,
|
|
1242
|
+
args.file, args.allow_private_manuscript)
|
|
1243
|
+
if args.json_out:
|
|
1244
|
+
core.print_json(payload)
|
|
1245
|
+
else:
|
|
1246
|
+
print("\n".join(out))
|
|
1247
|
+
return rc
|
|
1248
|
+
|
|
1249
|
+
|
|
1250
|
+
def cmd_coverage(args) -> int:
|
|
1251
|
+
fn = getattr(args, "coverage_fn", None)
|
|
1252
|
+
if fn is None:
|
|
1253
|
+
raise core.UsageError("coverage needs an action: check")
|
|
1254
|
+
return fn(args)
|
|
1255
|
+
|
|
1256
|
+
|
|
1257
|
+
def add_parsers(sub, add_json) -> None:
|
|
1258
|
+
s = sub.add_parser("coverage", help="coverage.yaml (coverage/1): the paper-to-Lean map (or a library's main "
|
|
1259
|
+
"results) `page` renders")
|
|
1260
|
+
add_json(s)
|
|
1261
|
+
s.set_defaults(fn=cmd_coverage, coverage_fn=None)
|
|
1262
|
+
csub = s.add_subparsers(dest="coverage_cmd")
|
|
1263
|
+
c = csub.add_parser("check", help="validate coverage.yaml against claims.yaml and the receipts at HEAD; "
|
|
1264
|
+
"exit 0/1; read-only (--file without NAME: offline, no registry)")
|
|
1265
|
+
c.add_argument("name", nargs="?", default=None)
|
|
1266
|
+
c.add_argument("--file", default=None, metavar="PATH",
|
|
1267
|
+
help="check this working-copy file instead of coverage.yaml committed at HEAD (claim ids and "
|
|
1268
|
+
"receipts are still read at HEAD); without NAME: the offline check, which reads no "
|
|
1269
|
+
"registry and no receipt and says which checks it skipped")
|
|
1270
|
+
c.add_argument("--claims", default=None, metavar="PATH",
|
|
1271
|
+
help="offline only (no NAME): the claims file the rows' claim ids are checked against")
|
|
1272
|
+
c.add_argument("--comparator", action="append", default=None, metavar="PATH",
|
|
1273
|
+
help="offline only (no NAME): a comparator configuration whose theorems must each be the "
|
|
1274
|
+
"declaration of a claim a row names (repeat for each configuration)")
|
|
1275
|
+
c.add_argument("--allow-private-manuscript", action="store_true",
|
|
1276
|
+
help="accept manuscript.version 'unposted' (a private draft); the output says so")
|
|
1277
|
+
add_json(c)
|
|
1278
|
+
c.set_defaults(fn=cmd_coverage, coverage_fn=run_check)
|