-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgenerate_python_sdk_docs.py
More file actions
64 lines (49 loc) · 1.9 KB
/
Copy pathgenerate_python_sdk_docs.py
File metadata and controls
64 lines (49 loc) · 1.9 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
"""Generate Python SDK reference stubs under docs/reference/python-sdk/.
Reads ``fathom.__all__`` and writes one short Markdown stub per public
symbol. Each stub uses a ``:::`` mkdocstrings directive so the actual
API reference (signatures, docstrings, type hints) is rendered at
``mkdocs build`` time from live source. Also writes an ``index.md``
landing page that links every symbol.
"""
from __future__ import annotations
import sys
from pathlib import Path
import fathom
DEFAULT_OUT = Path("docs/reference/python-sdk")
def _stub_body(qualname: str) -> str:
return f"# `fathom.{qualname}`\n\n::: fathom.{qualname}\n"
def _index_body(symbols: list[str]) -> str:
lines = [
"# Python SDK Reference",
"",
"Generated from `fathom.__all__` at docs-build time via mkdocstrings.",
"",
"## Public symbols",
"",
]
lines.extend(f"- [`{s}`]({s.lower()}.md)" for s in symbols)
lines.append("")
return "\n".join(lines)
def main(out_dir: Path) -> int:
out_dir.mkdir(parents=True, exist_ok=True)
# Clear previous run so deleted symbols don't leave orphan pages
for child in out_dir.iterdir():
if child.name == ".gitkeep":
continue
if child.is_dir():
# No nested dirs expected; be tolerant
for sub in child.rglob("*"):
if sub.is_file():
sub.unlink()
child.rmdir()
else:
child.unlink()
symbols = [s for s in fathom.__all__ if not s.startswith("_")]
for name in symbols:
(out_dir / f"{name.lower()}.md").write_text(_stub_body(name), encoding="utf-8")
(out_dir / "index.md").write_text(_index_body(symbols), encoding="utf-8")
print(f"wrote {len(symbols) + 1} Python SDK stubs under {out_dir}")
return 0
if __name__ == "__main__":
out = Path(sys.argv[1]) if len(sys.argv) > 1 else DEFAULT_OUT
sys.exit(main(out))