1# shellcheck shell=bash
2echo "Sourcing sphinx-hook"
3
4declare -a __sphinxBuilders
5
6buildSphinxPhase() {
7 echo "Executing buildSphinxPhase"
8
9 local __sphinxRoot=""
10 runHook preBuildSphinx
11
12 if [[ -n "${sphinxRoot:-}" ]]; then # explicit root
13 if ! [[ -f "${sphinxRoot}/conf.py" ]]; then
14 echo 2>&1 "$sphinxRoot/conf.py: no such file"
15 exit 1
16 fi
17 __sphinxRoot=$sphinxRoot
18 else
19 for candidate in doc docs doc/source docs/source; do
20 if [[ -f "$candidate/conf.py" ]]; then
21 echo "Sphinx documentation found in $candidate"
22 __sphinxRoot=$candidate
23 break
24 fi
25 done
26 fi
27
28 if [[ -z "${__sphinxRoot}" ]]; then
29 echo 2>&1 "Sphinx documentation not found, use 'sphinxRoot' variable"
30 exit 1
31 fi
32
33 if [ -n "${sphinxBuilders-}" ]; then
34 eval "__sphinxBuilders=($sphinxBuilders)"
35 else
36 __sphinxBuilders=(html)
37 fi
38
39 for __builder in "${__sphinxBuilders[@]}"; do
40 echo "Executing sphinx-build with ${__builder} builder"
41 @sphinxBuild@ -M "${__builder}" "${__sphinxRoot}" ".sphinx/${__builder}" -v
42 done
43
44 runHook postBuildSphinx
45}
46
47installSphinxPhase() {
48 echo "Executing installSphinxPhase"
49
50 local docdir=""
51 runHook preInstallSphinx
52
53 for __builder in "${__sphinxBuilders[@]}"; do
54 # divert output for man builder
55 if [ "$__builder" == "man" ]; then
56 installManPage .sphinx/man/man/*
57
58 else
59 # shellcheck disable=2154
60 docdir="${doc:-$out}/share/doc/${name}"
61
62 mkdir -p "$docdir"
63
64 cp -r ".sphinx/${__builder}/${__builder}" "$docdir/"
65 rm -fr "${docdir}/${__builder}/_sources" "${docdir}/${__builder}/.buildinfo"
66 fi
67 done
68
69 runHook postInstallSphinx
70}
71
72appendToVar preFixupPhases buildSphinxPhase installSphinxPhase