./scripts/<name>.py now sources activate when the inherited environment is missing or stale (scripts/_hermes-python) and runs under the pinned interpreter, so these work from a bare shell and any cwd. The fast path from an activated shell costs ~5ms over bare python. These all import repo or locked third-party code. CI invokes them as `python3 scripts/<name>.py` under setup-pm's environment, where the shebang is inert, so no require_activation() guard: that would fail those lanes, which run without __HERMES_ACTIVATED. Left out on purpose: keystroke_diagnostic.py (run by users inside their own install, where activation would provision their home) and docker_config_migrate.py (runs in the container through its venv python).
51 lines
1.7 KiB
Python
Executable File
51 lines
1.7 KiB
Python
Executable File
#!/usr/bin/env -S bash -c 'exec "$BASH" "$(dirname "$0")/_hermes-python" "$0" "$@"'
|
|
"""Regenerate apps/desktop/src/lib/desktop-slash-registry.json from COMMAND_REGISTRY.
|
|
|
|
Run after changing any ``desktop=`` value or alias in ``hermes_cli/commands.py``;
|
|
``tests/hermes_cli/test_desktop_slash_registry.py`` fails until the committed
|
|
copy matches. ``--check`` writes nothing and exits 1 when the committed JSON
|
|
differs from what the registry renders (the same verdict the pytest gives,
|
|
usable from any shell or CI step without pytest).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
OUT = ROOT / "apps" / "desktop" / "src" / "lib" / "desktop-slash-registry.json"
|
|
|
|
|
|
def render() -> str:
|
|
sys.path.insert(0, str(ROOT))
|
|
from hermes_cli.commands import desktop_surface_registry
|
|
|
|
return json.dumps(desktop_surface_registry(), indent=2, sort_keys=True) + "\n"
|
|
|
|
|
|
def check(out: Path = OUT) -> int:
|
|
"""0 when ``out`` matches the registry byte-for-byte, else 1 with a hint on stderr."""
|
|
committed = out.read_text(encoding="utf-8-sig") if out.exists() else ""
|
|
if committed == render():
|
|
return 0
|
|
rel = out.relative_to(ROOT) if out.is_relative_to(ROOT) else out
|
|
print(f"{rel} is stale — run scripts/dump_desktop_slash_registry.py", file=sys.stderr)
|
|
return 1
|
|
|
|
|
|
def main(argv: list[str]) -> int:
|
|
if argv == ["--check"]:
|
|
return check()
|
|
if argv:
|
|
print(f"usage: {Path(__file__).name} [--check]", file=sys.stderr)
|
|
return 2
|
|
OUT.write_text(render(), encoding="utf-8")
|
|
print(f"wrote {OUT.relative_to(ROOT)}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main(sys.argv[1:]))
|