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
lean_pkg/container.py ADDED
@@ -0,0 +1,172 @@
1
+ # lean-pkg container -- the container image a verification job ran in, as an additive receipt key
2
+ """The additive receipt key `container` (#236): the identity of the container image the job's tools ran in.
3
+
4
+ container:
5
+ engine: apptainer | singularity | podman | docker
6
+ image_sha256: <64 hex> # Apptainer / Singularity: the SHA-256 of the SIF file
7
+ oci_digest: sha256:<64 hex> # podman / docker: the image's OCI digest (exactly one of the two)
8
+ ref: TEXT # the image path or name as given, a home directory shown as ~
9
+
10
+ Where it comes from:
11
+
12
+ - `receipt slurm` (and `receipt systemd`, which shares the pipeline): the verify log's `container-engine:`,
13
+ `container-image:` and `container-image-sha256:` (or `container-oci-digest:`) lines, which the
14
+ `--template` job writes when it runs its tools in a container (CONTAINER_IMAGE, or a `.sif` word of
15
+ RUN). With --stdout, the job stdout must carry the same digest line (`container-image-sha256 <hex>`),
16
+ so an edited stdout line and an edited log line both refuse (the log is sealed by verify-log-sha256).
17
+ - `comparator-receipt` / `receipt comparator`: inside Apptainer or Singularity, from APPTAINER_CONTAINER
18
+ (else SINGULARITY_CONTAINER) when it names a regular file readable here, hashed when the receipt is
19
+ written. A sandbox directory, an image path not visible inside the container, or an OCI runtime (no
20
+ digest is visible from inside one) leaves the key absent.
21
+
22
+ No schema bump: gate and every reader that does not know the key ignore it; a receipt without it is
23
+ unchanged. `receipt check` shows it and fails a malformed one; the page names the engine and the digest,
24
+ never `ref`. The digest is what the job (or the runner) measured; nothing published lets a referee
25
+ re-derive it, because the image is not published.
26
+ """
27
+
28
+ from __future__ import annotations
29
+
30
+ import hashlib
31
+ import os
32
+ import re
33
+
34
+ SIF_ENGINES = ("apptainer", "singularity")
35
+ OCI_ENGINES = ("podman", "docker")
36
+ ENGINES = SIF_ENGINES + OCI_ENGINES
37
+ # verify-log key -> (receipt key, engines it belongs to, value pattern)
38
+ DIGEST_KEYS = {
39
+ "container-image-sha256": ("image_sha256", SIF_ENGINES, re.compile(r"[0-9a-f]{64}")),
40
+ "container-oci-digest": ("oci_digest", OCI_ENGINES, re.compile(r"sha256:[0-9a-f]{64}")),
41
+ }
42
+ ENGINE_KEY, REF_KEY = "container-engine", "container-image"
43
+ LOG_KEYS = (ENGINE_KEY, REF_KEY, *DIGEST_KEYS)
44
+ LABELS = {"apptainer": "Apptainer", "singularity": "Singularity", "podman": "Podman", "docker": "Docker"}
45
+ REF_MAX = 300
46
+ _HOME_RE = re.compile(r"^(?:/home|/Users)/[^/\s]+(?=/)|^/root(?=/)")
47
+
48
+
49
+ def redact_ref(ref: str) -> str:
50
+ """The image path as given, with a home directory (this one, or /home/<u>, /Users/<u>, /root) shown as ~."""
51
+ home = os.environ.get("HOME") or ""
52
+ if home not in ("", "/") and (ref == home or ref.startswith(home.rstrip("/") + "/")):
53
+ ref = "~" + ref[len(home.rstrip("/")):]
54
+ return _HOME_RE.sub("~", ref, count=1)
55
+
56
+
57
+ def problems(value) -> list[str]:
58
+ """What is wrong with a receipt's `container` value (empty: well formed)."""
59
+ if not isinstance(value, dict):
60
+ return ["container: must be a mapping"]
61
+ out = []
62
+ engine = value.get("engine")
63
+ if engine not in ENGINES:
64
+ out.append(f"container.engine: must be one of {', '.join(ENGINES)}, got {engine!r}")
65
+ held = [(k, rk, eng, rx) for k, (rk, eng, rx) in DIGEST_KEYS.items() if rk in value]
66
+ if len(held) != 1:
67
+ out.append("container: exactly one of image_sha256 (a SIF file) and oci_digest (an OCI image)")
68
+ for _k, rk, eng, rx in held:
69
+ if not isinstance(value[rk], str) or not rx.fullmatch(value[rk]):
70
+ out.append(f"container.{rk}: must match {rx.pattern}")
71
+ if engine in ENGINES and engine not in eng:
72
+ out.append(f"container.{rk}: only for engine {' or '.join(eng)}, not {engine}")
73
+ ref = value.get("ref")
74
+ if ref is not None and (not isinstance(ref, str) or not ref.strip() or "\n" in ref or len(ref) > REF_MAX):
75
+ out.append(f"container.ref: one non-empty line of at most {REF_MAX} characters")
76
+ extra = sorted(set(value) - {"engine", "ref", *(rk for rk, _e, _r in DIGEST_KEYS.values())})
77
+ if extra:
78
+ out.append(f"container: unknown key(s) {', '.join(map(repr, extra))}")
79
+ return out
80
+
81
+
82
+ def digest_of(value: dict) -> tuple[str, str]:
83
+ """(kind, digest) of a well-formed value: ('SIF SHA-256', hex) or ('OCI digest', sha256:hex)."""
84
+ if "image_sha256" in value:
85
+ return "SIF SHA-256", value["image_sha256"]
86
+ return "OCI digest", value["oci_digest"]
87
+
88
+
89
+ def describe(value: dict) -> str:
90
+ """One line for `receipt check` and the receipt's check list."""
91
+ kind, digest = digest_of(value)
92
+ ref = f" (image `{value['ref']}`)" if value.get("ref") else ""
93
+ return f"{LABELS.get(value['engine'], value['engine'])} container, {kind} {digest}{ref}"
94
+
95
+
96
+ def from_log(fields: dict, stdout_values, refusals: list[str], checks: list[str]) -> dict | None:
97
+ """The `container` value of a Slurm / systemd receipt from the verify log's container lines (`fields`, the
98
+ parsed log), cross-checked with the job stdout's digest line when there is a stdout (`stdout_values(key)`,
99
+ the stdout's values for a key, else None). Returns None when neither names a container."""
100
+ in_log = [k for k in DIGEST_KEYS if k in fields]
101
+ on_stdout = {k: stdout_values(k) for k in DIGEST_KEYS} if stdout_values is not None else {}
102
+ if not in_log and not any(on_stdout.values()) and ENGINE_KEY not in fields and REF_KEY not in fields:
103
+ return None
104
+ n0 = len(refusals)
105
+ if len(in_log) != 1:
106
+ refusals.append("verify log: container lines need exactly one of `container-image-sha256:` (a SIF "
107
+ "file) and `container-oci-digest:` (an OCI image)"
108
+ + (f"; the job stdout has {', '.join(f'`{k}`' for k, v in on_stdout.items() if v)}"
109
+ if not in_log and any(on_stdout.values()) else ""))
110
+ return None
111
+ key = in_log[0]
112
+ rkey, engines, rx = DIGEST_KEYS[key]
113
+ digest = fields[key].strip().lower()
114
+ engine = (fields.get(ENGINE_KEY) or "").strip()
115
+ if not rx.fullmatch(digest):
116
+ refusals.append(f"verify log: `{key}:` must match {rx.pattern}, got {fields[key]!r}")
117
+ if engine not in engines:
118
+ refusals.append(f"verify log: `{ENGINE_KEY}:` must be one of {', '.join(engines)} beside `{key}:`, "
119
+ f"got {engine or 'nothing'!r}")
120
+ sealed = "in-log seal only (no --stdout)"
121
+ if stdout_values is not None:
122
+ for other in DIGEST_KEYS:
123
+ if other != key and on_stdout.get(other):
124
+ refusals.append(f"job stdout: a `{other}` line, but the verify log records `{key}:`")
125
+ vals = [v.lower() for v in on_stdout.get(key) or []]
126
+ if len(vals) != 1:
127
+ refusals.append(f"job stdout: {len(vals)} `{key}` line(s) beside the verify log's `{key}:` line; "
128
+ f"exactly one is required")
129
+ elif vals[0] != digest:
130
+ refusals.append(f"job stdout: `{key}` {vals[0][:19]}… is not the verify log's `{key}:` "
131
+ f"{digest[:19]}…; the image digest was changed after the job")
132
+ sealed = "verify log = job stdout"
133
+ if len(refusals) > n0:
134
+ return None
135
+ value = {"engine": engine, rkey: digest}
136
+ ref = fields.get(REF_KEY)
137
+ if ref:
138
+ value["ref"] = redact_ref(ref.strip())
139
+ bad = problems(value)
140
+ if bad:
141
+ refusals += [f"verify log: {b}" for b in bad]
142
+ return None
143
+ checks.append(f"✓ container: {describe(value)}; {sealed}")
144
+ return value
145
+
146
+
147
+ def sha256_file(path: str) -> str:
148
+ h = hashlib.sha256()
149
+ with open(path, "rb") as f:
150
+ for chunk in iter(lambda: f.read(1 << 20), b""):
151
+ h.update(chunk)
152
+ return h.hexdigest()
153
+
154
+
155
+ def from_environment(environ=None) -> dict | None:
156
+ """The `container` value a process running inside Apptainer / Singularity can measure itself: the SIF
157
+ named by APPTAINER_CONTAINER (else SINGULARITY_CONTAINER), hashed, when it is a regular file readable
158
+ here. None otherwise (not in a container, a sandbox directory, the image not visible inside, an OCI
159
+ runtime)."""
160
+ env = os.environ if environ is None else environ
161
+ for var, engine in (("APPTAINER_CONTAINER", "apptainer"), ("SINGULARITY_CONTAINER", "singularity")):
162
+ path = env.get(var)
163
+ if not path:
164
+ continue
165
+ try:
166
+ if not os.path.isfile(path):
167
+ return None
168
+ digest = sha256_file(path)
169
+ except OSError:
170
+ return None
171
+ return {"engine": engine, "image_sha256": digest, "ref": redact_ref(path)}
172
+ return None