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/claims_mark.py
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# lean-pkg claims mark -- set the status of the claims a comparator configuration covers
|
|
2
|
+
"""`lean-pkg claims mark NAME --from-comparator CONFIG.json --status reusable [--write | --dry-run]`
|
|
3
|
+
(#6 field report): a package can sync hundreds of `experimental` claims and still have nothing the
|
|
4
|
+
claims ledger requires (`status: reusable`), so `publish` reports the ledger `unknown`. This helper sets
|
|
5
|
+
the status of exactly the claims whose `decl` a comparator configuration's `theorem_names` cover (the
|
|
6
|
+
matching rule of `comparator config --coverage` and the ledger: `comparator_config.covers`, full names
|
|
7
|
+
only, a fully qualified decl only), in the checkout's working copy of the claims file.
|
|
8
|
+
|
|
9
|
+
Read-only unless `--write`; `--write` edits the file in place (only the changed `status:` values; the
|
|
10
|
+
rest of the file, comments included, is kept byte for byte when the edit can be made that way, else the
|
|
11
|
+
file is re-dumped and the output says so) and never commits. Configuration names that cover no claim are
|
|
12
|
+
reported. Changing claims.yaml is a new commit: commit it, `claims sync`, and re-gate.
|
|
13
|
+
|
|
14
|
+
Kept in its own module so `claims.py` carries only the parser registration and the zero-reusable warning.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import json
|
|
20
|
+
import pathlib
|
|
21
|
+
|
|
22
|
+
import yaml
|
|
23
|
+
|
|
24
|
+
from . import core
|
|
25
|
+
from . import comparator_config as cc
|
|
26
|
+
from . import holes
|
|
27
|
+
|
|
28
|
+
MARK_STATUSES = ("reusable", "internal", "experimental") # superseded needs superseded_by: edit by hand
|
|
29
|
+
NO_REUSABLE_FIX = ("mark the results others should rely on as status: reusable (`lean-pkg claims mark {name} "
|
|
30
|
+
"--from-comparator CONFIG.json --status reusable`, or edit claims.yaml)")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def no_reusable_warning(name: str, pkg: dict, claims: list | None = None) -> str | None:
|
|
34
|
+
"""A WARN line when a gated package (a gate receipt recorded) has claims and none is `reusable`: the
|
|
35
|
+
promote-stage ledger then requires nothing, so it can never be ready."""
|
|
36
|
+
claims = pkg.get("claims") if claims is None else claims
|
|
37
|
+
if not claims or not (pkg.get("gate") or {}).get("receipt"):
|
|
38
|
+
return None
|
|
39
|
+
if any(isinstance(c, dict) and c.get("status") == "reusable" for c in claims):
|
|
40
|
+
return None
|
|
41
|
+
return (f"{name}: gated, {len(claims)} claim(s), none with status reusable: the claims ledger requires "
|
|
42
|
+
f"nothing, so publish reports it unknown; " + NO_REUSABLE_FIX.format(name=name))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _status_edits(text: str, changes: dict[int, str]) -> str | None:
|
|
46
|
+
"""`text` with the `status` scalar of claim i set to changes[i], everything else byte for byte; None when
|
|
47
|
+
the file's shape does not allow that (the caller re-dumps instead)."""
|
|
48
|
+
try:
|
|
49
|
+
root = yaml.compose(text)
|
|
50
|
+
except yaml.YAMLError:
|
|
51
|
+
return None
|
|
52
|
+
if not isinstance(root, yaml.MappingNode):
|
|
53
|
+
return None
|
|
54
|
+
seq = next((v for k, v in root.value if isinstance(k, yaml.ScalarNode) and k.value == "claims"), None)
|
|
55
|
+
if not isinstance(seq, yaml.SequenceNode):
|
|
56
|
+
return None
|
|
57
|
+
spans = []
|
|
58
|
+
for i, new in changes.items():
|
|
59
|
+
if i >= len(seq.value) or not isinstance(seq.value[i], yaml.MappingNode):
|
|
60
|
+
return None
|
|
61
|
+
node = next((v for k, v in seq.value[i].value if isinstance(k, yaml.ScalarNode) and k.value == "status"),
|
|
62
|
+
None)
|
|
63
|
+
if not isinstance(node, yaml.ScalarNode) or node.start_mark.line != node.end_mark.line:
|
|
64
|
+
return None
|
|
65
|
+
spans.append((node.start_mark.index, node.end_mark.index, new))
|
|
66
|
+
out = text
|
|
67
|
+
for start, end, new in sorted(spans, reverse=True):
|
|
68
|
+
out = out[:start] + new + out[end:]
|
|
69
|
+
return out
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def do_claims_mark(reg: dict, name: str, config: str, status: str, write: bool,
|
|
73
|
+
agent: str | None = None) -> tuple[list[str], dict]:
|
|
74
|
+
from . import claims as cl
|
|
75
|
+
pkg = core.get_pkg(reg, name)
|
|
76
|
+
if status not in MARK_STATUSES:
|
|
77
|
+
raise core.Fail(f"--status must be one of {', '.join(MARK_STATUSES)} (superseded needs superseded_by: "
|
|
78
|
+
f"edit claims.yaml by hand)")
|
|
79
|
+
repo = core.repo_path(pkg)
|
|
80
|
+
if not repo.is_dir():
|
|
81
|
+
raise core.Fail(f"{name}: local_path does not exist: {repo}")
|
|
82
|
+
cpath = pathlib.Path(config).expanduser()
|
|
83
|
+
cpath = cpath if cpath.is_absolute() else repo / cpath
|
|
84
|
+
try:
|
|
85
|
+
cfg = json.loads(cpath.read_text(encoding="utf-8"))
|
|
86
|
+
except FileNotFoundError:
|
|
87
|
+
raise core.Fail(f"{name}: comparator config not found: {cpath} (a relative path is read from the "
|
|
88
|
+
f"checkout {repo})") from None
|
|
89
|
+
except ValueError as e:
|
|
90
|
+
raise core.Fail(f"{cpath}: not valid JSON ({e})") from e
|
|
91
|
+
names = cfg.get("theorem_names") if isinstance(cfg, dict) else None
|
|
92
|
+
if not isinstance(names, list) or not names or not all(isinstance(n, str) and n for n in names):
|
|
93
|
+
raise core.Fail(f"{cpath}: theorem_names must be a non-empty list of strings")
|
|
94
|
+
try:
|
|
95
|
+
crel = cpath.resolve().relative_to(repo.resolve()).as_posix()
|
|
96
|
+
except ValueError:
|
|
97
|
+
crel = None
|
|
98
|
+
if status == "reusable" and crel in holes.smoke_paths(cc.load_sidecar(repo)):
|
|
99
|
+
raise core.Fail(f"{crel}: {holes.SIDECAR} marks this configuration as a smoke check, which verifies no "
|
|
100
|
+
f"claim; mark claims from the configuration that judges them (docs/comparator.md, "
|
|
101
|
+
f"\"Smoke checks\")")
|
|
102
|
+
rel = pkg.get("claims_file") or cl.DEFAULT_CLAIMS_FILE
|
|
103
|
+
fpath = repo / rel
|
|
104
|
+
if fpath.is_symlink() or not fpath.is_file():
|
|
105
|
+
raise core.Fail(f"{name}: {rel} is missing (or a symbolic link) in {repo}")
|
|
106
|
+
text = fpath.read_text(encoding="utf-8")
|
|
107
|
+
doc = cl.load_claims_text(text, rel)
|
|
108
|
+
errors = cl.validate_claims(doc, name)
|
|
109
|
+
if errors:
|
|
110
|
+
raise core.Fail(f"{name}: {rel} fails the claims/1 schema; fix it first: " + "; ".join(errors[:3]))
|
|
111
|
+
claims = doc["claims"]
|
|
112
|
+
|
|
113
|
+
def read(r: str) -> str | None:
|
|
114
|
+
p = repo / r
|
|
115
|
+
return p.read_text(encoding="utf-8", errors="replace") if p.is_file() and not p.is_symlink() else None
|
|
116
|
+
qualified = cc.qualified_decls(read, claims)
|
|
117
|
+
nameset = set(names)
|
|
118
|
+
mapped = cc.mapped_names(claims) # judged_as (#CM): a mapped name marks its own claim only
|
|
119
|
+
matched, changes = [], {}
|
|
120
|
+
for i, c in enumerate(claims):
|
|
121
|
+
decl = str(c.get("decl") or "")
|
|
122
|
+
if not cc.claim_covered(nameset, c, qualified, mapped):
|
|
123
|
+
continue
|
|
124
|
+
matched.append({"id": c.get("id"), "decl": decl, "from": c.get("status"), "to": status,
|
|
125
|
+
"changed": c.get("status") != status})
|
|
126
|
+
if c.get("status") != status:
|
|
127
|
+
changes[i] = status
|
|
128
|
+
unmatched = sorted(n for n in nameset
|
|
129
|
+
if not any(cc.claim_covered({n}, c, qualified, mapped) for c in claims))
|
|
130
|
+
lines = [f"{name}: {len(matched)} claim(s) covered by {len(nameset)} theorem name(s) of {cpath.name}; "
|
|
131
|
+
f"{len(changes)} would change to status {status}" if not write else
|
|
132
|
+
f"{name}: {len(matched)} claim(s) covered by {len(nameset)} theorem name(s) of {cpath.name}; "
|
|
133
|
+
f"{len(changes)} set to status {status}"]
|
|
134
|
+
lines += [f" {'set' if m['changed'] else 'kept'} {m['id']} ({m['decl']}): {m['from']} -> {m['to']}"
|
|
135
|
+
for m in matched]
|
|
136
|
+
lines += [f" unmatched theorem name: {n} (covers no claim's fully qualified decl)" for n in unmatched]
|
|
137
|
+
hints = cc.name_hints(unmatched, [(str(c.get("decl") or ""), str(c.get("decl") or "") in qualified)
|
|
138
|
+
for c in claims]) if unmatched else []
|
|
139
|
+
if unmatched: # #6: say the rule, and the near misses it explains
|
|
140
|
+
lines.append(f" rule: {cc.COVER_RULE}")
|
|
141
|
+
lines += cc.hint_lines(hints)
|
|
142
|
+
payload = {"ok": True, "name": name, "file": rel, "config": str(config), "status": status,
|
|
143
|
+
"matched": matched, "changed": len(changes), "unmatched": unmatched, "written": False,
|
|
144
|
+
"reformatted": False, "rule": cc.COVER_RULE, "hints": hints}
|
|
145
|
+
if not changes:
|
|
146
|
+
lines.append(f"{name}: nothing to change; nothing written")
|
|
147
|
+
return lines, payload
|
|
148
|
+
if not write:
|
|
149
|
+
lines.append(f"DRY RUN — nothing written; --write edits {rel} in the checkout (never commits)")
|
|
150
|
+
return lines, payload
|
|
151
|
+
lease = pkg.get("lease")
|
|
152
|
+
core.refuse_invalid_lease(name, lease)
|
|
153
|
+
if core.lease_live(lease, core.dt.datetime.now(core.dt.timezone.utc)) and agent != lease.get("agent"):
|
|
154
|
+
raise core.Fail(f"{name}: lease held by {lease.get('agent')} — pass --agent {lease.get('agent')}; "
|
|
155
|
+
f"nothing written")
|
|
156
|
+
want = [dict(c, status=changes.get(i, c.get("status"))) for i, c in enumerate(claims)]
|
|
157
|
+
new = _status_edits(text, changes)
|
|
158
|
+
if new is None or (cl.load_claims_text(new, rel).get("claims") != want):
|
|
159
|
+
new = cl.dump_claims(dict(doc, claims=want))
|
|
160
|
+
payload["reformatted"] = True
|
|
161
|
+
lines.append(f" note: {rel} was re-dumped (its layout did not allow an in-place edit; comments are lost)")
|
|
162
|
+
if cl.validate_claims(cl.load_claims_text(new, rel), name):
|
|
163
|
+
raise core.Fail(f"{name}: the edited {rel} would fail the claims/1 schema; nothing written")
|
|
164
|
+
fpath.write_text(new, encoding="utf-8")
|
|
165
|
+
payload["written"] = True
|
|
166
|
+
lines.append(f"wrote {rel} (NOT committed). Next: commit it, `lean-pkg claims sync {name}`, then re-gate "
|
|
167
|
+
f"(claims.yaml is bound by the gate receipt's commit)")
|
|
168
|
+
return lines, payload
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def run_mark(args) -> int:
|
|
172
|
+
if args.write and args.dry_run:
|
|
173
|
+
raise core.UsageError("--write and --dry-run are mutually exclusive")
|
|
174
|
+
reg = core.load_registry(core.registry_path(args))
|
|
175
|
+
out, payload = do_claims_mark(reg, args.name, args.from_comparator, args.status, bool(args.write), args.agent)
|
|
176
|
+
if args.json_out:
|
|
177
|
+
core.print_json(payload)
|
|
178
|
+
else:
|
|
179
|
+
print("\n".join(out))
|
|
180
|
+
return 0
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def add_parser(csub, add_json, cmd_claims) -> None:
|
|
184
|
+
k = csub.add_parser("mark", help="set the status of the claims a comparator config's theorem_names cover "
|
|
185
|
+
"(exact full-name match); read-only unless --write; never commits")
|
|
186
|
+
k.add_argument("name")
|
|
187
|
+
k.add_argument("--from-comparator", dest="from_comparator", required=True, metavar="CONFIG.json",
|
|
188
|
+
help="the comparator configuration whose theorem_names select the claims (relative paths are "
|
|
189
|
+
"read from the checkout)")
|
|
190
|
+
k.add_argument("--status", required=True, choices=MARK_STATUSES, help="the status to set")
|
|
191
|
+
k.add_argument("--write", action="store_true",
|
|
192
|
+
help="edit the claims file in the checkout (only the status values; never committed)")
|
|
193
|
+
k.add_argument("--dry-run", dest="dry_run", action="store_true", help="print the changes; write nothing "
|
|
194
|
+
"(the default)")
|
|
195
|
+
k.add_argument("--agent", default=None, help="with --write: the lease holder, when the package is leased")
|
|
196
|
+
add_json(k)
|
|
197
|
+
k.set_defaults(fn=cmd_claims, claims_fn=run_mark)
|