Skip to content

Commit

Permalink
📝 use pywaterflood's noxfile session for doc building
Browse files Browse the repository at this point in the history
  • Loading branch information
frank1010111 committed Oct 25, 2023
1 parent 56d98ee commit 1059713
Showing 1 changed file with 39 additions and 11 deletions.
50 changes: 39 additions & 11 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1059713

Please sign in to comment.