From 63d783a3bc1706d9ad09137dd7252ed1d2baef65 Mon Sep 17 00:00:00 2001 From: Valentin Gagarin Date: Mon, 13 Nov 2023 17:30:54 +0100 Subject: [PATCH] fix and simplify devmode script previously, stderr was garbled, which made it really annoying to deal with build errors. it turns out that the library wrapper around calling a process is not just counterproductive, but also completely unnecessary. the build now takes longer because it's not incremental any more. but the problem with `sphinx-build` in a shell environment is that it doesn't keep track of an entire class of files, that would have to be considered manually. this is too much manual overhead that doesn't scale at all. with the new setup the live preview will do exactly what the final deployment does. [1]: https://github.com/executablebooks/sphinx-autobuild#relevant-sphinx-bugs Co-authored-by: Alex Groleau source@proof.construction --- default.nix | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/default.nix b/default.nix index 6df18b6..d2b28f5 100644 --- a/default.nix +++ b/default.nix @@ -1,6 +1,6 @@ -{ - inputs ? import ./nix/sources.nix, - system ? builtins.currentSystem, +{ inputs ? import ./nix/sources.nix +, system ? builtins.currentSystem +, }: let pkgs = import inputs.nixpkgs { @@ -37,19 +37,32 @@ let livereload ]); script = '' - from livereload import Server, shell + from livereload import Server + from subprocess import Popen, PIPE + import shlex server = Server() - build_docs = shell("make html") + def nix_build(): + p = Popen( + shlex.split("nix-build -A build"), + # capture output as text + stdout=PIPE, + stderr=PIPE, + text=True, + ) + # we only care about failures + stdout, stderr = p.communicate() + if p.returncode: + print(stderr) + return p - print("Doing an initial build of the docs...") - build_docs() + # (re-)build once before serving + nix_build().wait() - server.watch("source/*", build_docs) - server.watch("source/**/*", build_docs) - server.watch("_templates/*.html", build_docs) - server.serve(root="build/html") + server.watch("source/*", nix_build) + server.watch("source/**/*", nix_build) + server.serve(root="result") ''; in pkgs.writeShellApplication {