-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_generated_pyi_header.py
More file actions
73 lines (59 loc) · 2.38 KB
/
Copy pathcheck_generated_pyi_header.py
File metadata and controls
73 lines (59 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
"""Guard: every .pyi file under src/convert_sdk/_generated/ must carry the
AUTO-GENERATED marker on line 1.
This script mirrors the android/ruby pattern (android-sdk ci.yml:51 and
ruby-sdk scripts/check-generated-rbs-header.sh): it reads the first line of
each generated stub and fails fast if the AUTO-GENERATED marker is absent.
Why ALL stubs, including __init__.pyi:
Both serving_config.pyi and __init__.pyi were committed with the marker on
line 1 (verified at commit time). Treating them uniformly means a copy
operation that clobbers the header (or a manual edit that strips line 1) is
caught for every file in the directory, not only the data stub. No
exemptions needed — the empty __init__.pyi is also auto-generated by the
backend workflow (generate-pyi.js writes both files to dist-pyi/).
Usage:
uv run python scripts/check_generated_pyi_header.py
Exit codes:
0 all .pyi files carry the AUTO-GENERATED marker on line 1
1 one or more .pyi files are missing the marker (names printed to stderr)
"""
from __future__ import annotations
import sys
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent
GENERATED_DIR = REPO_ROOT / "src" / "convert_sdk" / "_generated"
MARKER = "AUTO-GENERATED"
def main() -> int:
pyi_files = sorted(GENERATED_DIR.glob("*.pyi"))
if not pyi_files:
print(
f"ERROR: no .pyi files found under {GENERATED_DIR}",
file=sys.stderr,
)
return 1
failures: list[Path] = []
for path in pyi_files:
try:
first_line = path.read_text(encoding="utf-8").splitlines()[0]
except (OSError, IndexError):
first_line = ""
if MARKER not in first_line:
failures.append(path)
print(
f"FAIL {path.relative_to(REPO_ROOT)}: "
f"line 1 does not contain '{MARKER}'",
file=sys.stderr,
)
if failures:
print(
f"\n{len(failures)} file(s) missing the AUTO-GENERATED marker. "
"Do not edit generated stubs by hand; "
"re-run the backend serving workflow to regenerate.",
file=sys.stderr,
)
return 1
checked = len(pyi_files)
print(f"OK {checked} .pyi file(s) carry the AUTO-GENERATED marker.")
return 0
if __name__ == "__main__":
raise SystemExit(main())