A hack to run custom steps when building documentation on Read the Docs.
Project description
readthedocs-custom-steps
A hack to run custom steps when building documentation on Read the Docs.
Important: This module should not be installed outside of a Read the Docs build environment. It will rename your Python executable and install a substitute. It does not currently provide an automated way to revert this change.
Installation
This package must be installed only during the Read the Docs build process, for example as an extra requirement or through an additional requirements file.
Example:
# .readthedocs.yml
version: 2
mkdocs:
configuration: "docs/mkdocs.yml"
python:
version: "3.7"
install:
- path: "."
extra_requirements: [ "rtd" ]
How to use this?
RtdCS overrides your python installation with a Bash script that dispatches the
execution of custom steps upon invokation of python -m mkdocs or python -m sphinx.
The commands to run are either defined in pyproject.toml or in a file called
.readthedocs-custom-steps.yml (deprecated).
Example:
pyproject.toml |
.readthedocs-custom-steps.yml |
|---|---|
[tool.readthedocs-custom-steps]
script = """
bash .scripts/generate-changelog.sh >docs/changelog.md
python -m "$@"
"""
|
steps:
- bash .scripts/generate-changelog.sh >docs/changelog.md
- python -m "$@"
|
Here, $@ contains the arguments after python -m in the Read the Docs build step, for example:
mkdocs build --clean --site-dir _site/html --config-file mkdocs.ymlsphinx -T -b html -d _build/doctrees -D language=en . _build/html
An infinite recursion of this script invoking itself in the example above is prevented automatically
with the RTD_CUSTOM_ENTRY environment variable that is set before your script/steps are executed.
Configuration
If a pyproject.toml exists and it contains a [tool.readthedocs-custom-steps] section, the configuration
will be read from there. Otherwise, a file called .readthedocs-custom-steps.yml must exist and will be
searched for in the following locations:
.readthedocs-custom-steps.ymldocs/.readthedocs-custom-steps.yml- Relative to any directories from which requirements files are specified in the
.readthedocs.ymlfile under the$.python.install[*].requirementsconfiguration option.
Environment
In addition to passing the original arguments to the custom steps, RtdCS provides PYTHON environment variables
as detected from the ~/.pyenv/shims folder in the RTD build environment. (e.g. if there is a shim python3.6 and
python3.7, there'll be PYTHON, PYTHON36 and PYTHON37 environment variables, and PYTHON will point to 3.7).
Copyright © 2022 Niklas Rosenstein
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file readthedocs-custom-steps-0.6.2.tar.gz.
File metadata
- Download URL: readthedocs-custom-steps-0.6.2.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fbd57fa1faa533da7f3b3f504f9f11a58515e513b5480481dad59401b22ea4e
|
|
| MD5 |
37ad77fd9eb1b4a1a09e0614c1160dff
|
|
| BLAKE2b-256 |
753fe22bae7b7cf83042e4c22318cc5ae0cd04ac1f584186c073460a056a1a13
|