refactor: documentation generation

This commit is contained in:
George Rawlinson 2020-11-24 14:39:38 +13:00
parent 8cc7771389
commit 79ccdf77c6
Signed by: grawlinson
GPG key ID: E0959FEA8B550539

View file

@ -1,6 +1,5 @@
"""Nox sessions.""" """Nox sessions."""
import functools import shutil
import os
from pathlib import Path from pathlib import Path
from textwrap import dedent from textwrap import dedent
@ -128,35 +127,36 @@ def precommit(session: Session) -> None:
@nox.session(python=latest_version) @nox.session(python=latest_version)
def docs(session: Session) -> None: def docs_build(session: Session) -> None:
"""Build the documentation. """Build the documentation.
Args: Args:
session: The Session object. session: The Session object.
""" """
output_dir = os.path.join(session.create_tmp(), "output") args = session.posargs or ["docs", "docs/_build"]
doctrees, html = map( nox_poetry.install(session, nox_poetry.WHEEL)
functools.partial(os.path.join, output_dir), ["doctrees", "html"] nox_poetry.install(session, "sphinx", "sphinx-rtd-theme")
)
session.run("rm", "-rf", output_dir, external=True)
build_dir = Path("docs", "_build")
if build_dir.exists():
shutil.rmtree(build_dir)
session.run("sphinx-build", *args)
@nox.session(python=latest_version)
def docs(session: Session) -> None:
"""Build and serve the documentation with live reloading on file changes.
Args:
session: The Session object.
"""
args = session.posargs or ["--open-browser", "docs", "docs/_build"]
nox_poetry.install(session, nox_poetry.WHEEL) nox_poetry.install(session, nox_poetry.WHEEL)
nox_poetry.install(session, "sphinx", "sphinx-autobuild", "sphinx-rtd-theme") nox_poetry.install(session, "sphinx", "sphinx-autobuild", "sphinx-rtd-theme")
session.cd("docs")
sphinx_args = [
"-b",
"html",
"-W",
"-d",
doctrees,
".",
html,
]
if not session.interactive: build_dir = Path("docs", "_build")
sphinx_cmd = "sphinx-build" if build_dir.exists():
else: shutil.rmtree(build_dir)
sphinx_cmd = "sphinx-autobuild"
sphinx_args.insert(0, "--open-browser")
session.run(sphinx_cmd, *sphinx_args) session.run("sphinx-autobuild", *args)