Files
patroni/tox.ini
Matt Baker e796198045 Generate API docs from code with sphinx autodoc (#2699)
Expanding on the addition of docstrings in code, this adds python module API docs to sphinx documentation.

A developer can preview what this might look like by running this locally:

```
tox -m docs
```

The option `-W` is added to the tox env so that warning messages are considered errors.

Adds doc generation using the above method to the test GitHub workflow to catch documentation problems on PRs.

Some docstrings have been reformatted and fixed to satisfy errors generated with the above setup.
2023-09-20 12:35:14 +02:00

228 lines
5.5 KiB
INI

[common]
python_matrix = {36,37,38,39,310,311}
postgres_matrix =
pg11: PG_MAJOR = 11
pg12: PG_MAJOR = 12
pg13: PG_MAJOR = 13
pg14: PG_MAJOR = 14
pg15: PG_MAJOR = 15
pg16: PG_MAJOR = 16
psycopg_deps =
py{37,38,39,310,311}-{lin,win}: psycopg[binary]
mac: psycopg2-binary
py36: psycopg2-binary
platforms =
lin: linux
mac: darwin
win: win32
[tox]
min_version = 4.0
requires =
tox>4
env_list =
dep
lint
py{[common]python_matrix}-test-{lin,mac,win}
docs
skipsdist = True
toxworkdir = {env:TOX_WORK_DIR:.tox}
skip_missing_interpreters = True
[testenv]
setenv =
PYTHONDONTWRITEBYTECODE = 1
mac: OPEN_CMD = {env:OPEN_CMD:open}
lin: OPEN_CMD = {env:OPEN_CMD:xdg-open}
passenv =
BROWSER
DISPLAY
[testenv:lint]
description = Lint code with flake8
commands = flake8 {posargs:patroni tests setup.py}
deps =
flake8
[testenv:py{36,37,38,39,310,311}-test-{lin,win,mac}]
description = Run unit tests with pytest
labels =
test
commands_pre =
- {tty:rm -f "{toxworkdir}{/}cov_report_{env_name}_html{/}index.html":true}
- {tty:rm -f "{toxworkdir}{/}pytest_report_{env_name}.html":true}
commands =
pytest \
-p no:cacheprovider \
--verbose \
--doctest-modules \
--capture=fd \
--cov=patroni \
--cov-report=term-missing \
--cov-append \
{tty::--cov-report="xml\:{toxworkdir}{/}cov_report.{env_name}.xml"} \
{tty:--cov-report="html\:{toxworkdir}{/}cov_report_{env_name}_html":} \
{tty:--html="{toxworkdir}{/}pytest_report_{env_name}.html":} \
{posargs:tests patroni}
commands_post =
- {tty:{env:OPEN_CMD} "{toxworkdir}{/}cov_report_{env_name}_html{/}index.html":true}
- {tty:{env:OPEN_CMD} "{toxworkdir}{/}pytest_report_{env_name}.html":true}
deps =
-r requirements.txt
mock>=2.0.0
pytest
pytest-cov
pytest-html
{[common]psycopg_deps}
platform =
{[common]platforms}
allowlist_externals =
rm
true
{env:OPEN_CMD}
[testenv:dep]
description = Check package dependency problems
commands = pipdeptree -w fail
deps =
-r requirements.txt
pipdeptree
{[common]psycopg_deps}
[testenv:py{37,38,39,310,311}-type-{lin,mac,win}]
description = Run static type checking with pyright
labels =
type
deps =
-r requirements.txt
pyright
psycopg2-binary
psycopg[binary]
commands = pyright --venv-path {toxworkdir}{/}{envname} {posargs:patroni}
platform =
{[common]platforms}
[testenv:black]
description = Reformat code with black
deps = black
commands = black {posargs:patroni tests}
[testenv:pg{12,13,14,15,16}-docker-build]
description = Build docker containers needed for testing
labels =
behave
docker-build
setenv =
{[common]postgres_matrix}
DOCKER_BUILDKIT = 1
passenv =
BASE_IMAGE
commands =
docker build . \
--tag patroni-dev:{env:PG_MAJOR} \
--build-arg PG_MAJOR \
--build-arg BASE_IMAGE={env:BASE_IMAGE:postgres} \
--file features/Dockerfile
allowlist_externals = docker
[testenv:pg{12,13,14,15,16}-docker-behave-{etcd}-{lin,mac}]
description = Run behaviour tests in patroni-dev docker container
setenv =
etcd: DCS=etcd
{[common]postgres_matrix}
CONTAINER_NAME = tox-{env_name}-{env:PYTHONHASHSEED}
labels =
behave
depends =
pg{11,12,13,14,15,16}-docker-build
# There's a bug which affects calling multiple envs on the command line
# This should be a valid command: tox -e 'py{36,37,38,39,310,311}-behave-{env:DCS}-lin'
# Replaced with workaround, see https://github.com/tox-dev/tox/issues/2850
commands =
docker run \
--volume {tox_root}:/src \
--env DCS={env:DCS} \
--hostname {env:CONTAINER_NAME} \
--name {env:CONTAINER_NAME} \
--rm \
--tty \
{env:PATRONI_DEV_IMAGE:patroni-dev:{env:PG_MAJOR}} \
tox run -x 'tox.env_list=py{[common]python_matrix}-behave-{env:DCS}-lin' \
-- --format plain {posargs}
allowlist_externals =
docker
find
platform =
lin: linux
; win: win32
mac: darwin
[testenv:py{36,38,39,310,311}-behave-{etcd}-{lin,win,mac}]
description = Run behaviour tests (locally with tox)
deps =
-r requirements.txt
behave
coverage
{[common]psycopg_deps}
setenv =
DCS = {env:DCS:etcd}
passenv =
ETCD_UNSUPPORTED_ARCH
commands =
python3 -m behave {posargs}
platform =
{[common]platforms}
[testenv:docs-{lin,mac,win}]
description = Build Sphinx documentation in HTML format
labels:
docs
deps =
-r requirements.docs.txt
-r requirements.txt
psycopg[binary]
psycopg2-binary
commands =
sphinx-build \
-d "{envtmpdir}{/}doctree" docs "{toxworkdir}{/}docs_out" \
--color -b html \
-T -E -W --keep-going \
{posargs}
commands_post =
- {tty:{env:OPEN_CMD} "{toxworkdir}{/}docs_out{/}index.html":true:}
allowlist_externals =
true
{env:OPEN_CMD}
platform =
{[common]platforms}
[testenv:pdf-{lin,mac,win}]
description = Build Sphinx documentation in PDF format
labels:
docs
deps =
-r requirements.docs.txt
-r requirements.txt
psycopg[binary]
psycopg2-binary
commands =
python -m sphinx -T -E -b latex -d _build/doctrees -D language=en . pdf
- latexmk -r pdf/latexmkrc -cd -C pdf/Patroni.tex
latexmk -r pdf/latexmkrc -cd -pdf -f -dvi- -ps- -jobname=Patroni -interaction=nonstopmode pdf/Patroni.tex
commands_post =
- {tty:{env:OPEN_CMD} "pdf{/}Patroni.pdf":true:}
allowlist_externals =
true
latexmk
{env:OPEN_CMD}
platform =
{[common]platforms}
change_dir = docs
[flake8]
max-line-length = 120
ignore = D401,W503