From cceb0cc9a38c9bc58572b9709788374962d2ecc7 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Sat, 17 Feb 2024 20:52:04 +0100 Subject: [PATCH] nix: Move docs build and serve scripts into nix 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. --- docs/build.sh | 31 -------------------- docs/livereload_docs.py | 18 ------------ nix/tools/docs.nix | 65 +++++++++++++++++++++++++++++++++++------ 3 files changed, 56 insertions(+), 58 deletions(-) delete mode 100755 docs/build.sh delete mode 100755 docs/livereload_docs.py diff --git a/docs/build.sh b/docs/build.sh deleted file mode 100755 index d8addb5b73..0000000000 --- a/docs/build.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# sphinx-intl fails if LC_ALL is not set -export LC_ALL=${LC_ALL:-C} - -function build() { - sphinx-build --color -W -a -n . -b "$@" -} - -if [ "${1:-}" == "" ]; 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 - 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/$1" - - # update and build specific locale, can be used to create new locale - build gettext _build/gettext - sphinx-intl update -p _build/gettext -l "$1" - - build html "_build/html/$1" -D "language=$1" -fi diff --git a/docs/livereload_docs.py b/docs/livereload_docs.py deleted file mode 100755 index 1ee9a6b75e..0000000000 --- a/docs/livereload_docs.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env python -import sys -from livereload import Server, shell -from subprocess import call - -if len(sys.argv) == 1 or sys.argv[1] == "": - locale = "default" - build = "./build.sh" -else: - locale = sys.argv[1] - build = f"./build.sh {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}") diff --git a/nix/tools/docs.nix b/nix/tools/docs.nix index 7574f426bd..fc20a9e5f0 100644 --- a/nix/tools/docs.nix +++ b/nix/tools/docs.nix @@ -3,9 +3,11 @@ , buildToolbox , checkedShellScript , python3 +, python3Packages +, writers }: let - python = python3.withPackages (ps: [ + selectPythonPackages = ps: [ ps.sphinx ps.sphinx_rtd_theme ps.livereload @@ -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 @@ -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 = @@ -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 =