From 6b8b02cef77a7dcd1192cc47ce60fd2e128617a4 Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Sat, 28 Aug 2021 11:52:28 -0400 Subject: [PATCH 1/3] python3.pkgs.sphinxHook: new package This hook takes care of building and installing html documentation from Sphinx sources. --- .../interpreters/python/hooks/default.nix | 6 ++ .../interpreters/python/hooks/sphinx-hook.sh | 57 +++++++++++++++++++ pkgs/top-level/python-packages.nix | 1 + 3 files changed, 64 insertions(+) create mode 100644 pkgs/development/interpreters/python/hooks/sphinx-hook.sh diff --git a/pkgs/development/interpreters/python/hooks/default.nix b/pkgs/development/interpreters/python/hooks/default.nix index 1a0618225a37..cb5ef87826a9 100644 --- a/pkgs/development/interpreters/python/hooks/default.nix +++ b/pkgs/development/interpreters/python/hooks/default.nix @@ -169,4 +169,10 @@ in rec { name = "wheel-unpack-hook.sh"; deps = [ wheel ]; } ./wheel-unpack-hook.sh) {}; + + sphinxHook = callPackage ({ sphinx }: + makeSetupHook { + name = "python${python.pythonVersion}-sphinx-hook"; + deps = [ sphinx ]; + } ./sphinx-hook.sh) {}; } diff --git a/pkgs/development/interpreters/python/hooks/sphinx-hook.sh b/pkgs/development/interpreters/python/hooks/sphinx-hook.sh new file mode 100644 index 000000000000..0140958b2316 --- /dev/null +++ b/pkgs/development/interpreters/python/hooks/sphinx-hook.sh @@ -0,0 +1,57 @@ +# This hook automatically finds Sphinx documentation, builds it in html format +# and installs it. +# +# This hook knows about several popular locations in which subdirectory +# documentation may be, but in very unusual cases $sphinxRoot directory can be +# set explicitly. +# +# Name of the directory relative to ${doc:-$out}/share/doc is normally also +# deduced automatically, but can be overridden with $sphinxOutdir variable. +# +# Sphinx build system can depend on arbitrary amount of python modules, client +# code is responsible for ensuring that all dependencies are present. + +buildSphinxPhase() { + local __sphinxRoot="" o + + 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 o in doc docs doc/source docs/source ; do + if [[ -f "$o/conf.py" ]] ; then + echo "Sphinx documentation found in $o" + __sphinxRoot=$o + break + fi + done + fi + + if [[ -z "${__sphinxRoot}" ]] ; then + echo 2>&1 "Sphinx documentation not found, use 'sphinxRoot' variable" + exit 1 + fi + sphinx-build -M html "${__sphinxRoot}" ".sphinx/html" -v + + runHook postBuildSphinx +} + +installSphinxPhase() { + local docdir="" + runHook preInstallSphinx + + docdir="${doc:-$out}/share/doc/${sphinxOutdir:-$name}" + mkdir -p "$docdir" + + cp -r .sphinx/html/html "$docdir/" + rm -fr "${docdir}/html/_sources" "${docdir}/html/.buildinfo" + + runHook postInstallSphinx +} + +preBuildPhases+=" buildSphinxPhase" +postPhases+=" installSphinxPhase" diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 3616171dfdfd..b90f54657c1e 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -106,6 +106,7 @@ in { inherit buildSetupcfg; inherit (callPackage ../development/interpreters/python/hooks { }) + sphinxHook condaInstallHook condaUnpackHook eggUnpackHook From 3bb2ac5adfb3f2bceba113f011212aa35b199348 Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Sun, 12 Dec 2021 19:38:40 -0400 Subject: [PATCH 2/3] python3.pkgs.beautifulsoup4: build offline html documentation --- pkgs/development/python-modules/beautifulsoup4/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/development/python-modules/beautifulsoup4/default.nix b/pkgs/development/python-modules/beautifulsoup4/default.nix index d75351839aa2..2a59ac00f7aa 100644 --- a/pkgs/development/python-modules/beautifulsoup4/default.nix +++ b/pkgs/development/python-modules/beautifulsoup4/default.nix @@ -6,12 +6,14 @@ , pytestCheckHook , pythonOlder , soupsieve +, sphinxHook }: buildPythonPackage rec { pname = "beautifulsoup4"; version = "4.11.1"; format = "setuptools"; + outputs = ["out" "doc"]; disabled = pythonOlder "3.6"; @@ -29,6 +31,7 @@ buildPythonPackage rec { checkInputs = [ pytestCheckHook ]; + nativeBuildInputs = [ sphinxHook ]; pythonImportsCheck = [ "bs4" From 23d3cd040e8f7c3e616ff57b9ce5bd4d28aa9a5a Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Sat, 25 Dec 2021 23:11:00 -0400 Subject: [PATCH 3/3] python3.pkgs.dropbox: build offline html documentation --- pkgs/development/python-modules/dropbox/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/development/python-modules/dropbox/default.nix b/pkgs/development/python-modules/dropbox/default.nix index efce258451ff..4184ddb12502 100644 --- a/pkgs/development/python-modules/dropbox/default.nix +++ b/pkgs/development/python-modules/dropbox/default.nix @@ -8,6 +8,7 @@ , mock , pytest-mock , pytestCheckHook +, sphinxHook }: buildPythonPackage rec { @@ -16,6 +17,7 @@ buildPythonPackage rec { format = "setuptools"; disabled = pythonOlder "3.7"; + outputs = ["out" "doc"]; src = fetchFromGitHub { owner = "dropbox"; @@ -46,6 +48,7 @@ buildPythonPackage rec { pythonImportsCheck = [ "dropbox" ]; + nativeBuildInputs = [ sphinxHook ]; # Set SCOPED_USER_DROPBOX_TOKEN environment variable to a valid value. disabledTests = [