nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1# This hook automatically finds Sphinx documentation, builds it in html format
2# and installs it.
3#
4# This hook knows about several popular locations in which subdirectory
5# documentation may be, but in very unusual cases $sphinxRoot directory can be
6# set explicitly.
7#
8# Name of the directory relative to ${doc:-$out}/share/doc is normally also
9# deduced automatically, but can be overridden with $sphinxOutdir variable.
10#
11# Sphinx build system can depend on arbitrary amount of python modules, client
12# code is responsible for ensuring that all dependencies are present.
13
14buildSphinxPhase() {
15 local __sphinxRoot="" o
16
17 runHook preBuildSphinx
18 if [[ -n "${sphinxRoot:-}" ]] ; then # explicit root
19 if ! [[ -f "${sphinxRoot}/conf.py" ]] ; then
20 echo 2>&1 "$sphinxRoot/conf.py: no such file"
21 exit 1
22 fi
23 __sphinxRoot=$sphinxRoot
24 else
25 for o in doc docs doc/source docs/source ; do
26 if [[ -f "$o/conf.py" ]] ; then
27 echo "Sphinx documentation found in $o"
28 __sphinxRoot=$o
29 break
30 fi
31 done
32 fi
33
34 if [[ -z "${__sphinxRoot}" ]] ; then
35 echo 2>&1 "Sphinx documentation not found, use 'sphinxRoot' variable"
36 exit 1
37 fi
38 sphinx-build -M html "${__sphinxRoot}" ".sphinx/html" -v
39
40 runHook postBuildSphinx
41}
42
43installSphinxPhase() {
44 local docdir=""
45 runHook preInstallSphinx
46
47 docdir="${doc:-$out}/share/doc/${sphinxOutdir:-$name}"
48 mkdir -p "$docdir"
49
50 cp -r .sphinx/html/html "$docdir/"
51 rm -fr "${docdir}/html/_sources" "${docdir}/html/.buildinfo"
52
53 runHook postInstallSphinx
54}
55
56preBuildPhases+=" buildSphinxPhase"
57postPhases+=" installSphinxPhase"