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,182 @@
1
+ # lean-pkg formalization kept -- the canonical kept view of formalization.yaml and its SHA-256
2
+ """`lean-pkg formalization kept [--repo DIR] [--file REL] [--at REV] [--against REV2] [--json]`.
3
+
4
+ A package's own release-input audit wants to pin what a person wrote in ``formalization.yaml`` without
5
+ tripping over the keys ``lean-pkg formalization`` regenerates after every receipt (``status.evidence``
6
+ and the rest of ``formalization.DERIVED_PATHS``). This command prints the **kept view** (the document with
7
+ every derived key removed, ``formalization.kept_view``) in one canonical byte form and its SHA-256, so an
8
+ audit can pin that hash; ``--against REV2`` reports which kept keys differ from another revision
9
+ (``formalization.changed_kept_keys``, the same rule the evidence-only descendant check applies) and exits 1
10
+ when any does. Read-only: never the registry, never a write, no network.
11
+
12
+ The recipe (docs/formalization.md, "The kept view"; pinned by tests/test_formalization_kept.py):
13
+
14
+ 1. Parse the YAML file (UTF-8) as YAML 1.1 with the safe schema (PyYAML ``SafeLoader``), except that
15
+ timestamps are not resolved: an unquoted ``2026-10-17`` stays the string ``"2026-10-17"``.
16
+ A non-mapping document reads as ``{}``.
17
+ 2. Remove each derived key path in DERIVED_PATHS where it exists; a parent mapping left empty stays (as
18
+ ``{}``). In ``acknowledgements`` (a string) drop every line starting ``Formalizes results of `` or
19
+ ``AI assistance: ``, strip leading and trailing newlines, and drop the key when what is left is
20
+ blank.
21
+ 3. Serialise as JSON: object keys sorted by Unicode code point, separators ``,`` and ``:`` (no spaces),
22
+ non-ASCII characters written as themselves (not ``\\uXXXX``), no NaN/Infinity, no trailing newline;
23
+ encode as UTF-8.
24
+ 4. The hash is the lowercase hex SHA-256 of those bytes.
25
+ """
26
+ from __future__ import annotations
27
+
28
+ import hashlib
29
+ import json
30
+ import math
31
+ import pathlib
32
+
33
+ import yaml
34
+
35
+ from . import core
36
+ from .formalization import DEFAULT_PATH, DERIVED_PATHS, changed_kept_keys, kept_view
37
+
38
+ SCHEMA = "formalization-kept/1"
39
+ RECIPE = ("kept_view (formalization.DERIVED_PATHS removed; renderer acknowledgements lines dropped), "
40
+ "YAML 1.1 safe schema without timestamp resolution, JSON sort_keys, separators (',', ':'), "
41
+ "ensure_ascii false, UTF-8, no trailing newline; sha256 hex")
42
+
43
+
44
+ class KeptLoader(yaml.SafeLoader):
45
+ """SafeLoader without the timestamp resolver: dates stay strings, so every value maps onto JSON."""
46
+
47
+
48
+ KeptLoader.yaml_implicit_resolvers = {
49
+ ch: [(tag, rx) for tag, rx in resolvers if tag != "tag:yaml.org,2002:timestamp"]
50
+ for ch, resolvers in yaml.SafeLoader.yaml_implicit_resolvers.items()}
51
+
52
+
53
+ def load_text(text: str) -> dict:
54
+ """The document as JSON-shaped data (step 1); a non-mapping document is {}."""
55
+ doc = yaml.load(text, Loader=KeptLoader) # noqa: S506 -- a SafeLoader subclass
56
+ return doc if isinstance(doc, dict) else {}
57
+
58
+
59
+ def _check_json(value, where: str = "") -> None:
60
+ if isinstance(value, dict):
61
+ for k, v in value.items():
62
+ if not isinstance(k, str):
63
+ raise core.Fail(f"formalization.yaml: key {k!r}{' under ' + where if where else ''} is not a "
64
+ f"string; the kept view needs JSON object keys")
65
+ _check_json(v, f"{where}.{k}" if where else k)
66
+ elif isinstance(value, list):
67
+ for i, v in enumerate(value):
68
+ _check_json(v, f"{where}[{i}]")
69
+ elif isinstance(value, float):
70
+ if not math.isfinite(value):
71
+ raise core.Fail(f"formalization.yaml: {where or 'the document'} is {value!r}; JSON has no NaN/Infinity")
72
+ elif not (value is None or isinstance(value, (str, bool, int))):
73
+ raise core.Fail(f"formalization.yaml: {where or 'the document'} is a {type(value).__name__}, not a "
74
+ f"JSON value (binary or set tags are not accepted)")
75
+
76
+
77
+ def canonical_bytes(view: dict) -> bytes:
78
+ """Step 3: the canonical JSON bytes of a kept view."""
79
+ _check_json(view)
80
+ return json.dumps(view, sort_keys=True, separators=(",", ":"), ensure_ascii=False,
81
+ allow_nan=False).encode("utf-8")
82
+
83
+
84
+ def kept_digest(doc: dict) -> tuple[dict, bytes, str]:
85
+ """(kept view, canonical bytes, sha256 hex) of a loaded document."""
86
+ view = kept_view(doc)
87
+ raw = canonical_bytes(view)
88
+ return view, raw, hashlib.sha256(raw).hexdigest()
89
+
90
+
91
+ def _resolve(repo: pathlib.Path, rev: str) -> str:
92
+ p = core.git(repo, "rev-parse", "--verify", "--quiet", f"{rev}^{{commit}}")
93
+ if p.returncode != 0 or not p.stdout.strip():
94
+ raise core.Fail(f"{rev!r} is not a commit in {repo}")
95
+ return p.stdout.strip()
96
+
97
+
98
+ def read_doc(repo: pathlib.Path, rel: str, rev: str | None) -> tuple[dict, str | None]:
99
+ """(document, resolved commit or None for the working tree)."""
100
+ if rev is None:
101
+ path = repo / rel
102
+ if not path.is_file():
103
+ raise core.Fail(f"{rel} not found in {repo}")
104
+ raw, commit = path.read_bytes(), None
105
+ else:
106
+ commit = _resolve(repo, rev)
107
+ raw = core.git_show_bytes(repo, rel, commit)
108
+ if raw is None:
109
+ raise core.Fail(f"{rel} is not tracked at {rev} ({commit[:12]})")
110
+ try:
111
+ text = raw.decode("utf-8")
112
+ except UnicodeDecodeError as e:
113
+ raise core.Fail(f"{rel} at {rev or 'the working tree'} is not UTF-8: {e}") from None
114
+ try:
115
+ return load_text(text), commit
116
+ except yaml.YAMLError as e:
117
+ raise core.Fail(f"{rel} at {rev or 'the working tree'} is not valid YAML: {e}") from None
118
+
119
+
120
+ def run_kept(args) -> int:
121
+ repo = pathlib.Path(args.repo or ".").expanduser()
122
+ if not repo.is_dir():
123
+ raise core.Fail(f"--repo {repo}: not a directory")
124
+ rel = (args.file or DEFAULT_PATH).strip()
125
+ while rel.startswith("./"):
126
+ rel = rel[2:]
127
+ if not rel or pathlib.PurePosixPath(rel).is_absolute() or ".." in pathlib.PurePosixPath(rel).parts:
128
+ raise core.UsageError(f"--file {args.file!r}: a path inside the repository (no '..', not absolute)")
129
+ if args.against is not None and core.git(repo, "rev-parse", "--git-dir").returncode != 0:
130
+ raise core.Fail(f"--against needs a git repository; {repo} is not one")
131
+ doc, commit = read_doc(repo, rel, args.at)
132
+ view, raw, sha = kept_digest(doc)
133
+ payload = {"ok": True, "schema": SCHEMA, "file": rel, "at": args.at, "commit": commit,
134
+ "kept_view": view, "canonical": raw.decode("utf-8"), "sha256": sha,
135
+ "derived_paths": [".".join(p) for p in DERIVED_PATHS], "recipe": RECIPE,
136
+ "against": None, "changed_kept_keys": None, "same": None}
137
+ rc = 0
138
+ if args.against is not None:
139
+ old, old_commit = read_doc(repo, rel, args.against)
140
+ _v, _r, old_sha = kept_digest(old)
141
+ changed = changed_kept_keys(old, doc)
142
+ same = old_sha == sha
143
+ if not changed and not same: # a difference changed_kept_keys cannot name (deeper than one level)
144
+ changed = ["(kept view)"]
145
+ payload.update(against={"rev": args.against, "commit": old_commit, "sha256": old_sha},
146
+ changed_kept_keys=changed, same=not changed)
147
+ rc = 1 if changed else 0
148
+ if args.json_out:
149
+ core.print_json(payload)
150
+ return rc
151
+ print(json.dumps(view, sort_keys=True, indent=2, ensure_ascii=False))
152
+ where = f"{args.at} ({commit[:12]})" if commit else "working tree"
153
+ print(f"kept-view sha256 {sha} {rel} at {where}")
154
+ if args.against is not None:
155
+ a = payload["against"]
156
+ if changed:
157
+ print(f"changed kept key(s) since {args.against} ({a['commit'][:12]}): {', '.join(changed)}")
158
+ else:
159
+ print(f"kept view unchanged since {args.against} ({a['commit'][:12]}); only derived keys may differ")
160
+ return rc
161
+
162
+
163
+ def add_parser(fsub, add_json) -> None:
164
+ k = fsub.add_parser(
165
+ "kept", help="the canonical kept view of formalization.yaml (derived keys removed) and its SHA-256, for "
166
+ "a release-input audit; --against REV: exit 1 when a kept key changed (read-only)",
167
+ description="`lean-pkg formalization kept [--repo DIR] [--file REL] [--at REV] [--against REV2] [--json]`: "
168
+ "print formalization.yaml without the keys `formalization render` derives (formalization.DERIVED_PATHS "
169
+ "and the renderer's acknowledgements lines), as canonical JSON (sort_keys, separators ',' ':', UTF-8, "
170
+ "no trailing newline) and the SHA-256 of those bytes; the recipe is in docs/formalization.md, \"The kept "
171
+ "view\". --against REV2 lists the kept keys that differ from REV2 and exits 1 when any does. Reads no "
172
+ "registry; writes nothing")
173
+ k.add_argument("--repo", default=None, metavar="DIR",
174
+ help="the package checkout (default: the current directory)")
175
+ k.add_argument("--file", default=None, metavar="REL",
176
+ help=f"the file's path inside the checkout (default {DEFAULT_PATH})")
177
+ k.add_argument("--at", default=None, metavar="REV",
178
+ help="read the file committed at REV (git objects) instead of the working tree")
179
+ k.add_argument("--against", default=None, metavar="REV2",
180
+ help="compare with the file committed at REV2: changed_kept_keys, exit 1 when any")
181
+ add_json(k)
182
+ k.set_defaults(fn=run_kept, name=None)