nixpkgs/pkgs/development/interpreters/python/hooks/sphinx-hook.sh
Dmitry Bogatov 82ae2e8f06 python3.pkgs.sphinxHook: fix co-installability of generated documentation
Include full $name of the derivation into docdir, so documentation for
python package "foo" is installed into $out/share/doc/python3.10-foo-1.2.3
instead of just $out/share/doc/foo, where it may conflict with some
other package named "foo" and not-coinstallable with different
versions of the same python package.

Change from $name to $pname was introduced in [1ee5fca], probably as
unindented side-effect of adding support for formats other than html.
2023-01-03 20:28:48 -05:00

73 lines
1.9 KiB
Bash

# shellcheck shell=bash
echo "Sourcing sphinx-hook"
declare -a __sphinxBuilders
buildSphinxPhase() {
echo "Executing buildSphinxPhase"
local __sphinxRoot=""
runHook preBuildSphinx
if [[ -n "${sphinxRoot:-}" ]] ; then # explicit root
if ! [[ -f "${sphinxRoot}/conf.py" ]] ; then
echo 2>&1 "$sphinxRoot/conf.py: no such file"
exit 1
fi
__sphinxRoot=$sphinxRoot
else
for candidate in doc docs doc/source docs/source ; do
if [[ -f "$candidate/conf.py" ]] ; then
echo "Sphinx documentation found in $candidate"
__sphinxRoot=$candidate
break
fi
done
fi
if [[ -z "${__sphinxRoot}" ]] ; then
echo 2>&1 "Sphinx documentation not found, use 'sphinxRoot' variable"
exit 1
fi
if [ -n "${sphinxBuilders-}" ]; then
eval "__sphinxBuilders=($sphinxBuilders)"
else
__sphinxBuilders=(html)
fi
for __builder in "${__sphinxBuilders[@]}"; do
echo "Executing sphinx-build with ${__builder} builder"
sphinx-build -M "${__builder}" "${__sphinxRoot}" ".sphinx/${__builder}" -v
done
runHook postBuildSphinx
}
installSphinxPhase() {
echo "Executing installSphinxPhase"
local docdir=""
runHook preInstallSphinx
for __builder in "${__sphinxBuilders[@]}"; do
# divert output for man builder
if [ "$__builder" == "man" ]; then
installManPage .sphinx/man/man/*
else
# shellcheck disable=2154
docdir="${doc:-$out}/share/doc/${name}"
mkdir -p "$docdir"
cp -r ".sphinx/${__builder}/${__builder}" "$docdir/"
rm -fr "${docdir}/${__builder}/_sources" "${docdir}/${__builder}/.buildinfo"
fi
done
runHook postInstallSphinx
}
preDistPhases+=" buildSphinxPhase installSphinxPhase"