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,282 @@
1
+ """Which tracked files a Lake package's build reads, for the docs-only binding rule, and whether a nested
2
+ registered package is a build input of the package around it.
3
+
4
+ Both questions are answered from the files committed at a commit (`show(rel) -> bytes | None`, rel
5
+ relative to the package directory), never from the working tree, and both fail closed: when the answer
6
+ cannot be read precisely, the caller keeps the conservative rule.
7
+
8
+ Lake semantics followed (Lake 4.x, `LeanLibConfig.isLocalModule`, `Package.isBuildableModule`): a
9
+ `lean_lib` owns every module that has one of its `roots` as a prefix, or that matches one of its `globs`
10
+ (`Foo`, `Foo.*`, `Foo.+`); its sources live under the package `srcDir` joined with the library's
11
+ `srcDir` (both default "."); `roots` defaults to the library's name. A `lean_exe` owns its `root`
12
+ module (default: its name); its modules below that root are counted too (over-inclusive on purpose).
13
+ `input_file` / `input_dir` targets and `require` path dependencies inside the package make every file
14
+ under their path a build input. Only lakefile.toml is read: Lake prefers lakefile.lean when both exist,
15
+ and a lakefile.lean is code, so with one present the scope is unknown and every `*.lean` counts."""
16
+
17
+ from __future__ import annotations
18
+
19
+ import json
20
+ import posixpath
21
+ import re
22
+ import tomllib
23
+ from dataclasses import dataclass, field
24
+
25
+ # The array-of-tables keys of a lakefile.toml that declare targets or dependencies (Lake.Load.Toml).
26
+ # Any other array of tables is a declaration this reader does not know: the scope is then unknown.
27
+ KNOWN_TABLE_ARRAYS = ("lean_lib", "lean_exe", "input_file", "input_dir", "require")
28
+
29
+
30
+ @dataclass
31
+ class LakeScope:
32
+ """The modules and paths a package's build reads, as read from its lakefile.toml."""
33
+ # (source dir relative to the package, "" for the package dir; module-name prefix; target label)
34
+ modules: list[tuple[str, tuple[str, ...], str]] = field(default_factory=list)
35
+ # (path relative to the package; target label): every file at or under it is a build input
36
+ paths: list[tuple[str, str]] = field(default_factory=list)
37
+
38
+
39
+ def norm_dir(value) -> str | None:
40
+ """A package-relative directory as a normalized posix path ("" for the package directory itself), or
41
+ None when it is not a string, is absolute, or leaves the package directory."""
42
+ if not isinstance(value, str):
43
+ return None
44
+ v = value.replace("\\", "/").strip()
45
+ if v.startswith("/"):
46
+ return None
47
+ n = posixpath.normpath(v) if v else "."
48
+ if n == ".":
49
+ return ""
50
+ if n == ".." or n.startswith("../"):
51
+ return None
52
+ return n
53
+
54
+
55
+ def name_parts(value) -> list[tuple[str, ...]] | None:
56
+ """The module-name readings of a Lake name string: split at the dots outside «», and (a name that is
57
+ not a dotted identifier is a simple name in Lake) the whole string as one component. None when the
58
+ value is not a nonempty string."""
59
+ if not isinstance(value, str) or not value.strip():
60
+ return None
61
+ s = value.strip()
62
+ parts, cur, esc = [], "", False
63
+ for ch in s:
64
+ if ch == "«":
65
+ esc = True
66
+ elif ch == "»":
67
+ esc = False
68
+ elif ch == "." and not esc:
69
+ parts.append(cur)
70
+ cur = ""
71
+ continue
72
+ else:
73
+ cur += ch
74
+ parts.append(cur)
75
+ out = []
76
+ if all(parts):
77
+ out.append(tuple(parts))
78
+ whole = (s.replace("«", "").replace("»", ""),)
79
+ if whole not in out:
80
+ out.append(whole)
81
+ return out
82
+
83
+
84
+ def lake_dir_name(value) -> str | None:
85
+ """A lake-manifest.json package `name` as Lake's directory name for it, or None when it is not a Lake
86
+ name. Lake writes the name with Lean's `ToJson Name` (`toString`, escaped: `«dep-with-hyphens»`) and
87
+ checks the package out under `name.toString (escape := false)` (Lake/Load/Materialize.lean, `dirName`):
88
+ each component without its «», the components joined by ".". A component is either «...» (no » inside)
89
+ or a nonempty run without ".", "«" or "»"; anything else (an unterminated «, a stray », an empty
90
+ component) is not decoded."""
91
+ if not isinstance(value, str) or not value:
92
+ return None
93
+ parts, i, n = [], 0, len(value)
94
+ while True:
95
+ if i < n and value[i] == "«":
96
+ j = value.find("»", i + 1)
97
+ if j < 0 or j == i + 1:
98
+ return None
99
+ parts.append(value[i + 1:j])
100
+ i = j + 1
101
+ else:
102
+ j = i
103
+ while j < n and value[j] not in ".«»":
104
+ j += 1
105
+ if j == i:
106
+ return None
107
+ parts.append(value[i:j])
108
+ i = j
109
+ if i == n:
110
+ return ".".join(parts)
111
+ if value[i] != ".":
112
+ return None
113
+ i += 1
114
+
115
+
116
+ def glob_parts(value) -> list[tuple[str, ...]] | None:
117
+ """`Foo`, `Foo.*`, `Foo.+` as module-name prefixes (every glob kind is read as a prefix: a superset)."""
118
+ if not isinstance(value, str):
119
+ return None
120
+ s = value.strip()
121
+ if s.endswith((".*", ".+")):
122
+ s = s[:-2]
123
+ return name_parts(s)
124
+
125
+
126
+ def _str_list(value) -> list | None:
127
+ """Lake's `decodeArrayOrSingleton`: a string or an array of them; None for anything else."""
128
+ if isinstance(value, str):
129
+ return [value]
130
+ if isinstance(value, list) and all(isinstance(x, str) for x in value):
131
+ return value
132
+ return None
133
+
134
+
135
+ def scope_from_toml(text: str) -> tuple[LakeScope | None, str]:
136
+ """(scope, "") from lakefile.toml text, or (None, why) when it cannot be read precisely."""
137
+ try:
138
+ data = tomllib.loads(text)
139
+ except (ValueError, TypeError) as e:
140
+ return None, f"lakefile.toml does not parse ({str(e)[:60]})"
141
+ if not isinstance(data, dict):
142
+ return None, "lakefile.toml is not a table"
143
+ for k, v in data.items():
144
+ if k not in KNOWN_TABLE_ARRAYS and isinstance(v, list) and v and all(isinstance(x, dict) for x in v):
145
+ return None, f"lakefile.toml declares [[{k}]], which this reader does not know"
146
+ pkg_src = norm_dir(data.get("srcDir", "."))
147
+ if pkg_src is None:
148
+ return None, "lakefile.toml srcDir leaves the package directory"
149
+ scope = LakeScope()
150
+ for kind in KNOWN_TABLE_ARRAYS:
151
+ entries = data.get(kind, [])
152
+ if not isinstance(entries, list) or not all(isinstance(e, dict) for e in entries):
153
+ return None, f"lakefile.toml [[{kind}]] is not an array of tables"
154
+ for e in entries:
155
+ name = e.get("name")
156
+ if kind == "require":
157
+ src = e.get("source") if isinstance(e.get("source"), dict) else {}
158
+ raw = e.get("path", src.get("dir") if src.get("type") == "path" else None)
159
+ if raw is None:
160
+ continue
161
+ d = norm_dir(raw)
162
+ if d is None:
163
+ return None, f"require {name!r}: path {raw!r} leaves the package directory"
164
+ scope.paths.append((d, f"require {name} path"))
165
+ continue
166
+ if not isinstance(name, str) or not name.strip():
167
+ return None, f"lakefile.toml [[{kind}]] without a name"
168
+ if kind in ("input_file", "input_dir"):
169
+ d = norm_dir(e.get("path", name))
170
+ if d is None:
171
+ return None, f"{kind} {name}: path leaves the package directory"
172
+ scope.paths.append((d, f"{kind} {name}"))
173
+ continue
174
+ sd = norm_dir(e.get("srcDir", "."))
175
+ if sd is None:
176
+ return None, f"{kind} {name}: srcDir leaves the package directory"
177
+ src_dir = posixpath.join(pkg_src, sd) if pkg_src and sd else (pkg_src or sd)
178
+ if kind == "lean_lib":
179
+ roots = _str_list(e.get("roots", name))
180
+ globs = _str_list(e.get("globs", [])) if "globs" in e else []
181
+ if roots is None or globs is None:
182
+ return None, f"lean_lib {name}: roots/globs are not strings"
183
+ prefixes = []
184
+ for r in roots:
185
+ got = name_parts(r)
186
+ if got is None:
187
+ return None, f"lean_lib {name}: unreadable root {r!r}"
188
+ prefixes += got
189
+ for g in globs:
190
+ got = glob_parts(g)
191
+ if got is None:
192
+ return None, f"lean_lib {name}: unreadable glob {g!r}"
193
+ prefixes += got
194
+ else:
195
+ root = e.get("root", name)
196
+ prefixes = name_parts(root)
197
+ if prefixes is None:
198
+ return None, f"lean_exe {name}: unreadable root {root!r}"
199
+ for p in prefixes:
200
+ scope.modules.append((src_dir, p, f"{kind} {name}"))
201
+ if not scope.modules:
202
+ return None, "lakefile.toml declares no lean_lib or lean_exe"
203
+ return scope, ""
204
+
205
+
206
+ def lake_scope(show) -> tuple[LakeScope | None, str]:
207
+ """(scope, "") for the package whose committed files `show` reads, or (None, why) when the
208
+ conservative rule applies (a lakefile.lean, no lakefile.toml, or one this reader cannot read)."""
209
+ if show("lakefile.lean") is not None:
210
+ return None, "lakefile.lean"
211
+ raw = show("lakefile.toml")
212
+ if raw is None:
213
+ return None, "no lakefile.toml"
214
+ return scope_from_toml(raw.decode("utf-8", errors="replace"))
215
+
216
+
217
+ def _under(path: str, d: str) -> bool:
218
+ return d == "" or path == d or path.startswith(d + "/")
219
+
220
+
221
+ def scope_reason(scope: LakeScope, path: str) -> str | None:
222
+ """Why a package-relative path is a build input under `scope`, or None."""
223
+ for d, label in scope.paths:
224
+ if _under(path, d):
225
+ return label
226
+ if not path.endswith(".lean"):
227
+ return None
228
+ for src, prefix, label in scope.modules:
229
+ if src and not path.startswith(src + "/"):
230
+ continue
231
+ rel = path[len(src) + 1:] if src else path
232
+ mod = tuple(rel[:-len(".lean")].split("/"))
233
+ if mod[:len(prefix)] == prefix:
234
+ return label
235
+ return None
236
+
237
+
238
+ def overlaps(a: str, b: str) -> bool:
239
+ """Two package-relative paths where one is (under) the other; "" is the whole package."""
240
+ return a == b or _under(a, b) or _under(b, a)
241
+
242
+
243
+ def nested_dependency(show, rel: str) -> str | None:
244
+ """Why the package whose committed files `show` reads depends on (or reads) the nested directory
245
+ `rel`, or None when nothing it commits points there. Fails closed: an unreadable manifest or lakefile
246
+ is a reason."""
247
+ raw = show("lake-manifest.json")
248
+ if raw is not None:
249
+ try:
250
+ man = json.loads(raw.decode("utf-8", errors="replace"))
251
+ except ValueError:
252
+ return "lake-manifest.json is not valid JSON"
253
+ pkgs = man.get("packages") if isinstance(man, dict) else None
254
+ if pkgs is not None and not isinstance(pkgs, list):
255
+ return "lake-manifest.json packages is not a list"
256
+ for p in pkgs or []:
257
+ if isinstance(p, dict) and p.get("type") == "path":
258
+ d = norm_dir(p.get("dir"))
259
+ if d is None or overlaps(d, rel):
260
+ return f"lake-manifest.json path package {p.get('name')!r} (dir {p.get('dir')!r})"
261
+ lean = show("lakefile.lean")
262
+ if lean is not None:
263
+ text = lean.decode("utf-8", errors="replace")
264
+ for comp in {rel, rel.split("/")[0]}:
265
+ if re.search(rf"(?<![\w.'«]){re.escape(comp)}(?![\w'»])", text):
266
+ return f"lakefile.lean mentions {comp!r} (a lakefile.lean is code; read conservatively)"
267
+ raw = show("lakefile.toml")
268
+ if raw is not None:
269
+ scope, why = scope_from_toml(raw.decode("utf-8", errors="replace"))
270
+ if scope is None:
271
+ if why == "lakefile.toml declares no lean_lib or lean_exe":
272
+ scope = LakeScope()
273
+ else:
274
+ return why
275
+ for d, label in scope.paths:
276
+ if overlaps(d, rel):
277
+ return f"lakefile.toml {label} ({d or '.'})"
278
+ for src, prefix, label in scope.modules:
279
+ mdir = posixpath.join(src, *prefix) if src else posixpath.join(*prefix)
280
+ if overlaps(mdir, rel):
281
+ return f"lakefile.toml {label} (sources under {mdir})"
282
+ return None