template-press 3.0.0__tar.gz → 3.2.0__tar.gz
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.
- {template_press-3.0.0 → template_press-3.2.0}/PKG-INFO +1 -1
- {template_press-3.0.0 → template_press-3.2.0}/pyproject.toml +2 -2
- {template_press-3.0.0 → template_press-3.2.0}/src/template_press/press_cli.py +4 -0
- {template_press-3.0.0 → template_press-3.2.0}/src/template_press/rebrand/cli.py +132 -54
- {template_press-3.0.0 → template_press-3.2.0}/src/template_press/rebrand/config.py +27 -0
- {template_press-3.0.0 → template_press-3.2.0}/src/template_press/rebrand/discovery.py +29 -4
- {template_press-3.0.0 → template_press-3.2.0}/src/template_press/rebrand/doctor.py +58 -4
- template_press-3.2.0/src/template_press/rebrand/engine.py +558 -0
- template_press-3.2.0/src/template_press/rebrand/ignores.py +221 -0
- template_press-3.2.0/src/template_press/rebrand/matcher.py +90 -0
- {template_press-3.0.0 → template_press-3.2.0}/src/template_press/rebrand/receipt.py +2 -4
- {template_press-3.0.0 → template_press-3.2.0}/src/template_press/rebrand/rules.py +4 -1
- template_press-3.2.0/src/template_press/rebrand/safety.py +531 -0
- template_press-3.2.0/src/template_press/rebrand/sandbox.py +167 -0
- template_press-3.2.0/src/template_press/rebrand/synthesize.py +236 -0
- template_press-3.2.0/src/template_press/rebrand/verifier.py +271 -0
- template_press-3.2.0/src/template_press/rebrand/verify_cli.py +398 -0
- template_press-3.2.0/src/template_press/rebrand/verify_config.py +153 -0
- template_press-3.0.0/src/template_press/rebrand/engine.py +0 -258
- {template_press-3.0.0 → template_press-3.2.0}/README.md +0 -0
- {template_press-3.0.0 → template_press-3.2.0}/src/template_press/__init__.py +0 -0
- {template_press-3.0.0 → template_press-3.2.0}/src/template_press/py.typed +0 -0
- {template_press-3.0.0 → template_press-3.2.0}/src/template_press/rebrand/__init__.py +0 -0
- {template_press-3.0.0 → template_press-3.2.0}/src/template_press/rebrand/identity.py +0 -0
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
[project]
|
|
21
21
|
name = "template_press"
|
|
22
22
|
# ITM-070 — static version (ADR-06 cutover). release-please bumps this.
|
|
23
|
-
version = "3.
|
|
23
|
+
version = "3.2.0"
|
|
24
24
|
description = "Standalone rebrand utility — press a new identity onto an external target repo"
|
|
25
25
|
readme = "README.md"
|
|
26
26
|
requires-python = ">=3.12"
|
|
@@ -95,7 +95,7 @@ Issues = "https://github.com/smorinlabs/template-press/issues"
|
|
|
95
95
|
|
|
96
96
|
# ITM-073 — uv_build (ADR-06 cutover; replaces Hatchling + hatch-vcs).
|
|
97
97
|
[build-system]
|
|
98
|
-
requires = ["uv_build>=0.
|
|
98
|
+
requires = ["uv_build>=0.11.28,<1.0"]
|
|
99
99
|
build-backend = "uv_build"
|
|
100
100
|
|
|
101
101
|
# ITM-074 — uv_build module configuration.
|
|
@@ -11,6 +11,7 @@ import sys
|
|
|
11
11
|
|
|
12
12
|
from template_press import __version__
|
|
13
13
|
from template_press.rebrand import cli as rebrand_cli
|
|
14
|
+
from template_press.rebrand import verify_cli
|
|
14
15
|
|
|
15
16
|
_RESERVED = {"provision", "status"}
|
|
16
17
|
|
|
@@ -19,6 +20,7 @@ usage: press <command> [options]
|
|
|
19
20
|
|
|
20
21
|
commands:
|
|
21
22
|
rebrand press an identity onto a target repo (press rebrand --help)
|
|
23
|
+
verify check that a template presses cleanly (press verify --help)
|
|
22
24
|
provision configure a target's features (coming in M6)
|
|
23
25
|
status report a target's provisioned state (coming in M6)
|
|
24
26
|
"""
|
|
@@ -35,6 +37,8 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
35
37
|
verb, rest = args[0], args[1:]
|
|
36
38
|
if verb == "rebrand":
|
|
37
39
|
return rebrand_cli.main(rest)
|
|
40
|
+
if verb == "verify":
|
|
41
|
+
return verify_cli.verify_command(rest)
|
|
38
42
|
if verb in _RESERVED:
|
|
39
43
|
print(
|
|
40
44
|
f"error: '{verb}' is part of the Provision phase and is not "
|
|
@@ -12,6 +12,7 @@ import argparse
|
|
|
12
12
|
import subprocess # nosec B404 — invokes git/uv on user-supplied targets
|
|
13
13
|
import sys
|
|
14
14
|
import tomllib
|
|
15
|
+
from dataclasses import dataclass
|
|
15
16
|
from pathlib import Path
|
|
16
17
|
|
|
17
18
|
from template_press.rebrand.config import (
|
|
@@ -22,10 +23,22 @@ from template_press.rebrand.config import (
|
|
|
22
23
|
)
|
|
23
24
|
from template_press.rebrand.discovery import discover, mismatches
|
|
24
25
|
from template_press.rebrand.doctor import find_leaks, render_leak_report
|
|
25
|
-
from template_press.rebrand.engine import
|
|
26
|
+
from template_press.rebrand.engine import (
|
|
27
|
+
ApplyReport,
|
|
28
|
+
apply,
|
|
29
|
+
build_plan,
|
|
30
|
+
stray_press_dirs,
|
|
31
|
+
)
|
|
26
32
|
from template_press.rebrand.identity import Identity, ValidationError, token_occurs
|
|
27
33
|
from template_press.rebrand.receipt import read_receipt, write_receipt
|
|
28
34
|
from template_press.rebrand.rules import DEFAULT_RULES, Rules, load_rules
|
|
35
|
+
from template_press.rebrand.safety import (
|
|
36
|
+
SafetyError,
|
|
37
|
+
git_hardening_args,
|
|
38
|
+
scrubbed_git_env,
|
|
39
|
+
scrubbed_uv_env,
|
|
40
|
+
write_control,
|
|
41
|
+
)
|
|
29
42
|
|
|
30
43
|
|
|
31
44
|
def _fail(msg: str) -> int:
|
|
@@ -45,11 +58,24 @@ def check_preconditions(target: Path, force: bool, allow_dirty: bool) -> str | N
|
|
|
45
58
|
"re-press with --force"
|
|
46
59
|
)
|
|
47
60
|
if not allow_dirty:
|
|
61
|
+
# A working-tree read on an untrusted target: hardening args
|
|
62
|
+
# neutralize fsmonitor/hooksPath/ext-transport, but a repo-local
|
|
63
|
+
# clean/smudge FILTER definition is a documented residual
|
|
64
|
+
# (git_hardening_args' docstring) that `-c` cannot disable by name —
|
|
65
|
+
# accepted here, not solved.
|
|
48
66
|
status = subprocess.run( # noqa: S603 # nosec B603 B607
|
|
49
|
-
[
|
|
67
|
+
[ # noqa: S607
|
|
68
|
+
"git",
|
|
69
|
+
"-C",
|
|
70
|
+
str(target),
|
|
71
|
+
*git_hardening_args(),
|
|
72
|
+
"status",
|
|
73
|
+
"--porcelain",
|
|
74
|
+
],
|
|
50
75
|
check=True,
|
|
51
76
|
capture_output=True,
|
|
52
77
|
text=True,
|
|
78
|
+
env=scrubbed_git_env(),
|
|
53
79
|
)
|
|
54
80
|
if status.stdout.strip():
|
|
55
81
|
return "target working tree is dirty; commit/stash or --allow-dirty"
|
|
@@ -179,6 +205,16 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
179
205
|
rules = load_rules(target)
|
|
180
206
|
plan = build_plan(target, source, dest, rules)
|
|
181
207
|
print(plan.render())
|
|
208
|
+
strays = stray_press_dirs(target)
|
|
209
|
+
if strays:
|
|
210
|
+
print(
|
|
211
|
+
"warning: these press/ director(ies) are NOT this tool's "
|
|
212
|
+
"control dir (no press-*.toml marker); their contents are "
|
|
213
|
+
"rewritten and leak-scanned as ordinary content — review:",
|
|
214
|
+
file=sys.stderr,
|
|
215
|
+
)
|
|
216
|
+
for stray in strays:
|
|
217
|
+
print(f" {stray}", file=sys.stderr)
|
|
182
218
|
if args.dry_run:
|
|
183
219
|
if write_pending:
|
|
184
220
|
print(f"(dry run) would write {SOURCE_CONFIG_REL} from discovery")
|
|
@@ -188,27 +224,18 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
188
224
|
# behind us, so the deferred source-config write can no longer be
|
|
189
225
|
# followed by a "no writes" exit code.
|
|
190
226
|
if write_pending:
|
|
191
|
-
|
|
192
|
-
path.parent.mkdir(parents=True, exist_ok=True)
|
|
193
|
-
path.write_text(render_source_config(source), encoding="utf-8")
|
|
227
|
+
write_control(target, SOURCE_CONFIG_REL, render_source_config(source))
|
|
194
228
|
print(f"wrote {SOURCE_CONFIG_REL} from discovery")
|
|
195
229
|
except (
|
|
196
230
|
ValidationError,
|
|
197
231
|
tomllib.TOMLDecodeError,
|
|
198
232
|
OSError,
|
|
199
233
|
subprocess.CalledProcessError,
|
|
234
|
+
SafetyError,
|
|
200
235
|
) as exc:
|
|
201
236
|
return _fail(str(exc))
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
except (OSError, subprocess.CalledProcessError) as exc:
|
|
205
|
-
# Exit 2 means "nothing applied"; a mid-apply failure is not that.
|
|
206
|
-
print(
|
|
207
|
-
f"error: {exc} — target may be PARTIALLY rewritten; restore with "
|
|
208
|
-
f"`git -C {target} checkout . && git clean -fd`",
|
|
209
|
-
file=sys.stderr,
|
|
210
|
-
)
|
|
211
|
-
return 1
|
|
237
|
+
outcome = _press(target, source, dest, rules)
|
|
238
|
+
return 1 if (outcome.env_error is not None or outcome.leaked) else 0
|
|
212
239
|
|
|
213
240
|
|
|
214
241
|
def _regenerate_lockfiles(target: Path, rules: Rules, report: ApplyReport) -> list[str]:
|
|
@@ -220,7 +247,14 @@ def _regenerate_lockfiles(target: Path, rules: Rules, report: ApplyReport) -> li
|
|
|
220
247
|
"""
|
|
221
248
|
failed: list[str] = []
|
|
222
249
|
for lockfile in rules.regenerate:
|
|
223
|
-
|
|
250
|
+
lockpath = target / lockfile
|
|
251
|
+
if lockpath.is_symlink(): # lstat-based, no-follow — check first
|
|
252
|
+
report.skipped.append(
|
|
253
|
+
f"regenerate {lockfile} (symlink — refusing to write through)"
|
|
254
|
+
)
|
|
255
|
+
failed.append(lockfile)
|
|
256
|
+
continue
|
|
257
|
+
if not lockpath.is_file():
|
|
224
258
|
continue
|
|
225
259
|
if lockfile == "uv.lock":
|
|
226
260
|
result = subprocess.run( # nosec B603 B607
|
|
@@ -228,6 +262,7 @@ def _regenerate_lockfiles(target: Path, rules: Rules, report: ApplyReport) -> li
|
|
|
228
262
|
cwd=target,
|
|
229
263
|
capture_output=True,
|
|
230
264
|
text=True,
|
|
265
|
+
env=scrubbed_uv_env(), # G5: no UV_* override can steer the write
|
|
231
266
|
)
|
|
232
267
|
if result.returncode == 0:
|
|
233
268
|
report.regenerated.append(lockfile)
|
|
@@ -240,47 +275,90 @@ def _regenerate_lockfiles(target: Path, rules: Rules, report: ApplyReport) -> li
|
|
|
240
275
|
return failed
|
|
241
276
|
|
|
242
277
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
278
|
+
@dataclass
|
|
279
|
+
class PressOutcome:
|
|
280
|
+
"""Structurally distinguishes an env/tool failure from a doctor leak.
|
|
281
|
+
|
|
282
|
+
`renamed`/`regenerated` carry `ApplyReport` provenance through to callers
|
|
283
|
+
even on failure (empty when `apply` itself never completed).
|
|
284
|
+
"""
|
|
285
|
+
|
|
286
|
+
leaked: bool
|
|
287
|
+
renamed: list[tuple[str, str]]
|
|
288
|
+
regenerated: list[str]
|
|
289
|
+
env_error: str | None
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def _press(
|
|
293
|
+
target: Path, source: Identity, dest: Identity, rules: Rules
|
|
294
|
+
) -> PressOutcome:
|
|
295
|
+
report = None
|
|
296
|
+
try:
|
|
297
|
+
report = apply(target, source, dest, rules)
|
|
298
|
+
failed_locks = _regenerate_lockfiles(target, rules, report)
|
|
299
|
+
if failed_locks:
|
|
300
|
+
print(
|
|
301
|
+
f"error: lockfile regeneration failed for "
|
|
302
|
+
f"{', '.join(failed_locks)} — the lockfile still carries the old "
|
|
303
|
+
f"identity and is exempt from the doctor scan, so this rebrand "
|
|
304
|
+
f"is INCOMPLETE; no receipt written. Regenerate it, then re-run "
|
|
305
|
+
f"with --force.",
|
|
306
|
+
file=sys.stderr,
|
|
307
|
+
)
|
|
308
|
+
print(report.render(), file=sys.stderr)
|
|
309
|
+
return PressOutcome(
|
|
310
|
+
False,
|
|
311
|
+
report.renamed,
|
|
312
|
+
report.regenerated,
|
|
313
|
+
env_error=f"lockfile regeneration failed for {', '.join(failed_locks)}",
|
|
314
|
+
)
|
|
315
|
+
# Verification never honors target-side REWRITE exclusions (EMP-01):
|
|
316
|
+
# neither extra_exclude_files nor extra_exclude_dirs can hide content
|
|
317
|
+
# from the doctor. The only sanctioned exemption is the explicit,
|
|
318
|
+
# committed verify_ignore list — the deliberate ignore set.
|
|
319
|
+
doctor_rules = Rules(
|
|
320
|
+
exclude_dirs=DEFAULT_RULES.exclude_dirs | rules.verify_ignore,
|
|
321
|
+
exclude_files=DEFAULT_RULES.exclude_files,
|
|
322
|
+
regenerate=rules.regenerate,
|
|
323
|
+
verify_ignore=rules.verify_ignore,
|
|
324
|
+
)
|
|
325
|
+
leaks = find_leaks(target, source, doctor_rules, dest=dest)
|
|
326
|
+
if leaks:
|
|
327
|
+
print(render_leak_report(leaks), file=sys.stderr)
|
|
328
|
+
print(report.render(), file=sys.stderr)
|
|
329
|
+
return PressOutcome(
|
|
330
|
+
True, report.renamed, report.regenerated, env_error=None
|
|
331
|
+
)
|
|
332
|
+
receipt_path = write_receipt(target, source, dest, report)
|
|
333
|
+
write_control(target, SOURCE_CONFIG_REL, render_source_config(dest))
|
|
334
|
+
print(report.render())
|
|
335
|
+
if report.skipped:
|
|
336
|
+
print("skipped (review):")
|
|
337
|
+
for entry in report.skipped:
|
|
338
|
+
print(f" {entry}")
|
|
339
|
+
print(f"verified: no identity leftovers. receipt: {receipt_path}")
|
|
340
|
+
print(f"updated {SOURCE_CONFIG_REL} to the new identity")
|
|
341
|
+
return PressOutcome(False, report.renamed, report.regenerated, env_error=None)
|
|
342
|
+
except (
|
|
343
|
+
FileNotFoundError,
|
|
344
|
+
OSError,
|
|
345
|
+
subprocess.CalledProcessError,
|
|
346
|
+
SafetyError,
|
|
347
|
+
) as exc:
|
|
348
|
+
# Exit 2 (main's pre-_press gate) means "nothing applied"; a
|
|
349
|
+
# mid-mutation failure here is not that — target may be PARTIALLY
|
|
350
|
+
# rewritten.
|
|
247
351
|
print(
|
|
248
|
-
f"error:
|
|
249
|
-
f"{
|
|
250
|
-
f"identity and is exempt from the doctor scan, so this rebrand "
|
|
251
|
-
f"is INCOMPLETE; no receipt written. Regenerate it, then re-run "
|
|
252
|
-
f"with --force.",
|
|
352
|
+
f"error: {exc} — target may be PARTIALLY rewritten; restore with "
|
|
353
|
+
f"`git -C {target} checkout . && git clean -fd`",
|
|
253
354
|
file=sys.stderr,
|
|
254
355
|
)
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
doctor_rules = Rules(
|
|
262
|
-
exclude_dirs=DEFAULT_RULES.exclude_dirs | rules.verify_ignore,
|
|
263
|
-
exclude_files=DEFAULT_RULES.exclude_files,
|
|
264
|
-
regenerate=rules.regenerate,
|
|
265
|
-
verify_ignore=rules.verify_ignore,
|
|
266
|
-
)
|
|
267
|
-
leaks = find_leaks(target, source, doctor_rules, dest=dest)
|
|
268
|
-
if leaks:
|
|
269
|
-
print(render_leak_report(leaks), file=sys.stderr)
|
|
270
|
-
print(report.render(), file=sys.stderr)
|
|
271
|
-
return 1
|
|
272
|
-
receipt_path = write_receipt(target, source, dest, report)
|
|
273
|
-
source_config_path = target / SOURCE_CONFIG_REL
|
|
274
|
-
source_config_path.parent.mkdir(parents=True, exist_ok=True)
|
|
275
|
-
source_config_path.write_text(render_source_config(dest), encoding="utf-8")
|
|
276
|
-
print(report.render())
|
|
277
|
-
if report.skipped:
|
|
278
|
-
print("skipped (review):")
|
|
279
|
-
for entry in report.skipped:
|
|
280
|
-
print(f" {entry}")
|
|
281
|
-
print(f"verified: no identity leftovers. receipt: {receipt_path}")
|
|
282
|
-
print(f"updated {SOURCE_CONFIG_REL} to the new identity")
|
|
283
|
-
return 0
|
|
356
|
+
return PressOutcome(
|
|
357
|
+
False,
|
|
358
|
+
report.renamed if report else [],
|
|
359
|
+
report.regenerated if report else [],
|
|
360
|
+
env_error=str(exc),
|
|
361
|
+
)
|
|
284
362
|
|
|
285
363
|
|
|
286
364
|
if __name__ == "__main__":
|
|
@@ -11,11 +11,37 @@ from __future__ import annotations
|
|
|
11
11
|
import tomllib
|
|
12
12
|
from pathlib import Path
|
|
13
13
|
|
|
14
|
+
from template_press.rebrand.engine import ROOT_CONTROL
|
|
14
15
|
from template_press.rebrand.identity import Identity, ValidationError
|
|
16
|
+
from template_press.rebrand.safety import ContainmentError, assert_under_root
|
|
15
17
|
|
|
16
18
|
SOURCE_CONFIG_REL = Path("press") / "press-source.toml"
|
|
17
19
|
|
|
18
20
|
|
|
21
|
+
def assert_control_real(target: Path) -> None:
|
|
22
|
+
"""Reject a control dir / artifact that is (or hides behind) a symlink (D8).
|
|
23
|
+
|
|
24
|
+
The control location is tool-managed and must be REAL: a symlinked
|
|
25
|
+
``press/`` (or a symlinked control artifact inside it) could redirect a
|
|
26
|
+
control-file WRITE out of the target tree, or make a control-file READ
|
|
27
|
+
trust external content. Called once at the top of the shared load path
|
|
28
|
+
(``load_source_config``) so both rebrand's resolve/write-from-discovery
|
|
29
|
+
and (later) verify's preflight are guarded. Raises ``ContainmentError``
|
|
30
|
+
(a ``SafetyError``/``ValueError``) → the CLI maps it to exit 2.
|
|
31
|
+
"""
|
|
32
|
+
control = target / "press"
|
|
33
|
+
# No symlinked ancestor and the leaf itself is not a symlink (no-follow
|
|
34
|
+
# lstat walk); the belt-and-suspenders is_symlink covers the present-leaf
|
|
35
|
+
# case explicitly.
|
|
36
|
+
assert_under_root(control, target)
|
|
37
|
+
if control.is_symlink():
|
|
38
|
+
raise ContainmentError(f"control dir is a symlink: {control}")
|
|
39
|
+
for rel in ROOT_CONTROL:
|
|
40
|
+
artifact = target / rel
|
|
41
|
+
if artifact.is_symlink():
|
|
42
|
+
raise ContainmentError(f"control artifact is a symlink: {artifact}")
|
|
43
|
+
|
|
44
|
+
|
|
19
45
|
def toml_string(value: str) -> str:
|
|
20
46
|
"""Render a str as a TOML basic-string literal (quoted, escaped)."""
|
|
21
47
|
out = []
|
|
@@ -46,6 +72,7 @@ def load_identity_toml(path: Path, table: str) -> Identity:
|
|
|
46
72
|
|
|
47
73
|
|
|
48
74
|
def load_source_config(target: Path, override: Path | None) -> Identity | None:
|
|
75
|
+
assert_control_real(target)
|
|
49
76
|
path = override if override is not None else target / SOURCE_CONFIG_REL
|
|
50
77
|
if not path.is_file():
|
|
51
78
|
return None
|
|
@@ -16,6 +16,7 @@ from dataclasses import dataclass
|
|
|
16
16
|
from pathlib import Path
|
|
17
17
|
|
|
18
18
|
from template_press.rebrand.identity import Identity
|
|
19
|
+
from template_press.rebrand.safety import git_hardening_args, scrubbed_git_env
|
|
19
20
|
|
|
20
21
|
_ORIGIN_RE = re.compile(
|
|
21
22
|
r"^(?:https?://github\.com/|git@github\.com:)"
|
|
@@ -26,19 +27,33 @@ _ORIGIN_RE = re.compile(
|
|
|
26
27
|
@dataclass(frozen=True)
|
|
27
28
|
class Discovered:
|
|
28
29
|
package_name: str | None
|
|
29
|
-
app_name: str | None
|
|
30
|
+
app_name: str | None # FIRST [project.scripts] key, for display/back-compat
|
|
30
31
|
owner: str | None
|
|
31
32
|
repo_name: str | None
|
|
32
33
|
author: str | None
|
|
33
34
|
email: str | None
|
|
34
35
|
layout: str | None # "src" | "flat" | None
|
|
36
|
+
app_names: tuple[str, ...] = () # ALL [project.scripts] keys, insertion order
|
|
35
37
|
|
|
36
38
|
|
|
37
39
|
def _origin(target: Path) -> tuple[str | None, str | None]:
|
|
40
|
+
# A config read on an untrusted target (its .git/config is attacker
|
|
41
|
+
# input) — scrubbed env blocks a poisoned global config from redirecting
|
|
42
|
+
# this; hardening args are cheap insurance even though this is not a
|
|
43
|
+
# working-tree read.
|
|
38
44
|
result = subprocess.run( # noqa: S603 # nosec B603 B607
|
|
39
|
-
[
|
|
45
|
+
[ # noqa: S607
|
|
46
|
+
"git",
|
|
47
|
+
"-C",
|
|
48
|
+
str(target),
|
|
49
|
+
*git_hardening_args(),
|
|
50
|
+
"remote",
|
|
51
|
+
"get-url",
|
|
52
|
+
"origin",
|
|
53
|
+
],
|
|
40
54
|
capture_output=True,
|
|
41
55
|
text=True,
|
|
56
|
+
env=scrubbed_git_env(),
|
|
42
57
|
)
|
|
43
58
|
if result.returncode != 0:
|
|
44
59
|
return None, None
|
|
@@ -48,6 +63,7 @@ def _origin(target: Path) -> tuple[str | None, str | None]:
|
|
|
48
63
|
|
|
49
64
|
def discover(target: Path) -> Discovered:
|
|
50
65
|
package_name = app_name = author = email = None
|
|
66
|
+
app_names: tuple[str, ...] = ()
|
|
51
67
|
pyproject_path = target / "pyproject.toml"
|
|
52
68
|
if pyproject_path.is_file():
|
|
53
69
|
data = tomllib.loads(pyproject_path.read_text(encoding="utf-8"))
|
|
@@ -57,7 +73,8 @@ def discover(target: Path) -> Discovered:
|
|
|
57
73
|
package_name = raw_name.replace("-", "_")
|
|
58
74
|
scripts = project.get("scripts", {})
|
|
59
75
|
if isinstance(scripts, dict) and scripts:
|
|
60
|
-
|
|
76
|
+
app_names = tuple(str(k) for k in scripts)
|
|
77
|
+
app_name = app_names[0] # first key — display/back-compat
|
|
61
78
|
authors = project.get("authors", [])
|
|
62
79
|
if authors and isinstance(authors[0], dict):
|
|
63
80
|
author = authors[0].get("name")
|
|
@@ -77,6 +94,7 @@ def discover(target: Path) -> Discovered:
|
|
|
77
94
|
author=author,
|
|
78
95
|
email=email,
|
|
79
96
|
layout=layout,
|
|
97
|
+
app_names=app_names,
|
|
80
98
|
)
|
|
81
99
|
|
|
82
100
|
|
|
@@ -85,7 +103,6 @@ def mismatches(source: Identity, found: Discovered) -> list[str]:
|
|
|
85
103
|
out: list[str] = []
|
|
86
104
|
checks: tuple[tuple[str, str | None], ...] = (
|
|
87
105
|
("package_name", found.package_name),
|
|
88
|
-
("app_name", found.app_name),
|
|
89
106
|
("owner", found.owner),
|
|
90
107
|
("repo_name", found.repo_name),
|
|
91
108
|
("author", found.author),
|
|
@@ -101,6 +118,14 @@ def mismatches(source: Identity, found: Discovered) -> list[str]:
|
|
|
101
118
|
f"{declared[field_name]!r} but target shows "
|
|
102
119
|
f"{discovered_value!r}"
|
|
103
120
|
)
|
|
121
|
+
# app_name matches when it is ANY [project.scripts] key (membership),
|
|
122
|
+
# not just the first (F3/D2) — a target may expose several scripts and
|
|
123
|
+
# commit a non-first one. Empty app_names -> undiscoverable, unchallenged.
|
|
124
|
+
if found.app_names and declared["app_name"] not in found.app_names:
|
|
125
|
+
out.append(
|
|
126
|
+
f"app_name: source-config says {declared['app_name']!r} but "
|
|
127
|
+
f"target [project.scripts] exposes {list(found.app_names)!r}"
|
|
128
|
+
)
|
|
104
129
|
if found.package_name is not None and found.layout is None:
|
|
105
130
|
out.append(
|
|
106
131
|
f"layout: pyproject declares {found.package_name!r} but neither "
|
|
@@ -8,14 +8,24 @@ no receipt. Port of init_doctor.check_no_identity_leftover, generalized to
|
|
|
8
8
|
|
|
9
9
|
from __future__ import annotations
|
|
10
10
|
|
|
11
|
+
import os
|
|
11
12
|
from dataclasses import dataclass
|
|
12
13
|
from pathlib import Path
|
|
13
14
|
|
|
14
|
-
from template_press.rebrand.engine import
|
|
15
|
+
from template_press.rebrand.engine import (
|
|
16
|
+
_git_listed,
|
|
17
|
+
_is_root_press,
|
|
18
|
+
iter_target_files,
|
|
19
|
+
)
|
|
15
20
|
from template_press.rebrand.identity import Identity, token_occurs
|
|
16
21
|
from template_press.rebrand.rules import Rules
|
|
17
22
|
|
|
18
|
-
PATH_FIELDS: tuple[str, ...] = (
|
|
23
|
+
PATH_FIELDS: tuple[str, ...] = (
|
|
24
|
+
"package_name",
|
|
25
|
+
"repo_name",
|
|
26
|
+
"app_name",
|
|
27
|
+
"app_name_upper",
|
|
28
|
+
)
|
|
19
29
|
|
|
20
30
|
|
|
21
31
|
@dataclass(frozen=True)
|
|
@@ -23,7 +33,7 @@ class Leak:
|
|
|
23
33
|
path: str
|
|
24
34
|
field: str
|
|
25
35
|
value: str
|
|
26
|
-
where: str # "content" | "path" | "unverifiable"
|
|
36
|
+
where: str # "content" | "path" | "symlink" | "unverifiable"
|
|
27
37
|
|
|
28
38
|
|
|
29
39
|
def _read_for_scan(path: Path) -> str | None:
|
|
@@ -58,6 +68,7 @@ def find_leaks(
|
|
|
58
68
|
if dest is not None:
|
|
59
69
|
dest_fields = dest.as_dict()
|
|
60
70
|
fields = {k: v for k, v in fields.items() if v != dest_fields[k]}
|
|
71
|
+
covered_symlinks: set[str] = set()
|
|
61
72
|
for path in iter_target_files(target, rules):
|
|
62
73
|
rel = path.relative_to(target)
|
|
63
74
|
rel_posix = rel.as_posix()
|
|
@@ -70,11 +81,54 @@ def find_leaks(
|
|
|
70
81
|
for field_name, value in fields.items():
|
|
71
82
|
if token_occurs(text, field_name, value):
|
|
72
83
|
leaks.append(Leak(rel_posix, field_name, value, "content"))
|
|
73
|
-
|
|
84
|
+
if path.is_symlink():
|
|
85
|
+
# A symlink's bytes are its target string, not file content — an
|
|
86
|
+
# identity token embedded there would dangle/leak in a pressed fork.
|
|
87
|
+
covered_symlinks.add(rel_posix)
|
|
88
|
+
link = os.readlink(path)
|
|
89
|
+
for field_name, value in fields.items():
|
|
90
|
+
if token_occurs(link, field_name, value):
|
|
91
|
+
leaks.append(Leak(rel_posix, field_name, value, "symlink"))
|
|
92
|
+
for i, component in enumerate(rel.parts):
|
|
93
|
+
if _is_root_press(rel, i):
|
|
94
|
+
continue
|
|
74
95
|
for field_name in PATH_FIELDS:
|
|
75
96
|
value = fields.get(field_name)
|
|
76
97
|
if value is not None and token_occurs(component, field_name, value):
|
|
77
98
|
leaks.append(Leak(rel_posix, field_name, value, "path"))
|
|
99
|
+
# DIRECTORY and DANGLING symlinks never reach the loop above:
|
|
100
|
+
# `iter_target_files` keeps only `is_file()` paths, and `is_file()` FOLLOWS
|
|
101
|
+
# the link — so a symlink to a dir (or to nothing) is dropped, and a source
|
|
102
|
+
# token embedded in its link string would slip the gate. Scan every
|
|
103
|
+
# git-listed symlink's `readlink` STRING here (never the destination),
|
|
104
|
+
# deduping the symlink-to-file links the loop already covered.
|
|
105
|
+
for rel in _git_listed(target):
|
|
106
|
+
rel_posix = rel.as_posix()
|
|
107
|
+
if rel_posix in covered_symlinks:
|
|
108
|
+
continue
|
|
109
|
+
path = target / rel
|
|
110
|
+
if not path.is_symlink():
|
|
111
|
+
continue
|
|
112
|
+
# The NAME of a dir/dangling symlink is never scanned by the main loop
|
|
113
|
+
# (iter_target_files drops non-is_file paths), so scan its path
|
|
114
|
+
# components here exactly as Pass 1 does — a source token in the link's
|
|
115
|
+
# OWN name would otherwise slip the gate. (symlink-to-file names are
|
|
116
|
+
# already covered above via covered_symlinks.)
|
|
117
|
+
for i, component in enumerate(rel.parts):
|
|
118
|
+
if _is_root_press(rel, i):
|
|
119
|
+
continue
|
|
120
|
+
for field_name in PATH_FIELDS:
|
|
121
|
+
value = fields.get(field_name)
|
|
122
|
+
if value is not None and token_occurs(component, field_name, value):
|
|
123
|
+
leaks.append(Leak(rel_posix, field_name, value, "path"))
|
|
124
|
+
try:
|
|
125
|
+
link = os.readlink(path)
|
|
126
|
+
except OSError:
|
|
127
|
+
leaks.append(Leak(rel_posix, "io", "unreadable", "unverifiable"))
|
|
128
|
+
continue
|
|
129
|
+
for field_name, value in fields.items():
|
|
130
|
+
if token_occurs(link, field_name, value):
|
|
131
|
+
leaks.append(Leak(rel_posix, field_name, value, "symlink"))
|
|
78
132
|
return leaks
|
|
79
133
|
|
|
80
134
|
|