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/recommended.py
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# lean-pkg recommended version -- the lean-pkg a shared registry recommends, against the one running now
|
|
2
|
+
"""A lab shares one registry; each machine runs its own lean-pkg. A machine still on an older release gates
|
|
3
|
+
and writes with it, and nothing said so (#388: a gate run with 0.20.0 while 0.22.0 was current). The registry
|
|
4
|
+
file declares the release its users should run, in the optional top-level key
|
|
5
|
+
|
|
6
|
+
lean_pkg:
|
|
7
|
+
recommended: X.Y.Z
|
|
8
|
+
|
|
9
|
+
written only by `lean-pkg registry recommend X.Y.Z` (event `registry-recommended`), never by hand. The check
|
|
10
|
+
is offline and reproducible: it reads the registry, never the network.
|
|
11
|
+
|
|
12
|
+
- Writing commands (every registry write, `cli.is_write_invocation`, and the receipt producers `receipt slurm`,
|
|
13
|
+
`receipt systemd`, `receipt ci`, `receipt comparator`, outside their read-only forms) print ONE stderr notice
|
|
14
|
+
when the running lean-pkg is older than the recommendation, and never refuse. A registry write's `--json`
|
|
15
|
+
payload gains `lean_pkg_skew {running, recommended}`; the key is absent when the running lean-pkg is not
|
|
16
|
+
older (equal, newer, no recommendation, an unreadable one).
|
|
17
|
+
- `doctor` prints a `recommended` line: warn when older, ok when equal or newer, n/a when the registry
|
|
18
|
+
recommends nothing, warn when the key is malformed.
|
|
19
|
+
- `registry validate` refuses a malformed key: `lean_pkg` must be a mapping and `lean_pkg.recommended`, when
|
|
20
|
+
present, a version string X.Y.Z (three non-negative integers without leading zeros). Other keys under
|
|
21
|
+
`lean_pkg` are ignored, as an unknown optional key is (docs/formats.md), so a later release may add one.
|
|
22
|
+
|
|
23
|
+
The comparison is on X.Y.Z only. The running version's leading X.Y.Z is used, so an editable development
|
|
24
|
+
build (`0.23.0.dev1`, `0.23.0+dirty`) compares as 0.23.0; a running version with no leading X.Y.Z is never
|
|
25
|
+
older. The key is additive: the registry schema stays version 3, and an older lean-pkg ignores it and keeps
|
|
26
|
+
it on every save (it saves the mapping it loaded).
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
from __future__ import annotations
|
|
30
|
+
|
|
31
|
+
import re
|
|
32
|
+
import shlex
|
|
33
|
+
import sys
|
|
34
|
+
|
|
35
|
+
import yaml
|
|
36
|
+
|
|
37
|
+
from . import core
|
|
38
|
+
|
|
39
|
+
KEY = "lean_pkg"
|
|
40
|
+
FIELD = "recommended"
|
|
41
|
+
EVENT = "registry-recommended"
|
|
42
|
+
VERSION_RE = re.compile(r"(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)")
|
|
43
|
+
_LEADING_RE = re.compile(r"(\d+)\.(\d+)\.(\d+)")
|
|
44
|
+
INSTALL_URL = "git+https://github.com/lean-pkg/lean-pkg.git"
|
|
45
|
+
# The receipt producers' forms that write nothing (a template, a preflight, an estimate, a read of attempts).
|
|
46
|
+
_RECEIPT_READ_ONLY_FLAGS = ("template", "check", "preflight_deps", "estimate")
|
|
47
|
+
# The notices printed during the current top-level invocation: `verify` runs its steps (receipts, the gate) as
|
|
48
|
+
# nested invocations of cli.main, and the notice is still one line. cli.main clears it when it is outermost.
|
|
49
|
+
_PRINTED: set[str] = set()
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def parse(version) -> tuple[int, int, int] | None:
|
|
53
|
+
"""X.Y.Z of a recommendation (strict: the whole string), else None."""
|
|
54
|
+
m = VERSION_RE.fullmatch(version) if isinstance(version, str) else None
|
|
55
|
+
return tuple(int(x) for x in m.groups()) if m else None
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def running_triple(version: str) -> tuple[int, int, int] | None:
|
|
59
|
+
"""The leading X.Y.Z of the running version (0.23.0.dev1 and 0.23.0+dirty compare as 0.23.0), else None."""
|
|
60
|
+
m = _LEADING_RE.match(version or "")
|
|
61
|
+
return tuple(int(x) for x in m.groups()) if m else None
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def shape_errors(data) -> list[str]:
|
|
65
|
+
"""`registry validate`'s errors for the top-level `lean_pkg` key (none when absent)."""
|
|
66
|
+
if not isinstance(data, dict) or KEY not in data:
|
|
67
|
+
return []
|
|
68
|
+
block = data[KEY]
|
|
69
|
+
if not isinstance(block, dict):
|
|
70
|
+
return [f"{KEY}: must be a mapping (e.g. {{{FIELD}: 0.23.0}}), got {block!r}"]
|
|
71
|
+
if FIELD in block and parse(block[FIELD]) is None:
|
|
72
|
+
return [f"{KEY}.{FIELD}: must be a version string X.Y.Z (three non-negative integers), got "
|
|
73
|
+
f"{block[FIELD]!r} (set it with `lean-pkg registry recommend X.Y.Z`)"]
|
|
74
|
+
return []
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def recommended(data) -> str | None:
|
|
78
|
+
"""The registry's well-formed recommendation, else None (absent or malformed)."""
|
|
79
|
+
block = data.get(KEY) if isinstance(data, dict) else None
|
|
80
|
+
value = block.get(FIELD) if isinstance(block, dict) else None
|
|
81
|
+
return value if parse(value) is not None else None
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def skew(data, running: str | None = None) -> dict | None:
|
|
85
|
+
"""{"running", "recommended"} when the running lean-pkg is older than the registry's recommendation;
|
|
86
|
+
None when it is not (equal, newer, nothing recommended, a malformed key, an unparseable running version)."""
|
|
87
|
+
if running is None:
|
|
88
|
+
from . import __version__ as running
|
|
89
|
+
rec = recommended(data)
|
|
90
|
+
run = running_triple(running)
|
|
91
|
+
if rec is None or run is None or run >= parse(rec):
|
|
92
|
+
return None
|
|
93
|
+
return {"running": running, "recommended": rec}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def upgrade_route(rec: str) -> str:
|
|
97
|
+
"""How to upgrade, offline: `git -C <checkout> pull --ff-only` for an editable install (a git checkout),
|
|
98
|
+
else the documented pipx install pinned to the recommended release's tag."""
|
|
99
|
+
from . import cli # install_detect lives there; cli imports this module only inside functions
|
|
100
|
+
try:
|
|
101
|
+
info = cli.install_detect(cli.package_dir())
|
|
102
|
+
except Exception: # noqa: BLE001 -- the route is advice; never let it break a write
|
|
103
|
+
info = {"install": "unknown"}
|
|
104
|
+
if info.get("install") == "editable":
|
|
105
|
+
return f"git -C {shlex.quote(str(info['path']))} pull --ff-only"
|
|
106
|
+
return f"pipx install --force '{INSTALL_URL}@v{rec}'"
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def notice_line(sk: dict) -> str:
|
|
110
|
+
return (f"lean-pkg: notice: this is lean-pkg {sk['running']}; the registry recommends {sk['recommended']} "
|
|
111
|
+
f"(upgrade: {upgrade_route(sk['recommended'])})")
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def notices_for(args) -> bool:
|
|
115
|
+
"""Does this invocation get the notice? Every registry write, and the receipt producers outside their
|
|
116
|
+
read-only forms (`receipt check`, `--template`, `--check`, `--preflight-deps`, `--estimate`,
|
|
117
|
+
`--verify-oleans`, `--attempts`)."""
|
|
118
|
+
from . import cli
|
|
119
|
+
if core.registry_snapshot_arg(args):
|
|
120
|
+
return False
|
|
121
|
+
if cli.is_write_invocation(args):
|
|
122
|
+
return True
|
|
123
|
+
if getattr(args, "cmd", None) != "receipt" or getattr(args, "receipt_cmd", None) not in (
|
|
124
|
+
"slurm", "systemd", "ci", "comparator"):
|
|
125
|
+
return False
|
|
126
|
+
# `is True`: receipt comparator's --check is a path (the script to run), not the read-only mode
|
|
127
|
+
if any(getattr(args, f, False) is True for f in _RECEIPT_READ_ONLY_FLAGS):
|
|
128
|
+
return False
|
|
129
|
+
return getattr(args, "verify_oleans", None) is None and getattr(args, "attempts", None) is None
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def registry_top(args) -> dict | None:
|
|
133
|
+
"""The top-level keys of the registry this invocation read (core._LOADED_TOP), else a best-effort read of
|
|
134
|
+
the resolved registry (a receipt producer reads none; a refusal may come before the load); None when
|
|
135
|
+
unreadable. Never raises."""
|
|
136
|
+
if core._LOADED_TOP:
|
|
137
|
+
return dict(core._LOADED_TOP)
|
|
138
|
+
try:
|
|
139
|
+
p = core.registry_path(args)
|
|
140
|
+
if not p.is_file():
|
|
141
|
+
return None
|
|
142
|
+
data = yaml.safe_load(p.read_text())
|
|
143
|
+
except Exception: # noqa: BLE001 -- best effort: an unreadable registry means no notice
|
|
144
|
+
return None
|
|
145
|
+
return data if isinstance(data, dict) else None
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def after_command(args) -> dict | None:
|
|
149
|
+
"""run_command's step after a command: print the one stderr notice when this invocation gets it and the
|
|
150
|
+
running lean-pkg is older than the registry's recommendation; returns the skew for the --json payload."""
|
|
151
|
+
try:
|
|
152
|
+
if not notices_for(args):
|
|
153
|
+
return None
|
|
154
|
+
sk = skew(registry_top(args))
|
|
155
|
+
if sk is not None:
|
|
156
|
+
line = notice_line(sk)
|
|
157
|
+
if line not in _PRINTED:
|
|
158
|
+
_PRINTED.add(line)
|
|
159
|
+
print(line, file=sys.stderr)
|
|
160
|
+
return sk
|
|
161
|
+
except Exception: # noqa: BLE001 -- a notice must never change a command's outcome
|
|
162
|
+
return None
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def doctor_line(data) -> tuple[str, str]:
|
|
166
|
+
"""(level, detail) of doctor's `recommended` line."""
|
|
167
|
+
from . import __version__
|
|
168
|
+
if not isinstance(data, dict):
|
|
169
|
+
return "n/a", "registry unreadable; nothing compared"
|
|
170
|
+
errs = shape_errors(data)
|
|
171
|
+
if errs:
|
|
172
|
+
return "warn", f"{errs[0]}; nothing compared (lean-pkg registry validate)"
|
|
173
|
+
rec = recommended(data)
|
|
174
|
+
if rec is None:
|
|
175
|
+
return "n/a", ("the registry recommends no lean-pkg version (whoever upgrades the lab sets one: "
|
|
176
|
+
"lean-pkg registry recommend X.Y.Z)")
|
|
177
|
+
sk = skew(data, __version__)
|
|
178
|
+
if sk is not None:
|
|
179
|
+
return "warn", (f"this is lean-pkg {__version__}, older than the {rec} the registry recommends "
|
|
180
|
+
f"(upgrade: {upgrade_route(rec)})")
|
|
181
|
+
if running_triple(__version__) is None:
|
|
182
|
+
return "n/a", f"the registry recommends {rec}; the running version {__version__!r} is not X.Y.Z"
|
|
183
|
+
return "ok", f"lean-pkg {__version__}; the registry recommends {rec}"
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def cmd_registry_recommend(args) -> int:
|
|
187
|
+
"""`registry recommend X.Y.Z`: set the registry's recommended lean-pkg (top-level lean_pkg.recommended)
|
|
188
|
+
and append the log-only event registry-recommended {recommended, previous, reason}. The same version
|
|
189
|
+
again writes nothing (exit 0)."""
|
|
190
|
+
from . import __version__
|
|
191
|
+
version = (args.version or "").strip()
|
|
192
|
+
if parse(version) is None:
|
|
193
|
+
raise core.UsageError(f"registry recommend: VERSION must be X.Y.Z (three non-negative integers, e.g. "
|
|
194
|
+
f"0.23.0), got {args.version!r}")
|
|
195
|
+
reg_path, events_p = core.registry_path(args), core.events_path(args)
|
|
196
|
+
data = core.load_registry(reg_path)
|
|
197
|
+
block = data.get(KEY)
|
|
198
|
+
previous = block.get(FIELD) if isinstance(block, dict) else None
|
|
199
|
+
payload = {"ok": True, "recommended": version, "previous": previous, "registry": str(reg_path),
|
|
200
|
+
"event": None, "running": __version__}
|
|
201
|
+
if previous == version and isinstance(block, dict):
|
|
202
|
+
line = f"the registry already recommends lean-pkg {version}; nothing written"
|
|
203
|
+
else:
|
|
204
|
+
new_block = dict(block) if isinstance(block, dict) else {}
|
|
205
|
+
new_block[FIELD] = version
|
|
206
|
+
data[KEY] = new_block
|
|
207
|
+
core.save_registry(reg_path, data)
|
|
208
|
+
core._LOADED_TOP[KEY] = new_block
|
|
209
|
+
fields = {"recommended": version, "previous": previous}
|
|
210
|
+
if (args.reason or "").strip():
|
|
211
|
+
fields["reason"] = args.reason.strip()
|
|
212
|
+
core.append_event(events_p, core.now_iso(), None, EVENT, **fields)
|
|
213
|
+
payload["event"] = EVENT
|
|
214
|
+
line = (f"the registry recommends lean-pkg {version}" + (f" (was {previous})" if previous else "")
|
|
215
|
+
+ f"; writing commands of an older lean-pkg print a notice (this is {__version__})")
|
|
216
|
+
if args.json_out:
|
|
217
|
+
core.print_json(payload)
|
|
218
|
+
else:
|
|
219
|
+
print(line)
|
|
220
|
+
return 0
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def add_parser(registry_sub, add_json) -> None:
|
|
224
|
+
s = registry_sub.add_parser(
|
|
225
|
+
"recommend", help="set the lean-pkg version this registry recommends; an older lean-pkg's writing "
|
|
226
|
+
"commands then print a notice (offline; never a refusal)")
|
|
227
|
+
s.add_argument("version", metavar="VERSION",
|
|
228
|
+
help="X.Y.Z: the release every machine using this registry should run (stored as the "
|
|
229
|
+
"top-level lean_pkg.recommended; event registry-recommended)")
|
|
230
|
+
s.add_argument("--reason", default="", help="free text recorded with the event")
|
|
231
|
+
add_json(s)
|
|
232
|
+
s.set_defaults(fn=cmd_registry_recommend)
|