forked from ChelseaKR/tods-validate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_i18n.py
More file actions
47 lines (36 loc) · 1.45 KB
/
Copy pathcheck_i18n.py
File metadata and controls
47 lines (36 loc) · 1.45 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
#!/usr/bin/env python3
"""Enforce the i18n N/A declaration.
Per STANDARDS/INTERNATIONALIZATION-STANDARD.md §1, a repo that declares i18n
N/A must ship docs/I18N.md carrying the marker `i18n status: N/A` and a
non-empty `Reason:` line. This gate fails (non-zero exit) if the file, the
marker, or the reason is missing, so the declaration cannot silently rot. CI
runs it alongside the other verify checks.
"""
from __future__ import annotations
import re
import sys
from pathlib import Path
DOC_PATH = Path(__file__).parent.parent / "docs" / "I18N.md"
STATUS_MARKER = "i18n status: N/A"
REASON_RE = re.compile(r"^Reason:[ \t]*(?P<reason>\S.*)$", re.MULTILINE)
def check() -> list[str]:
problems: list[str] = []
if not DOC_PATH.exists():
return [f"{DOC_PATH} is missing; an i18n N/A declaration is required (see §1)."]
text = DOC_PATH.read_text(encoding="utf-8")
if STATUS_MARKER not in text:
problems.append(f"{DOC_PATH}: missing the marker '{STATUS_MARKER}'.")
match = REASON_RE.search(text)
if match is None or not match.group("reason").strip():
problems.append(f"{DOC_PATH}: no non-empty 'Reason:' line.")
return problems
def main() -> int:
problems = check()
if problems:
for problem in problems:
print(problem, file=sys.stderr)
return 1
print(f"{DOC_PATH.name}: i18n N/A declaration present and valid")
return 0
if __name__ == "__main__":
raise SystemExit(main())