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.
Files changed (103) hide show
  1. lean_pkg/__init__.py +3 -0
  2. lean_pkg/adapters/__init__.py +148 -0
  3. lean_pkg/adapters/github.py +65 -0
  4. lean_pkg/adapters/leansearch.py +68 -0
  5. lean_pkg/adapters/loogle.py +45 -0
  6. lean_pkg/adapters/palomar.py +170 -0
  7. lean_pkg/adapters/reservoir.py +127 -0
  8. lean_pkg/anchor.py +678 -0
  9. lean_pkg/audit.py +716 -0
  10. lean_pkg/binding_file.py +446 -0
  11. lean_pkg/blueprint.py +213 -0
  12. lean_pkg/build_scope.py +282 -0
  13. lean_pkg/ci_github.py +917 -0
  14. lean_pkg/claim_axioms.py +421 -0
  15. lean_pkg/claims.py +1155 -0
  16. lean_pkg/claims_mark.py +197 -0
  17. lean_pkg/cli.py +5208 -0
  18. lean_pkg/cli_parser.py +768 -0
  19. lean_pkg/command_tree.py +615 -0
  20. lean_pkg/comparator_config.py +990 -0
  21. lean_pkg/comparator_contracts.py +382 -0
  22. lean_pkg/comparator_receipt.py +2854 -0
  23. lean_pkg/comparator_stage.py +623 -0
  24. lean_pkg/comparator_types.py +830 -0
  25. lean_pkg/container.py +172 -0
  26. lean_pkg/core.py +1570 -0
  27. lean_pkg/coverage.py +1278 -0
  28. lean_pkg/data/stacks/lts-2026.10.yaml +73 -0
  29. lean_pkg/data/toolchain-advisories.yaml +77 -0
  30. lean_pkg/data/upgrade-breaking.yaml +20 -0
  31. lean_pkg/data/verify-workflow-pins.yaml +14 -0
  32. lean_pkg/deps_closure.py +512 -0
  33. lean_pkg/deps_fill.py +445 -0
  34. lean_pkg/dup_constants.py +448 -0
  35. lean_pkg/exercise.py +828 -0
  36. lean_pkg/exercise_forbid.py +288 -0
  37. lean_pkg/export_paths.py +77 -0
  38. lean_pkg/extract.py +1172 -0
  39. lean_pkg/extract_decls.py +501 -0
  40. lean_pkg/extract_ledger.py +1408 -0
  41. lean_pkg/extract_summary.py +132 -0
  42. lean_pkg/extract_types.py +502 -0
  43. lean_pkg/extract_write.py +138 -0
  44. lean_pkg/formalization.py +1078 -0
  45. lean_pkg/formalization_kept.py +182 -0
  46. lean_pkg/fresh_repo.py +709 -0
  47. lean_pkg/gate.py +2141 -0
  48. lean_pkg/headline.py +211 -0
  49. lean_pkg/help_topics.py +442 -0
  50. lean_pkg/holes.py +289 -0
  51. lean_pkg/host_routes.py +376 -0
  52. lean_pkg/hypotheses.py +788 -0
  53. lean_pkg/index.py +1749 -0
  54. lean_pkg/json_stdout.py +48 -0
  55. lean_pkg/lake_hygiene.py +289 -0
  56. lean_pkg/lean_diag.py +280 -0
  57. lean_pkg/lean_scan.py +1300 -0
  58. lean_pkg/ledger.py +582 -0
  59. lean_pkg/next_step.py +510 -0
  60. lean_pkg/page.py +1831 -0
  61. lean_pkg/page_html.py +153 -0
  62. lean_pkg/palomar.py +316 -0
  63. lean_pkg/palomar_check.py +1027 -0
  64. lean_pkg/port_modules.py +677 -0
  65. lean_pkg/prior_art.py +286 -0
  66. lean_pkg/producer.py +212 -0
  67. lean_pkg/producer_skew.py +208 -0
  68. lean_pkg/public_safety.py +1487 -0
  69. lean_pkg/publish.py +402 -0
  70. lean_pkg/rebase.py +984 -0
  71. lean_pkg/receipt.py +2385 -0
  72. lean_pkg/receipt_check.py +1064 -0
  73. lean_pkg/receipt_ci.py +660 -0
  74. lean_pkg/receipt_systemd.py +890 -0
  75. lean_pkg/recommended.py +232 -0
  76. lean_pkg/report.py +727 -0
  77. lean_pkg/reservoir.py +203 -0
  78. lean_pkg/scaffold.py +588 -0
  79. lean_pkg/schemas/formalization-0.4.schema.json +344 -0
  80. lean_pkg/schemas/formalization-0.4.schema.source.txt +15 -0
  81. lean_pkg/scripts/ClaimAxioms.lean +47 -0
  82. lean_pkg/scripts/ContractsOnly.lean +300 -0
  83. lean_pkg/scripts/DupConstants.lean +149 -0
  84. lean_pkg/scripts/HypProbe.lean +257 -0
  85. lean_pkg/scripts/comparator-check.sh +396 -0
  86. lean_pkg/scripts/verify-comparator.sh +135 -0
  87. lean_pkg/seal_bundle.py +647 -0
  88. lean_pkg/search.py +865 -0
  89. lean_pkg/site_profiles/easley.yaml +10 -0
  90. lean_pkg/site_profiles/github-actions.yaml +12 -0
  91. lean_pkg/sites.py +225 -0
  92. lean_pkg/stacks.py +373 -0
  93. lean_pkg/statements_module.py +217 -0
  94. lean_pkg/templates/Apache-2.0.txt +202 -0
  95. lean_pkg/toolchain_advisories.py +225 -0
  96. lean_pkg/upgrade.py +706 -0
  97. lean_pkg/verify.py +495 -0
  98. lean_pkg-0.25.0.dist-info/METADATA +93 -0
  99. lean_pkg-0.25.0.dist-info/RECORD +103 -0
  100. lean_pkg-0.25.0.dist-info/WHEEL +5 -0
  101. lean_pkg-0.25.0.dist-info/entry_points.txt +5 -0
  102. lean_pkg-0.25.0.dist-info/licenses/LICENSE +202 -0
  103. lean_pkg-0.25.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,208 @@
