|
| 1 | +# Documentation |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +To install the necessary dependencies, please run `pip install -e .[docs]`. |
| 6 | +You can then do the following: |
| 7 | + |
| 8 | +1. `make dev`: Generate the docs for the current version |
| 9 | +2. `make github`: Build the docs for tagged versions, `master` and `dev` in a sequential fashion |
| 10 | +3. `make parallel`: As `make github`, but builds occur in parallel (see below for details) |
| 11 | + |
| 12 | +The docs will be copied to `../docs`. |
| 13 | + |
| 14 | +## Build process |
| 15 | + |
| 16 | +In this section, the goals and constraints for the build process are described. |
| 17 | + |
| 18 | +Goals: |
| 19 | + |
| 20 | +- (semi-)automated documentation generation |
| 21 | +- multi-version documentation |
| 22 | +- runnable as a GitHub action |
| 23 | + |
| 24 | +Constraints: |
| 25 | + |
| 26 | +- GitHub actions have limited disk space (14GB) |
| 27 | + |
| 28 | +### Considerations |
| 29 | + |
| 30 | +For building the documentation, we need to install a given BayesFlow |
| 31 | +version/branch, its dependencies and the documentation dependencies into |
| 32 | +a virtual environment. As the dependencies differ, we cannot share the |
| 33 | +environments between versions. |
| 34 | + |
| 35 | +[sphinx-polyversion](https://github.com/real-yfprojects/sphinx-polyversion/) is a compact standalone tool that handles this case in a customizable manner. |
| 36 | + |
| 37 | +### Setup |
| 38 | + |
| 39 | +Please refer to the [sphinx-polyversion documentation](https://real-yfprojects.github.io/sphinx-polyversion/1.0.0/index.html) |
| 40 | +for a getting started tutorial and general documentation. |
| 41 | +Important locations are the following: |
| 42 | + |
| 43 | +- `poly.py`: Contains the polyversion-specific configuration. |
| 44 | +- `pre-build.py`: Build script to move files from other locations to `source`. |
| 45 | + Shared between all versions. |
| 46 | +- `source/conf.py`: Contains the sphinx-specific configuration. Will be copied |
| 47 | + from the currently checked-out branch, and shared between all versions. |
| 48 | + This enables a unified look and avoids having to add commits to old versions. |
| 49 | +- `polyversion/`: Polyversion-specific files, currently only redirect template. |
| 50 | +- `Makefile`/`make.bat`: Define commands to build different configurations. |
| 51 | + |
| 52 | +### Building |
| 53 | + |
| 54 | +For the multi-version docs, there are two ways to build them, which can be |
| 55 | +configured by setting the `BF_DOCS_SEQUENTIAL_BUILDS` environment variable. |
| 56 | + |
| 57 | +#### Parallel Builds (Default) |
| 58 | + |
| 59 | +This is the faster, but more resource intensive way. All builds run in parallel, |
| 60 | +in different virtual environments which are cached between runs. |
| 61 | +Therefore it needs a lot of space (around 20GB), some memory, and the runtime |
| 62 | +is determined by the slowest build. |
| 63 | + |
| 64 | +#### Sequential Builds |
| 65 | + |
| 66 | +By setting the environment variable `BF_DOCS_SEQUENTIAL_BUILDS=1`, a |
| 67 | +resource-constrained approach is chosen. Builds are sequential, and the |
| 68 | +virtual environment is deleted after the build. This overcomes the disk space |
| 69 | +limitations in the GitHub actions, at the cost of slightly higher built times |
| 70 | +(currently about 30 minutes). The variable can be set in the following way, |
| 71 | +which is used in `make github`: |
| 72 | + |
| 73 | +```bash |
| 74 | +BF_DOCS_SEQUENTIAL_BUILDS=1 sphinx-polyversion -vv poly.py |
| 75 | +``` |
| 76 | + |
| 77 | +### Internals |
| 78 | + |
| 79 | +We customize the creation and loading of the virtual environment to have |
| 80 | +one environment per revision (`DynamicPip`). We also create a variant that |
| 81 | +removes the environment after leaving it (`DestructingDynamicPip`). This |
| 82 | +enables freeing disk space in sequential builds. |
| 83 | + |
| 84 | +As only the contents of a revision, but not the `.git` folder is copied |
| 85 | +for the build, we have to supply `SETUPTOOLS_SCM_PRETEND_VERSION_FOR_BAYESFLOW` |
| 86 | +with a version, otherwise `setuptools-scm` will fail when running |
| 87 | +`pip install -e .`. To enable this, we accept and set environment variables |
| 88 | +in `DynamicPip`. |
| 89 | + |
| 90 | +The environments are created in `VENV_DIR_NAME`, and only removed if they are |
| 91 | +in this directory. |
| 92 | + |
| 93 | +For sequential builds, define the `SynchronousDriver` class, which builds the |
| 94 | +revisions sequentially. |
| 95 | + |
| 96 | +For all other details, please refer to `poly.py` and the code of `sphinx-polyversion`. |
| 97 | + |
| 98 | +This text was written by @vpratz, if you have any questions feel free to reach out. |
0 commit comments