Skip to content

Commit

Permalink
nix: Move docs build and serve scripts into nix
Browse files Browse the repository at this point in the history
This is long overdue. We expect everyone contributing to postgrest to use the nix tools,
so it makes no sense to carry around external tools anymore.
  • Loading branch information
wolfgangwalther committed Feb 18, 2024
1 parent 0f1544f commit cceb0cc
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 58 deletions.
31 changes: 0 additions & 31 deletions docs/build.sh

This file was deleted.

18 changes: 0 additions & 18 deletions docs/livereload_docs.py

This file was deleted.

65 changes: 56 additions & 9 deletions nix/tools/docs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
, buildToolbox
, checkedShellScript
, python3
, python3Packages
, writers
}:
let
python = python3.withPackages (ps: [
selectPythonPackages = ps: [
ps.sphinx
ps.sphinx_rtd_theme
ps.livereload
Expand All @@ -14,7 +16,9 @@ let
ps.sphinxext-opengraph
# TODO: Remove override once new sphinx-intl version (> 2.1.0) is released and available in nixpkgs
(ps.sphinx-intl.overrideAttrs (drv: { nativeBuildInputs = drv.nativeBuildInputs ++ [ ps.six ]; }))
]);
];

python = python3.withPackages selectPythonPackages;

build =
checkedShellScript
Expand All @@ -25,10 +29,56 @@ let
workingDir = "/docs";
}
''
# build.sh needs to find "sphinx-build"
PATH=${python}/bin:$PATH
function build() {
${python}/bin/sphinx-build --color -W -a -n . -b "$@"
}
if [ "$_arg_language" == "" ]; then
# clean previous build, otherwise some errors might be supressed
rm -rf "_build/html/default"
if [ -d languages ]; then
# default to updating all existing locales
build gettext _build/gettext
${python}/bin/sphinx-intl update -p _build/gettext
fi
build html "_build/html/default"
else
# clean previous build, otherwise some errors might be supressed
rm -rf "_build/html/$_arg_language"
./build.sh "$_arg_language"
# update and build specific locale, can be used to create new locale
build gettext _build/gettext
${python}/bin/sphinx-intl update -p _build/gettext -l "$_arg_language"
build html "_build/html/$_arg_language" -D "language=$_arg_language"
fi
'';

server =
writers.writePython3
"postgrest-docs-server"
{ libraries = selectPythonPackages python3Packages; }
''
import sys
from livereload import Server, shell
from subprocess import call
build = sys.argv[1]
locale = sys.argv[2]
if locale == "":
locale = "default"
else:
build += " " + locale
call(build, shell=True)
server = Server()
server.watch("**/*.rst", shell(build))
server.watch(f"locales/{locale}/LC_MESSAGES/*.po", shell(build))
server.serve(root=f"_build/html/{locale}")
'';

serve =
Expand All @@ -40,10 +90,7 @@ let
workingDir = "/docs";
}
''
# livereload_docs.py needs to find "sphinx-build"
PATH=${python}/bin:$PATH
./livereload_docs.py "$_arg_language"
${server} ${build} "$_arg_language"
'';

spellcheck =
Expand Down

0 comments on commit cceb0cc

Please sign in to comment.