···744744 unittestFlags = [ "-s" "tests" "-v" ];
745745```
746746747747+##### Using sphinxHook {#using-sphinxhook}
748748+749749+The `sphinxHook` is a helpful tool to build documentation and manpages
750750+using the popular Sphinx documentation generator.
751751+It is setup to automatically find common documentation source paths and
752752+render them using the default `html` style.
753753+754754+```
755755+ outputs = [
756756+ "out"
757757+ "doc"
758758+ ];
759759+760760+ nativeBuildInputs = [
761761+ sphinxHook
762762+ ];
763763+```
764764+765765+The hook will automatically build and install the artifact into the
766766+`doc` output, if it exists. It also provides an automatic diversion
767767+for the artifacts of the `man` builder into the `man` target.
768768+769769+```
770770+ outputs = [
771771+ "out"
772772+ "doc"
773773+ "man"
774774+ ];
775775+776776+ # Use multiple builders
777777+ sphinxBuilders = [
778778+ "singlehtml"
779779+ "man"
780780+ ];
781781+```
782782+783783+Overwrite `sphinxRoot` when the hook is unable to find your
784784+documentation source root.
785785+786786+```
787787+ # Configure sphinxRoot for uncommon paths
788788+ sphinxRoot = "weird/docs/path";
789789+```
790790+791791+The hook is also available to packages outside the python ecosystem by
792792+referencing it using `python3.pkgs.sphinxHook`.
793793+747794### Develop local package {#develop-local-package}
748795749796As a Python developer you're likely aware of [development mode](http://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode)
···12701317- `pytestCheckHook` to run tests with `pytest`. See [example usage](#using-pytestcheckhook).
12711318- `pythonCatchConflictsHook` to check whether a Python package is not already existing.
12721319- `pythonImportsCheckHook` to check whether importing the listed modules works.
13201320+- `pythonRelaxDepsHook` will relax Python dependencies restrictions for the package.
13211321+ See [example usage](#using-pythonrelaxdepshook).
12731322- `pythonRemoveBinBytecode` to remove bytecode from the `/bin` folder.
12741323- `setuptoolsBuildHook` to build a wheel using `setuptools`.
12751324- `setuptoolsCheckHook` to run tests with `python setup.py test`.
13251325+- `sphinxHook` to build documentation and manpages using Sphinx.
12761326- `venvShellHook` to source a Python 3 `venv` at the `venvDir` location. A
12771327 `venv` is created if it does not yet exist. `postVenvCreation` can be used to
12781328 to run commands only after venv is first created.
12791329- `wheelUnpackHook` to move a wheel to the correct folder so it can be installed
12801330 with the `pipInstallHook`.
12811281-- `pythonRelaxDepsHook` will relax Python dependencies restrictions for the package.
12821282- See [example usage](#using-pythonrelaxdepshook).
12831331- `unittestCheckHook` will run tests with `python -m unittest discover`. See [example usage](#using-unittestcheckhook).
1284133212851333### Development mode {#development-mode}
···11-# This hook automatically finds Sphinx documentation, builds it in html format
22-# and installs it.
33-#
44-# This hook knows about several popular locations in which subdirectory
55-# documentation may be, but in very unusual cases $sphinxRoot directory can be
66-# set explicitly.
77-#
88-# Name of the directory relative to ${doc:-$out}/share/doc is normally also
99-# deduced automatically, but can be overridden with $sphinxOutdir variable.
1010-#
1111-# Sphinx build system can depend on arbitrary amount of python modules, client
1212-# code is responsible for ensuring that all dependencies are present.
11+# shellcheck shell=bash
22+echo "Sourcing sphinx-hook"
33+44+declare -a __sphinxBuilders
135146buildSphinxPhase() {
1515- local __sphinxRoot="" o
77+ echo "Executing buildSphinxPhase"
16899+ local __sphinxRoot=""
1710 runHook preBuildSphinx
1111+1812 if [[ -n "${sphinxRoot:-}" ]] ; then # explicit root
1913 if ! [[ -f "${sphinxRoot}/conf.py" ]] ; then
2014 echo 2>&1 "$sphinxRoot/conf.py: no such file"
···2216 fi
2317 __sphinxRoot=$sphinxRoot
2418 else
2525- for o in doc docs doc/source docs/source ; do
2626- if [[ -f "$o/conf.py" ]] ; then
2727- echo "Sphinx documentation found in $o"
2828- __sphinxRoot=$o
1919+ for candidate in doc docs doc/source docs/source ; do
2020+ if [[ -f "$candidate/conf.py" ]] ; then
2121+ echo "Sphinx documentation found in $candidate"
2222+ __sphinxRoot=$candidate
2923 break
3024 fi
3125 done
···3529 echo 2>&1 "Sphinx documentation not found, use 'sphinxRoot' variable"
3630 exit 1
3731 fi
3838- sphinx-build -M html "${__sphinxRoot}" ".sphinx/html" -v
3232+3333+ if [ -n "${sphinxBuilders-}" ]; then
3434+ eval "__sphinxBuilders=($sphinxBuilders)"
3535+ else
3636+ __sphinxBuilders=(html)
3737+ fi
3838+3939+ for __builder in "${__sphinxBuilders[@]}"; do
4040+ echo "Executing sphinx-build with ${__builder} builder"
4141+ sphinx-build -M "${__builder}" "${__sphinxRoot}" ".sphinx/${__builder}" -v
4242+ done
39434044 runHook postBuildSphinx
4145}
42464347installSphinxPhase() {
4848+ echo "Executing installSphinxPhase"
4949+4450 local docdir=""
4551 runHook preInstallSphinx
46524747- docdir="${doc:-$out}/share/doc/${sphinxOutdir:-$name}"
4848- mkdir -p "$docdir"
5353+ for __builder in "${__sphinxBuilders[@]}"; do
5454+ # divert output for man builder
5555+ if [ "$__builder" == "man" ]; then
5656+ installManPage .sphinx/man/man/*
5757+5858+ else
5959+ # shellcheck disable=2154
6060+ docdir="${doc:-$out}/share/doc/${pname}"
49615050- cp -r .sphinx/html/html "$docdir/"
5151- rm -fr "${docdir}/html/_sources" "${docdir}/html/.buildinfo"
6262+ mkdir -p "$docdir"
6363+6464+ cp -r ".sphinx/${__builder}/${__builder}" "$docdir/"
6565+ rm -fr "${docdir}/${__builder}/_sources" "${docdir}/${__builder}/.buildinfo"
6666+ fi
6767+ done
52685369 runHook postInstallSphinx
5470}
55715656-preDistPhases+=" buildSphinxPhase"
5757-postPhases+=" installSphinxPhase"
7272+preDistPhases+=" buildSphinxPhase installSphinxPhase"