openai/chatkit-python

Public

mirrored fromhttps://github.com/openai/chatkit-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.6.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

docs/gen_ref_pages.py

58lines · modecode

1from pathlib import Path
2
3import mkdocs_gen_files
4
5SRC_ROOT = Path("chatkit")
6URL_ROOT = Path("api") / "chatkit"
7DOCS_ROOT = Path("docs")
8MANUAL_DOCS_ROOT = DOCS_ROOT / URL_ROOT
9
10if MANUAL_DOCS_ROOT.exists():
11 MANUAL_DOCS = {
12 path.relative_to(DOCS_ROOT) for path in MANUAL_DOCS_ROOT.rglob("*.md")
13 }
14else:
15 MANUAL_DOCS = set()
16
17# Root index page for the package
18root_doc = URL_ROOT / "index.md"
19if root_doc not in MANUAL_DOCS:
20 with mkdocs_gen_files.open(root_doc, "w") as f:
21 f.write("# chatkit\n\n")
22 f.write("::: chatkit\n")
23else:
24 mkdocs_gen_files.set_edit_path(root_doc, DOCS_ROOT / root_doc)
25
26for path in SRC_ROOT.rglob("*.py"):
27 if path.name.startswith("_"):
28 continue
29 if path.name in {"version.py", "logger.py", "actions.py"}:
30 continue
31
32 module_path = path.with_suffix("").relative_to(SRC_ROOT)
33 identifier = ".".join(("chatkit", *module_path.parts))
34 doc_path = (URL_ROOT / module_path).with_suffix(".md")
35
36 if doc_path in MANUAL_DOCS:
37 mkdocs_gen_files.set_edit_path(doc_path, DOCS_ROOT / doc_path)
38 continue
39
40 mkdocs_gen_files.set_edit_path(doc_path, path)
41 with mkdocs_gen_files.open(doc_path, "w") as f:
42 f.write(f"# {path.stem}\n\n")
43
44 # For the widgets module, keep the module-level directive but only include
45 # a curated set of public members so we preserve nice headings.
46 if identifier == "chatkit.widgets":
47 f.write(f"::: {identifier}\n")
48 f.write(" options:\n")
49 f.write(" members:\n")
50 for symbol in (
51 "WidgetTemplate",
52 "DynamicWidgetRoot",
53 "BasicRoot",
54 "DynamicWidgetComponent",
55 ):
56 f.write(f" - {symbol}\n")
57 else:
58 f.write(f"::: {identifier}\n")
59