lol

Merge pull request #188032 from mweinelt/sphinx-hook-builders

authored by

Martin Weinelt and committed by
GitHub
faef0022 235b897e

+94 -36
+50 -2
doc/languages-frameworks/python.section.md
··· 744 744 unittestFlags = [ "-s" "tests" "-v" ]; 745 745 ``` 746 746 747 + ##### Using sphinxHook {#using-sphinxhook} 748 + 749 + The `sphinxHook` is a helpful tool to build documentation and manpages 750 + using the popular Sphinx documentation generator. 751 + It is setup to automatically find common documentation source paths and 752 + render them using the default `html` style. 753 + 754 + ``` 755 + outputs = [ 756 + "out" 757 + "doc" 758 + ]; 759 + 760 + nativeBuildInputs = [ 761 + sphinxHook 762 + ]; 763 + ``` 764 + 765 + The hook will automatically build and install the artifact into the 766 + `doc` output, if it exists. It also provides an automatic diversion 767 + for the artifacts of the `man` builder into the `man` target. 768 + 769 + ``` 770 + outputs = [ 771 + "out" 772 + "doc" 773 + "man" 774 + ]; 775 + 776 + # Use multiple builders 777 + sphinxBuilders = [ 778 + "singlehtml" 779 + "man" 780 + ]; 781 + ``` 782 + 783 + Overwrite `sphinxRoot` when the hook is unable to find your 784 + documentation source root. 785 + 786 + ``` 787 + # Configure sphinxRoot for uncommon paths 788 + sphinxRoot = "weird/docs/path"; 789 + ``` 790 + 791 + The hook is also available to packages outside the python ecosystem by 792 + referencing it using `python3.pkgs.sphinxHook`. 793 + 747 794 ### Develop local package {#develop-local-package} 748 795 749 796 As a Python developer you're likely aware of [development mode](http://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode) ··· 1270 1317 - `pytestCheckHook` to run tests with `pytest`. See [example usage](#using-pytestcheckhook). 1271 1318 - `pythonCatchConflictsHook` to check whether a Python package is not already existing. 1272 1319 - `pythonImportsCheckHook` to check whether importing the listed modules works. 1320 + - `pythonRelaxDepsHook` will relax Python dependencies restrictions for the package. 1321 + See [example usage](#using-pythonrelaxdepshook). 1273 1322 - `pythonRemoveBinBytecode` to remove bytecode from the `/bin` folder. 1274 1323 - `setuptoolsBuildHook` to build a wheel using `setuptools`. 1275 1324 - `setuptoolsCheckHook` to run tests with `python setup.py test`. 1325 + - `sphinxHook` to build documentation and manpages using Sphinx. 1276 1326 - `venvShellHook` to source a Python 3 `venv` at the `venvDir` location. A 1277 1327 `venv` is created if it does not yet exist. `postVenvCreation` can be used to 1278 1328 to run commands only after venv is first created. 1279 1329 - `wheelUnpackHook` to move a wheel to the correct folder so it can be installed 1280 1330 with the `pipInstallHook`. 1281 - - `pythonRelaxDepsHook` will relax Python dependencies restrictions for the package. 1282 - See [example usage](#using-pythonrelaxdepshook). 1283 1331 - `unittestCheckHook` will run tests with `python -m unittest discover`. See [example usage](#using-unittestcheckhook). 1284 1332 1285 1333 ### Development mode {#development-mode}
+2 -1
pkgs/development/interpreters/python/hooks/default.nix
··· 6 6 , isPy3k 7 7 , ensureNewerSourcesForZipFilesHook 8 8 , findutils 9 + , installShellFiles 9 10 }: 10 11 11 12 let ··· 190 191 sphinxHook = callPackage ({ sphinx }: 191 192 makeSetupHook { 192 193 name = "python${python.pythonVersion}-sphinx-hook"; 193 - deps = [ sphinx ]; 194 + deps = [ sphinx installShellFiles ]; 194 195 } ./sphinx-hook.sh) {}; 195 196 }
+39 -24
pkgs/development/interpreters/python/hooks/sphinx-hook.sh
··· 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. 1 + # shellcheck shell=bash 2 + echo "Sourcing sphinx-hook" 3 + 4 + declare -a __sphinxBuilders 13 5 14 6 buildSphinxPhase() { 15 - local __sphinxRoot="" o 7 + echo "Executing buildSphinxPhase" 16 8 9 + local __sphinxRoot="" 17 10 runHook preBuildSphinx 11 + 18 12 if [[ -n "${sphinxRoot:-}" ]] ; then # explicit root 19 13 if ! [[ -f "${sphinxRoot}/conf.py" ]] ; then 20 14 echo 2>&1 "$sphinxRoot/conf.py: no such file" ··· 22 16 fi 23 17 __sphinxRoot=$sphinxRoot 24 18 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 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 29 23 break 30 24 fi 31 25 done ··· 35 29 echo 2>&1 "Sphinx documentation not found, use 'sphinxRoot' variable" 36 30 exit 1 37 31 fi 38 - sphinx-build -M html "${__sphinxRoot}" ".sphinx/html" -v 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 + sphinx-build -M "${__builder}" "${__sphinxRoot}" ".sphinx/${__builder}" -v 42 + done 39 43 40 44 runHook postBuildSphinx 41 45 } 42 46 43 47 installSphinxPhase() { 48 + echo "Executing installSphinxPhase" 49 + 44 50 local docdir="" 45 51 runHook preInstallSphinx 46 52 47 - docdir="${doc:-$out}/share/doc/${sphinxOutdir:-$name}" 48 - mkdir -p "$docdir" 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/${pname}" 49 61 50 - cp -r .sphinx/html/html "$docdir/" 51 - rm -fr "${docdir}/html/_sources" "${docdir}/html/.buildinfo" 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 52 68 53 69 runHook postInstallSphinx 54 70 } 55 71 56 - preDistPhases+=" buildSphinxPhase" 57 - postPhases+=" installSphinxPhase" 72 + preDistPhases+=" buildSphinxPhase installSphinxPhase"
+3 -9
pkgs/tools/backup/borgbackup/default.nix
··· 33 33 setuptools-scm 34 34 35 35 # docs 36 - sphinx 36 + sphinxHook 37 37 guzzle_sphinx_theme 38 38 39 39 # shell completions 40 40 installShellFiles 41 41 ]; 42 + 43 + sphinxBuilders = [ "singlehtml" "man" ]; 42 44 43 45 buildInputs = [ 44 46 libb2 ··· 67 69 ]; 68 70 69 71 postInstall = '' 70 - make -C docs singlehtml 71 - mkdir -p $out/share/doc/borg 72 - cp -R docs/_build/singlehtml $out/share/doc/borg/html 73 - 74 - make -C docs man 75 - mkdir -p $out/share/man 76 - cp -R docs/_build/man $out/share/man/man1 77 - 78 72 installShellCompletion --cmd borg \ 79 73 --bash scripts/shell_completions/bash/borg \ 80 74 --fish scripts/shell_completions/fish/borg.fish \