|
| 1 | +#!/bin/bash |
| 2 | +set -e # Exit immediately if a command exits with a non-zero status. |
| 3 | + |
| 4 | +# --- Configuration --- |
| 5 | +PACKAGE_NAME="a2a" # The name of the package to import |
| 6 | +PYPI_PACKAGE_NAME="a2a-sdk" # The name on PyPI |
| 7 | +DOCS_SOURCE_DIR="docs/sdk/python" |
| 8 | +DOCS_BUILD_DIR="${DOCS_SOURCE_DIR}/_build" |
| 9 | +VENV_DIR=".doc-venv" |
| 10 | + |
| 11 | +echo "--- Setting up documentation build environment ---" |
| 12 | + |
| 13 | +# Create a clean virtual environment |
| 14 | +if [ -d "$VENV_DIR" ]; then |
| 15 | + rm -rf "$VENV_DIR" |
| 16 | +fi |
| 17 | +python3 -m venv "$VENV_DIR" |
| 18 | +source "$VENV_DIR/bin/activate" |
| 19 | + |
| 20 | +echo "--- Installing package and dependencies ---" |
| 21 | + |
| 22 | +# Upgrade pip and install documentation requirements |
| 23 | +pip install -U pip |
| 24 | +pip install -r "requirements-docs.txt" |
| 25 | + |
| 26 | +# Install the package itself |
| 27 | +pip install "${PYPI_PACKAGE_NAME}" |
| 28 | + |
| 29 | +echo "--- Finding installed package path ---" |
| 30 | + |
| 31 | +# Find the installation path of the package |
| 32 | +PACKAGE_PATH=$(python -c "import ${PACKAGE_NAME}, os; print(os.path.dirname(${PACKAGE_NAME}.__file__))") |
| 33 | +echo "Found '${PACKAGE_NAME}' at: ${PACKAGE_PATH}" |
| 34 | + |
| 35 | +echo "--- Generating API documentation source files (.rst) ---" |
| 36 | + |
| 37 | +# Run sphinx-apidoc on the installed package directory |
| 38 | +# -f: force overwrite of existing files |
| 39 | +# -e: put each module on its own page |
| 40 | +sphinx-apidoc -f -e -o "${DOCS_SOURCE_DIR}" "${PACKAGE_PATH}" |
| 41 | + |
| 42 | +echo "--- Building HTML documentation ---" |
| 43 | + |
| 44 | +# Build the HTML documentation |
| 45 | +sphinx-build -b html "${DOCS_SOURCE_DIR}" "${DOCS_BUILD_DIR}/html" |
| 46 | + |
| 47 | +# Deactivate the virtual environment |
| 48 | +deactivate |
| 49 | + |
| 50 | +echo "" |
| 51 | +echo "✅ Documentation build complete!" |
| 52 | +echo "View the docs by opening: ${DOCS_BUILD_DIR}/html/index.html" |
0 commit comments