|
| 1 | +# Documentation Generation |
| 2 | + |
| 3 | +This directory contains Python scripts that generate the API reference pages for |
| 4 | +the GoodData Python SDK documentation site. |
| 5 | + |
| 6 | +## How it works |
| 7 | + |
| 8 | +The docs site is built with Hugo. API reference pages are generated in two steps: |
| 9 | + |
| 10 | +1. **`json_builder.py`** — introspects the installed `gooddata_sdk` and |
| 11 | + `gooddata_pandas` packages using `inspect`, producing a `data.json` file with |
| 12 | + class/function/property metadata and parsed docstrings. |
| 13 | +2. **`python_ref_builder.py`** — reads `data.json` and `api_spec.toml`, then |
| 14 | + generates markdown files with pre-rendered HTML for each module, class, and |
| 15 | + function. Jinja2 templates in `templates/` replicate the output of the former |
| 16 | + Hugo shortcodes, but at build time instead of at Hugo render time. |
| 17 | + |
| 18 | +The generated markdown files contain Hugo front matter (title, linkTitle, weight) |
| 19 | +and a `CONTENT` block with the full HTML. Hugo serves them as-is without needing |
| 20 | +shortcodes, `data.json`, or `links.json`. |
| 21 | + |
| 22 | +## Workflows |
| 23 | + |
| 24 | +There are three documentation deployment workflows, in order of |
| 25 | +preference: |
| 26 | + |
| 27 | +### 1. V2 parallel workflow (`netlify-deploy-v2.yaml`) — recommended |
| 28 | + |
| 29 | +Triggered manually via `workflow_dispatch`. |
| 30 | + |
| 31 | +``` |
| 32 | +discover-versions ──> generate-version (matrix, parallel) ──> build-and-deploy |
| 33 | +``` |
| 34 | + |
| 35 | +- `discover-versions.sh` finds the latest N release branches. |
| 36 | +- Each version runs in its own runner: checks out the version's SDK packages, |
| 37 | + installs master's `script-requirements.txt`, runs `json_builder.py` + |
| 38 | + `python_ref_builder.py` via `generate-single-version.sh`. |
| 39 | +- Per-version results are cached by `(scripts hash + templates hash + branch SHA)`. |
| 40 | +- `assemble-versions.sh` merges all version artifacts, promotes the highest |
| 41 | + numbered version to `/latest`, then Hugo builds the final site. |
| 42 | +- Deploys as a Netlify **draft** (no `--prod`). |
| 43 | + |
| 44 | +### 2. Legacy single-job workflow (`netlify-deploy.yaml`) — production |
| 45 | + |
| 46 | +Triggered manually via `workflow_dispatch`. |
| 47 | + |
| 48 | +- Uses `hugo-build-versioned-action` which downloads `generate.sh` from master. |
| 49 | +- `generate.sh` runs all versions sequentially in one job. |
| 50 | +- Deploys to Netlify with `--prod`. |
| 51 | + |
| 52 | +### 3. PR preview (`netlify-deploy-preview.yaml`) |
| 53 | + |
| 54 | +Triggered automatically on PRs that change `docs/**`. |
| 55 | + |
| 56 | +- Only builds the current branch's docs content (no multi-version). |
| 57 | +- Uses the simpler `hugo-build-action` (no API reference generation). |
| 58 | +- Deploys to a Netlify preview URL (`preview-{PR}--{site}.netlify.app`). |
| 59 | + |
| 60 | +## Local development |
| 61 | + |
| 62 | +Build and serve docs locally using Docker: |
| 63 | + |
| 64 | +```bash |
| 65 | +cd docs |
| 66 | +docker build -t python-sdk-docs -f Dockerfile .. |
| 67 | +docker run --rm -p 1313:1313 python-sdk-docs |
| 68 | +# Open http://localhost:1313/latest/ |
| 69 | +``` |
| 70 | + |
| 71 | +## Key files |
| 72 | + |
| 73 | +| File | Purpose | |
| 74 | +|------|---------| |
| 75 | +| `json_builder.py` | Introspects SDK packages into `data.json` | |
| 76 | +| `python_ref_builder.py` | Generates markdown + HTML from `data.json` | |
| 77 | +| `templates/*.html.j2` | Jinja2 templates (replicate old Hugo shortcodes) | |
| 78 | +| `tests/test_python_ref_builder.py` | Unit tests (`make test-docs-scripts`) | |
| 79 | +| `../script-requirements.txt` | Python dependencies for both scripts | |
| 80 | +| `../../docs/api_spec.toml` | Maps package names to output directories | |
| 81 | +| `../../docs/*_template.md` | Markdown front matter templates (module/class/function) | |
| 82 | + |
| 83 | +## Running tests |
| 84 | + |
| 85 | +```bash |
| 86 | +make test-docs-scripts |
| 87 | +``` |
0 commit comments