1
+ # lean-pkg producer skew -- which lean-pkg wrote a package's gate receipts, against the one running now
2
+ """A package's evidence chain can mix lean-pkg versions: the lower-tier receipt written by one release, the
3
+ comparator receipt by another, and `gate`, `gate --check` or `receipt check` run by a third (a field report).
4
+ A receipt records the lean-pkg that wrote it in its additive key `producer` (`producer.lean_pkg`: `receipt
5
+ slurm`, `receipt systemd --run`, `receipt comparator`); `skew(pkg, repo)` compares that version with the
6
+ running `__version__` for the receipts the package's gate state rests on, the registry's `gate.receipt`
7
+ (lower tier) and `gate.comparator`, read from the checkout as `status` reads them.
8
+
9
+ Directions, per receipt:
10
+
11
+ - `unknown`: no readable receipt, no `producer` key (a receipt written before receipts recorded it, or by
12
+ `receipt systemd` without `--run`) or a version that is not X.Y.Z. Info only: nothing can be compared.
13
+ - `same`: the same version string. Info only; commits between releases are not compared.
14
+ - `older` (producer < running): the breaking entries of the shipped list `data/upgrade-breaking.yaml`
15
+ (generated from docs/upgrades/*.yaml by scripts/upgrade-breaking.py) whose version is above the producer's,
16
+ restricted to EVIDENCE_AREAS. The list ships with the running lean-pkg, so every entry in it is part of the
17
+ running code (its own unreleased record included): the range is (producer, running]. With such an entry:
18
+ a WARN naming the entry ids and `lean-pkg doctor --upgrade-from vPRODUCER --source DIR`. Without one
19
+ (only page, CLI or other non-evidence entries in between, or none): info only, no warning.
20
+ - `newer` (producer > running): always a WARN. An older checker reading a newer receipt is the dangerous
21
+ direction: it ignores what it does not know (an older lean-pkg reads a sealed `slurm_sacct` block as an
22
+ unknown key and checks nothing), and its shipped list cannot name the later releases' changes.
23
+
24
+ Never a refusal, never an exit status: `status NAME` prints the WARN lines and adds `producer_skew` to its
25
+ JSON; `doctor --package NAME` runs the same check on demand.
26
+
27
+ EVIDENCE_AREAS is derived from the `area` values the records use (an area is a comma-separated list of
28
+ components): the components whose change alters what a receipt holds or how it is judged, the receipt
29
+ writers and readers (receipts, receipt slurm, receipt check, comparator receipts, comparator, stage logs),
30
+ the gate, and what turns evidence into credited claims (claims, claims ledger, claims mark, coverage check,
31
+ lean-pkg-signoff.json, palomar check, verify). OTHER_AREAS are the components that do not (the page and its
32
+ renderers, the CLI surface, the registry, the index, scaffolding, diagnostics, docs and tests, and palomar
33
+ prepare: its bundle copies the receipts, judged by the gate's own validators, and adds documentation; and
34
+ seal-bundle, which writes a later job's inputs from receipts and never a receipt).
35
+ tests/test_producer_skew.py fails when a record uses a component in neither list, so a new area is
36
+ classified when it first appears.
37
+ """
38
+
39
+ from __future__ import annotations
40
+
41
+ import functools
42
+ import json
43
+ import pathlib
44
+ import re
45
+
46
+ import yaml
47
+
48
+ SCHEMA = "lean-pkg-upgrade-breaking/1"
49
+ DATA_PATH = pathlib.Path(__file__).resolve().parent / "data" / "upgrade-breaking.yaml"
50
+ ENTRY_KEYS = ("version", "id", "pr", "kind", "area")
51
+ ROLES = (("lower-tier", "receipt"), ("comparator", "comparator")) # (role, the registry's gate.<key>)
52
+
53
+ EVIDENCE_AREAS = frozenset({
54
+ "receipts", "receipt slurm", "receipt ci", "receipt check", "comparator receipts", "comparator",
55
+ "comparator (legacy mechanism)", "stage logs", "gate", "claims", "claims ledger", "claims mark",
56
+ "coverage check", "lean-pkg-signoff.json", "palomar check", "verify"})
57
+ OTHER_AREAS = frozenset({
58
+ "page", "cli", "--json", "new", "doctor", "status", "registry", "public-safety", "report", "extract",
59
+ "lean-pkg-extract", "formalization", "formalization render", "formalization.yaml", "coverage.yaml",
60
+ "index add", "index check", "index render", "index entries", "blueprint", "stacks", "comparator check",
61
+ "comparator config --coverage and --from-claims", "comparator config", "tests", "docs (receipts recipe)",
62
+ "repo export", "publish", "search", "lean-exercise", "palomar port-modules",
63
+ "palomar prepare", "seal-bundle"})
64
+
65
+ UNKNOWN_NOTE = ("the receipt records no `producer` (written before receipts recorded it, or by `receipt systemd` "
66
+ "without --run)")
67
+ _VERSION = re.compile(r"^(\d+)\.(\d+)\.(\d+)$")
68
+
69
+
70
+ def version_key(text) -> tuple[int, int, int] | None:
71
+ m = _VERSION.fullmatch(str(text or "").strip())
72
+ return tuple(int(g) for g in m.groups()) if m else None
73
+
74
+
75
+ def area_components(area) -> list[str]:
76
+ return [a.strip() for a in str(area or "").split(",") if a.strip()]
77
+
78
+
79
+ def evidence_entry(entry: dict) -> bool:
80
+ return any(a in EVIDENCE_AREAS for a in area_components(entry.get("area")))
81
+
82
+
83
+ class DataError(ValueError):
84
+ """The shipped breaking-entries file is malformed."""
85
+
86
+
87
+ def parse(text: str) -> list[dict]:
88
+ doc = yaml.safe_load(text)
89
+ if not isinstance(doc, dict) or doc.get("schema") != SCHEMA or set(doc) != {"schema", "entries"}:
90
+ raise DataError(f"not a {SCHEMA} document with exactly the keys schema and entries")
91
+ out = []
92
+ for i, e in enumerate(doc.get("entries") or []):
93
+ if not isinstance(e, dict) or tuple(e) != ENTRY_KEYS or version_key(e["version"]) is None:
94
+ raise DataError(f"entries[{i}]: not {{{', '.join(ENTRY_KEYS)}}} with an X.Y.Z version")
95
+ out.append(dict(e))
96
+ return out
97
+
98
+
99
+ @functools.lru_cache(maxsize=1)
100
+ def load() -> tuple[dict, ...]:
101
+ return tuple(parse(DATA_PATH.read_text(encoding="utf-8")))
102
+
103
+
104
+ def doctor_command(frm: str, to: str | None = None) -> str:
105
+ return (f"lean-pkg doctor --upgrade-from v{frm}" + (f" --to v{to}" if to else "")
106
+ + " --source DIR")
107
+
108
+
109
+ def _read(repo: pathlib.Path | None, rel) -> tuple[dict | None, str | None]:
110
+ if not rel:
111
+ return None, None
112
+ if repo is None or not repo.is_dir():
113
+ return None, "the checkout is missing"
114
+ try:
115
+ data = json.loads((repo / rel).read_text(encoding="utf-8"))
116
+ except (OSError, ValueError) as e:
117
+ return None, f"unreadable ({e.__class__.__name__})"
118
+ return (data, None) if isinstance(data, dict) else (None, "not a JSON object")
119
+
120
+
121
+ def judge(role: str, rel: str, rec: dict | None, why: str | None, running: str, entries) -> dict:
122
+ """One receipt's row: {role, receipt, producer (the lean_pkg string or "unknown"), producer_record (the
123
+ receipt's `producer` object or null), direction, breaking[] (entry views), other_breaking[] (ids outside
124
+ the evidence areas), level (warn|info), message, command}."""
125
+ prod = rec.get("producer") if isinstance(rec, dict) else None
126
+ ver = prod.get("lean_pkg") if isinstance(prod, dict) else None
127
+ row = {"role": role, "receipt": rel, "readable": rec is not None,
128
+ "producer": str(ver) if isinstance(ver, str) and ver.strip() else "unknown",
129
+ "producer_record": prod if isinstance(prod, dict) else None, "direction": "unknown",
130
+ "breaking": [], "other_breaking": [], "level": "info", "message": "", "command": None}
131
+ what = f"{role} receipt {rel}"
132
+ pk, rk = version_key(ver), version_key(running)
133
+ if rec is None:
134
+ row["message"] = f"{what}: producer unknown ({why or 'unreadable'})"
135
+ return row
136
+ if pk is None or rk is None:
137
+ row["message"] = (f"{what}: producer unknown: {UNKNOWN_NOTE}" if row["producer"] == "unknown"
138
+ else f"{what}: producer unknown (version {row['producer']!r} is not X.Y.Z)")
139
+ return row
140
+ if pk == rk:
141
+ row.update(direction="same", message=f"{what}: written by lean-pkg {ver}, the running version")
142
+ return row
143
+ if pk > rk:
144
+ row.update(direction="newer", level="warn", command=doctor_command(running, ver),
145
+ message=(f"{what} was written by lean-pkg {ver}, newer than the running {running}: an older "
146
+ f"lean-pkg ignores evidence it does not know (for example a sealed slurm_sacct record "
147
+ f"that 0.19.0 and older never check) and cannot list what later releases changed; "
148
+ f"upgrade lean-pkg to {ver} or later before trusting gate, gate --check or receipt "
149
+ f"check on it, or read `{doctor_command(running, ver)}` in a lean-pkg clone"))
150
+ return row
151
+ later = [e for e in entries if version_key(e["version"]) > pk]
152
+ hits = [e for e in later if evidence_entry(e)]
153
+ row["breaking"] = [{"id": e["id"], "version": e["version"], "pr": e["pr"], "kind": e["kind"],
154
+ "area": e["area"]} for e in hits]
155
+ row["other_breaking"] = [e["id"] for e in later if not evidence_entry(e)]
156
+ row["direction"] = "older"
157
+ row["command"] = doctor_command(ver)
158
+ if hits:
159
+ ids = ", ".join(f"{e['id']} ({e['version']}, #{e['pr']})" for e in hits)
160
+ row.update(level="warn",
161
+ message=(f"{what} was written by lean-pkg {ver}; the running {running} carries "
162
+ f"{len(hits)} breaking change(s) to receipts, gate or claims since then: {ids}; "
163
+ f"read `{doctor_command(ver)}` (DIR: a lean-pkg clone; omit --source when this "
164
+ f"lean-pkg runs from its own checkout)"))
165
+ else:
166
+ other = (f" ({len(row['other_breaking'])} breaking change(s) elsewhere: "
167
+ f"{', '.join(row['other_breaking'])})" if row["other_breaking"] else "")
168
+ row["message"] = (f"{what}: written by lean-pkg {ver}, older than the running {running}; no breaking "
169
+ f"change to receipts, gate or claims in between{other}")
170
+ return row
171
+
172
+
173
+ def skew(pkg: dict, repo: pathlib.Path | None, running: str | None = None, entries=None) -> dict:
174
+ """{running, receipts[] (judge rows), warnings[] (the WARN texts), skew (any warning), data_problem}.
175
+ Never raises on a package or receipt; a malformed shipped list yields data_problem and no entries."""
176
+ from . import __version__
177
+ running = running or __version__
178
+ problem = None
179
+ if entries is None:
180
+ try:
181
+ entries = load()
182
+ except (OSError, ValueError, yaml.YAMLError) as e:
183
+ entries, problem = (), f"{DATA_PATH.name} could not be read ({e})"
184
+ gate = (pkg or {}).get("gate") if isinstance((pkg or {}).get("gate"), dict) else {}
185
+ rows = []
186
+ for role, key in ROLES:
187
+ rel = gate.get(key)
188
+ if rel:
189
+ rec, why = _read(repo, rel)
190
+ rows.append(judge(role, str(rel), rec, why, running, entries))
191
+ warnings = [r["message"] for r in rows if r["level"] == "warn"]
192
+ return {"running": running, "receipts": rows, "warnings": warnings, "skew": bool(warnings),
193
+ "data_problem": problem}
194
+
195
+
196
+ def warn_lines(result: dict) -> list[str]:
197
+ out = [f"WARN: producer skew: {w}" for w in result["warnings"]]
198
+ if result.get("data_problem"):
199
+ out.append(f"WARN: producer skew: {result['data_problem']}")
200
+ return out
201
+
202
+
203
+ def info_lines(result: dict) -> list[str]:
204
+ """The text block `status` prints: one line per gate receipt (nothing when none is recorded)."""
205
+ if not result["receipts"]:
206
+ return []
207
+ return ([f"producer (the lean-pkg that wrote each gate receipt; running {result['running']}):"]
208
+ + [f" {'WARN ' if r['level'] == 'warn' else ''}{r['message']}" for r in result["receipts"]])