-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathcheck-env-docs.py
More file actions
executable file
·95 lines (81 loc) · 3.02 KB
/
Copy pathcheck-env-docs.py
File metadata and controls
executable file
·95 lines (81 loc) · 3.02 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations
import re
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
DOC = ROOT / "docs" / "env-vars.md"
REFERENCE_DOCS = [ROOT / "AGENTS.md", ROOT / "README.md", ROOT / "CONTRIBUTING.md"]
DIRECT_ENV = re.compile(
r'\b(?:std::)?env::var(?:_os)?\(\s*"(HIPFIRE_[A-Z0-9_]+)"\s*\)',
re.MULTILINE,
)
BOOTSTRAP_ENV = {
"HIPFIRE_HOME",
"HIPFIRE_MODELS_DIR",
"HIPFIRE_DAEMON_BIN",
"HIPFIRE_TUI_BIN",
"HIPFIRE_CLI_BIN",
"HIPFIRE_HF_BASE",
"HIPFIRE_REGISTRY_URL",
"HIPFIRE_NO_REGISTRY_FETCH",
"HIPFIRE_KERNEL_CACHE",
"HIPFIRE_SPILL_DIR",
"HIPFIRE_QUANT_DIAG_PATH",
# Read by the daemon's init_tracing() before the CLI has sent the process
# config; going through developer_var there installs the local fallback
# snapshot and makes the real install fail ("already initialized").
"HIPFIRE_LOG_FORMAT",
# Read by GpuLocks::open() before install_process_config() — the lock
# directory must be resolved before the config snapshot exists, and a
# developer_var read would install the local fallback early. Two daemons
# contending for a card must read the same ambient dir before either has
# its own config.
"HIPFIRE_LOCK_DIR",
}
CENTRAL_CONFIG_READERS = {
"crates/hipfire-config/src/lib.rs",
"crates/hipfire-runtime/src/config.rs",
"crates/rdna-compute/src/feature_flags.rs",
}
def env_vars(path: Path) -> set[str]:
text = path.read_text(encoding="utf-8", errors="ignore")
return set(re.findall(r"\bHIPFIRE_[A-Z0-9_]+\b", text))
def main() -> int:
canonical = DOC.read_text(encoding="utf-8", errors="ignore")
missing: list[tuple[str, str]] = []
for path in REFERENCE_DOCS:
for name in sorted(env_vars(path)):
if name not in canonical:
missing.append((path.relative_to(ROOT).as_posix(), name))
if missing:
print("docs/env-vars.md is missing HIPFIRE_* vars referenced by top-level docs:")
for path, name in missing:
print(f" {path}: {name}")
return 1
direct_reads: list[tuple[str, str]] = []
for path in (ROOT / "crates").rglob("*.rs"):
relative = path.relative_to(ROOT).as_posix()
if (
relative in CENTRAL_CONFIG_READERS
or path.name == "build.rs"
or "examples" in path.parts
or "tests" in path.parts
):
continue
text = path.read_text(encoding="utf-8", errors="ignore")
for name in DIRECT_ENV.findall(text):
if name not in BOOTSTRAP_ENV:
direct_reads.append((relative, name))
if direct_reads:
print("production HIPFIRE_* reads must use ProcessConfig/TOML:")
for path, name in sorted(direct_reads):
print(f" {path}: {name}")
return 1
print(
"env-docs: references covered; production HIPFIRE_* reads are config-owned"
)
return 0
if __name__ == "__main__":
sys.exit(main())