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
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# lean-pkg-extract -- the write step shared by every lean-pkg-extract verb that writes a tree
|
|
2
|
+
"""The one way lean-pkg-extract writes an output tree (proposal 0009, stage S3; two-tracks gap 17).
|
|
3
|
+
|
|
4
|
+
`lean-pkg-extract decls --output DIR` uses it today; the file-level `write --output DIR` of gap 17 is
|
|
5
|
+
meant to use it too. The contract:
|
|
6
|
+
|
|
7
|
+
- `output_refusals(out, flag, protected)`: why DIR cannot be written, as a list (empty: it can). DIR
|
|
8
|
+
must be absent or an empty directory, must not be a symbolic link, its parent directory must exist,
|
|
9
|
+
and its resolved path must lie outside every protected tree (SRC's work tree and git directory: the
|
|
10
|
+
extraction tools leave SRC unchanged). Nothing is created by asking.
|
|
11
|
+
- `stage_path(out)`: the staging directory, beside DIR on the same filesystem (so the final move is
|
|
12
|
+
one `os.replace`): `.<DIR name>.lean-pkg-stage`. Its name is fixed, so a staging directory left by
|
|
13
|
+
an interrupted run is found and refused (`StagingCollision`), never silently reused or deleted.
|
|
14
|
+
- `write_tree(out, files, ...)`: creates the staging directory (exclusively), writes every file into
|
|
15
|
+
it, scans it with public-safety as `repo export` scans its staged tree (`ps.scan(..., export=True)`:
|
|
16
|
+
every file, the source repository's patterns file and declared addresses), and refuses on a blocking
|
|
17
|
+
hit (`WriteRefused`). Then `prepare(stage)` runs (for example `git init`), then `before_move(stage)`
|
|
18
|
+
(for example writing the ledger, which may return an undo callable), then one `os.replace(stage,
|
|
19
|
+
out)` puts the tree in place. Any failure on the way, a refusal or an exception, removes the
|
|
20
|
+
staging directory and undoes `before_move`: DIR is then exactly as it was (absent or empty), and
|
|
21
|
+
nothing half-written is left anywhere.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
import os
|
|
27
|
+
import pathlib
|
|
28
|
+
import shutil
|
|
29
|
+
from typing import Callable
|
|
30
|
+
|
|
31
|
+
from . import export_paths as xp
|
|
32
|
+
from . import public_safety as ps
|
|
33
|
+
|
|
34
|
+
STAGE_SUFFIX = ".lean-pkg-stage"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class WriteRefused(Exception):
|
|
38
|
+
"""The tree was not written; `reasons` says why (one line each). Nothing is left behind."""
|
|
39
|
+
|
|
40
|
+
def __init__(self, reasons: list[str], scan: dict | None = None):
|
|
41
|
+
super().__init__("; ".join(reasons))
|
|
42
|
+
self.reasons = reasons
|
|
43
|
+
self.scan = scan
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class StagingCollision(WriteRefused):
|
|
47
|
+
"""The staging directory beside DIR already exists (an interrupted run, or a concurrent one)."""
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _resolved(p: pathlib.Path) -> pathlib.Path:
|
|
51
|
+
"""p with its nearest existing ancestor resolved (symbolic links followed), the rest appended."""
|
|
52
|
+
p = p.absolute()
|
|
53
|
+
tail: list[str] = []
|
|
54
|
+
while not p.exists() and not p.is_symlink() and p != p.parent:
|
|
55
|
+
tail.append(p.name)
|
|
56
|
+
p = p.parent
|
|
57
|
+
return p.resolve().joinpath(*reversed(tail))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def output_refusals(out: pathlib.Path, flag: str, protected) -> list[str]:
|
|
61
|
+
"""Why `out` cannot receive a written tree (see the module docstring); [] when it can. `protected`
|
|
62
|
+
is [(what, path or None)]."""
|
|
63
|
+
shown = f"{flag} {out}"
|
|
64
|
+
if out.is_symlink():
|
|
65
|
+
return [f"{shown}: a symbolic link; name a new directory (the tree is never written through a link)"]
|
|
66
|
+
if out.exists() and not out.is_dir():
|
|
67
|
+
return [f"{shown}: exists and is not a directory; nothing written"]
|
|
68
|
+
refusals = []
|
|
69
|
+
if out.is_dir() and any(out.iterdir()):
|
|
70
|
+
refusals.append(f"{shown}: exists and is not empty; nothing written (name a new or empty directory)")
|
|
71
|
+
if not out.absolute().parent.is_dir():
|
|
72
|
+
refusals.append(f"{shown}: its parent directory does not exist")
|
|
73
|
+
real = _resolved(out)
|
|
74
|
+
for what, root in protected:
|
|
75
|
+
if root is None:
|
|
76
|
+
continue
|
|
77
|
+
r = root.resolve()
|
|
78
|
+
if real == r or r in real.parents:
|
|
79
|
+
refusals.append(f"{shown}: inside {what} (resolved: it lies under that tree); lean-pkg-extract "
|
|
80
|
+
f"leaves the source unchanged, so write outside it")
|
|
81
|
+
return refusals
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def stage_path(out: pathlib.Path) -> pathlib.Path:
|
|
85
|
+
out = out.absolute()
|
|
86
|
+
return out.parent / f".{out.name}{STAGE_SUFFIX}"
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def blob_rel_refusal(rel: str) -> str | None:
|
|
90
|
+
why = xp.bad_rel_path(rel)
|
|
91
|
+
return f"{rel}: {why}" if why else None
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def write_tree(out: pathlib.Path, files: dict[str, bytes], *, scan_pkg: dict, patterns_root: pathlib.Path | None,
|
|
95
|
+
source_repo: pathlib.Path | None, prepare: Callable[[pathlib.Path], None] | None = None,
|
|
96
|
+
before_move: Callable[[pathlib.Path], Callable[[], None] | None] | None = None) -> dict:
|
|
97
|
+
"""Write `files` (relative POSIX path -> bytes) as the tree `out`, through a staging directory beside it
|
|
98
|
+
(see the module docstring). Returns the public-safety scan of the staged tree. Raises WriteRefused
|
|
99
|
+
(StagingCollision for a leftover staging directory) or the OSError that stopped it; in every failing
|
|
100
|
+
case the staging directory is gone and `out` is as it was."""
|
|
101
|
+
bad = [r for r in (blob_rel_refusal(rel) for rel in sorted(files)) if r]
|
|
102
|
+
if bad:
|
|
103
|
+
raise WriteRefused([f"not written: {b}" for b in bad])
|
|
104
|
+
stage = stage_path(out)
|
|
105
|
+
collision = StagingCollision([f"the staging directory {stage.name} exists beside {out.name} (left by an "
|
|
106
|
+
f"interrupted run, or another run is writing): remove it after checking "
|
|
107
|
+
f"nothing is using it; nothing written"])
|
|
108
|
+
if stage.exists() or stage.is_symlink():
|
|
109
|
+
raise collision
|
|
110
|
+
try:
|
|
111
|
+
stage.mkdir()
|
|
112
|
+
except FileExistsError:
|
|
113
|
+
raise collision from None
|
|
114
|
+
undo: Callable[[], None] | None = None
|
|
115
|
+
try:
|
|
116
|
+
for rel in sorted(files):
|
|
117
|
+
f = stage / rel
|
|
118
|
+
f.parent.mkdir(parents=True, exist_ok=True)
|
|
119
|
+
with open(f, "xb") as fh:
|
|
120
|
+
fh.write(files[rel])
|
|
121
|
+
scan = ps.scan(scan_pkg, stage, export=True, patterns_root=patterns_root, source_repo=source_repo,
|
|
122
|
+
public_allow_root=stage)
|
|
123
|
+
blocking = ps.blocking(scan["hits"])
|
|
124
|
+
if blocking:
|
|
125
|
+
lines = [f"public-safety: {len(blocking)} blocking hit(s) in the staged tree; nothing written"]
|
|
126
|
+
lines += [f"public-safety:{ps.hit_line(h)}" for h in blocking]
|
|
127
|
+
raise WriteRefused(lines, scan)
|
|
128
|
+
if prepare is not None:
|
|
129
|
+
prepare(stage)
|
|
130
|
+
if before_move is not None:
|
|
131
|
+
undo = before_move(stage)
|
|
132
|
+
os.replace(stage, out)
|
|
133
|
+
return scan
|
|
134
|
+
except BaseException:
|
|
135
|
+
if undo is not None:
|
|
136
|
+
undo()
|
|
137
|
+
shutil.rmtree(stage, ignore_errors=True)
|
|
138
|
+
raise
|