-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathgen_meta.py
More file actions
43 lines (33 loc) · 1.17 KB
/
gen_meta.py
File metadata and controls
43 lines (33 loc) · 1.17 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
#!/usr/bin/env python3
from __future__ import annotations
import json
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SCHEMA_DIR = ROOT / "schema"
VERSION_FILE = SCHEMA_DIR / "VERSION"
def main() -> None:
generate_meta()
def generate_meta() -> None:
meta_json = SCHEMA_DIR / "meta.json"
out_py = ROOT / "src" / "acp" / "meta.py"
if not meta_json.exists():
raise SystemExit("schema/meta.json not found. Run gen_schema.py first.")
data = json.loads(meta_json.read_text("utf-8"))
agent_methods = data.get("agentMethods", {})
client_methods = data.get("clientMethods", {})
version = data.get("version", 1)
header_lines = ["# Generated from schema/meta.json. Do not edit by hand."]
if VERSION_FILE.exists():
ref = VERSION_FILE.read_text("utf-8").strip()
if ref:
header_lines.append(f"# Schema ref: {ref}")
out_py.write_text(
"\n".join(header_lines)
+ "\n"
+ f"AGENT_METHODS = {agent_methods!r}\n"
+ f"CLIENT_METHODS = {client_methods!r}\n"
+ f"PROTOCOL_VERSION = {int(version)}\n",
encoding="utf-8",
)
if __name__ == "__main__":
main()