forked from openai/openai-agents-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_ref_files.py
More file actions
77 lines (54 loc) · 2.21 KB
/
Copy pathgenerate_ref_files.py
File metadata and controls
77 lines (54 loc) · 2.21 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
#!/usr/bin/env python
"""
generate_ref_files.py
Create missing Markdown reference stubs for mkdocstrings.
Usage:
python scripts/generate_ref_files.py
"""
from pathlib import Path
# ---- Paths -----------------------------------------------------------
REPO_ROOT = Path(__file__).resolve().parent.parent.parent # adjust if layout differs
SRC_ROOT = REPO_ROOT / "src" / "agents" # source tree to scan
DOCS_ROOT = REPO_ROOT / "docs" / "ref" # where stubs go
# ---- Helpers ---------------------------------------------------------
def to_identifier(py_path: Path) -> str:
"""Convert src/agents/foo/bar.py -> 'agents.foo.bar'."""
rel = py_path.relative_to(SRC_ROOT).with_suffix("") # drop '.py'
return ".".join(("agents", *rel.parts))
def md_target(py_path: Path) -> Path:
"""Return docs/ref/.../*.md path corresponding to py_path."""
rel = py_path.relative_to(SRC_ROOT).with_suffix(".md")
return DOCS_ROOT / rel
def pretty_title(last_segment: str) -> str:
"""
Convert a module/file segment like 'tool_context' to 'Tool Context'.
Handles underscores and hyphens; leaves camelCase as‑is except first‑letter cap.
"""
cleaned = last_segment.replace("_", " ").replace("-", " ")
return cleaned.title()
# ---- Main ------------------------------------------------------------
def main() -> None:
if not SRC_ROOT.exists():
raise SystemExit(f"Source path not found: {SRC_ROOT}")
created = 0
for py_file in SRC_ROOT.rglob("*.py"):
if py_file.name.startswith("_"): # skip private files
continue
md_path = md_target(py_file)
if md_path.exists():
continue # keep existing
md_path.parent.mkdir(parents=True, exist_ok=True)
identifier = to_identifier(py_file)
title = pretty_title(identifier.split(".")[-1]) # last segment
md_content = f"""# `{title}`
::: {identifier}
"""
md_path.write_text(md_content, encoding="utf-8")
created += 1
print(f"Created {md_path.relative_to(REPO_ROOT)}")
if created == 0:
print("All reference files were already present.")
else:
print(f"Done. {created} new file(s) created.")
if __name__ == "__main__":
main()