envvar-config-file¶
Nota
This is a test of https://github.com/readthedocs/readthedocs.org/issues/6311#issuecomment-1324426604 but it seems it does not work…
Use a hacky way to define environment variables in the .readthedocs.yaml
.
These are the variables defined in the YAML:
MYVAR1: | None |
---|---|
MYVAR2: | None |
MYVAR3: | None |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | version: 2 build: os: ubuntu-22.04 tools: python: "3" jobs: post_checkout: - echo "export MYVAR1=myvar1" >> ~/.bash_profile - echo "export MYVAR2=myvar2" >> ~/.bash_profile - echo "export MYVAR3=myvar3" >> ~/.bash_profile post_build: - env sphinx: configuration: docs/conf.py python: install: - requirements: requirements.txt |
Sphinx configuration file used to build this docs (see full file),
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import os # Default settings project = 'Test Builds' extensions = [ 'sphinx_autorun', ] # Include all your settings here html_theme = 'sphinx_rtd_theme' myvar1 = os.environ.get('MYVAR1') myvar2 = os.environ.get('MYVAR2') myvar3 = os.environ.get('MYVAR3') rst_epilog = f""" .. |myvar1| replace:: {myvar1} .. |myvar2| replace:: {myvar2} .. |myvar3| replace:: {myvar3} """ |
>>> # Build at
>>> import datetime
>>> datetime.datetime.utcnow() # UTC
datetime.datetime(2022, 11, 23, 9, 19, 43, 877619)