Wire cli/docs.py build/serve/generate commands to run extraction scripts and Docusaurus. Add extract_cli.py (27 CLI docs from typer help), extract_openapi.py (8 REST API docs from FastAPI schema), extract_citations.py (14 pipeline pages with bib references), extract_dag.py (pipeline + table lineage Mermaid diagrams). Closes #26, #27, #28, #29, #30.
102 lines
2.6 KiB
Python
102 lines
2.6 KiB
Python
"""stack docs — documentation generation and serving."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import typer
|
|
|
|
app = typer.Typer(no_args_is_help=True)
|
|
|
|
DOCS_DIR = Path(__file__).resolve().parent.parent.parent / "docs"
|
|
SCRIPTS_DIR = DOCS_DIR / "scripts"
|
|
|
|
|
|
def _run_script(name: str) -> bool:
|
|
"""Run a docs generation script via uv. Returns True on success."""
|
|
script = SCRIPTS_DIR / name
|
|
if not script.exists():
|
|
typer.echo(f" skip: {name} not found")
|
|
return False
|
|
|
|
typer.echo(f" running {name}...")
|
|
|
|
# griffe is needed for extract_docs
|
|
extras = ["--with", "griffe"] if name == "extract_docs.py" else []
|
|
|
|
result = subprocess.run(
|
|
["uv", "run", *extras, "python", str(script)],
|
|
cwd=str(DOCS_DIR.parent),
|
|
)
|
|
return result.returncode == 0
|
|
|
|
|
|
def _generate() -> None:
|
|
"""Run all documentation generation scripts."""
|
|
typer.echo("Generating documentation content...")
|
|
scripts = [
|
|
"extract_docs.py",
|
|
"extract_cli.py",
|
|
"extract_openapi.py",
|
|
"extract_citations.py",
|
|
"extract_dag.py",
|
|
"export_library.py",
|
|
]
|
|
ok = 0
|
|
for s in scripts:
|
|
if _run_script(s):
|
|
ok += 1
|
|
typer.echo(f"Generated: {ok}/{len(scripts)} scripts succeeded")
|
|
|
|
|
|
@app.command()
|
|
def build(
|
|
skip_generate: bool = typer.Option(
|
|
False,
|
|
"--skip-generate",
|
|
help="Skip content generation, only run Docusaurus build.",
|
|
),
|
|
) -> None:
|
|
"""Generate documentation site."""
|
|
if not skip_generate:
|
|
_generate()
|
|
|
|
typer.echo("Building Docusaurus site...")
|
|
npm = "npm.cmd" if sys.platform == "win32" else "npm"
|
|
result = subprocess.run(
|
|
[npm, "run", "build"],
|
|
cwd=str(DOCS_DIR),
|
|
)
|
|
if result.returncode != 0:
|
|
typer.echo("Docusaurus build failed. Is node/npm installed?")
|
|
typer.echo(f" docs dir: {DOCS_DIR}")
|
|
raise typer.Exit(1)
|
|
typer.echo("docs build complete")
|
|
|
|
|
|
@app.command()
|
|
def serve(
|
|
port: int = typer.Option(3000, help="Port to serve on."),
|
|
skip_generate: bool = typer.Option(
|
|
False, "--skip-generate", help="Skip content generation."
|
|
),
|
|
) -> None:
|
|
"""Serve documentation locally with hot reload."""
|
|
if not skip_generate:
|
|
_generate()
|
|
|
|
typer.echo(f"Starting Docusaurus dev server on port={port}...")
|
|
npm = "npm.cmd" if sys.platform == "win32" else "npm"
|
|
subprocess.run(
|
|
[npm, "start", "--", "--port", str(port)],
|
|
cwd=str(DOCS_DIR),
|
|
)
|
|
|
|
|
|
@app.command()
|
|
def generate() -> None:
|
|
"""Generate documentation content without building the site."""
|
|
_generate()
|