From 10597135fabde828707f4e5ae3d24b1a939c309f Mon Sep 17 00:00:00 2001 From: Frank Male Date: Wed, 25 Oct 2023 01:01:50 -0400 Subject: [PATCH] :memo: use pywaterflood's noxfile session for doc building --- noxfile.py | 50 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/noxfile.py b/noxfile.py index 3513e7b..a3072da 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,6 +1,7 @@ """Nox sessions for linting, docs, and testing.""" from __future__ import annotations +import argparse import os import shutil from pathlib import Path @@ -29,19 +30,46 @@ def tests(session: nox.Session) -> None: session.run("pytest", *session.posargs) -@nox.session +@nox.session(reuse_venv=True) def docs(session: nox.Session) -> None: - """Build the docs. Pass "serve" to serve.""" - session.install(".[docs]") + """ + Build the docs. Pass "--serve" to serve. Pass "-b linkcheck" to check links. + """ + + parser = argparse.ArgumentParser() + parser.add_argument("--serve", action="store_true", help="Serve after building") + parser.add_argument( + "-b", dest="builder", default="html", help="Build target (default: html)" + ) + args, posargs = parser.parse_known_args(session.posargs) + + if args.builder != "html" and args.serve: + session.error("Must not specify non-HTML builder with --serve") + + extra_installs = ["sphinx-autobuild"] if args.serve else [] + + session.install("-e.[docs]", *extra_installs) session.chdir("docs") - session.run("sphinx-build", "-M", "html", ".", "_build") - - if session.posargs: - if "serve" in session.posargs: - print("Launching docs at http://localhost:8000/ - use Ctrl-C to quit") - session.run("python", "-m", "http.server", "8000", "-d", "_build/html") - else: - session.warn("Unsupported argument to docs") + + if args.builder == "linkcheck": + session.run( + "sphinx-build", "-b", "linkcheck", ".", "_build/linkcheck", *posargs + ) + return + + shared_args = ( + "-n", # nitpicky mode + "-T", # full tracebacks + f"-b={args.builder}", + ".", + f"_build/{args.builder}", + *posargs, + ) + + if args.serve: + session.run("sphinx-autobuild", *shared_args) + else: + session.run("sphinx-build", "--keep-going", *shared_args) @nox.session