Buckets:
| #!/usr/bin/env python3 | |
| """Invoke-only tasks for building the Sphinx documentation.""" | |
| import os | |
| import shlex | |
| import subprocess | |
| from invoke import Exit, task | |
| def _split_cli_args(value: str) -> list[str]: | |
| """Split a shell-style option string into argv tokens.""" | |
| if not value.strip(): | |
| return [] | |
| return shlex.split(value, posix=os.name != "nt") | |
| def _collect_sphinx_opts(opts: str = "") -> list[str]: | |
| """Preserve the established Sphinx option merge order.""" | |
| args: list[str] = [] | |
| for part in (os.environ.get("SPHINXOPTS", ""), os.environ.get("O", ""), opts): | |
| args.extend(_split_cli_args(part)) | |
| return args | |
| def _run_sphinx_make_mode( | |
| target: str, | |
| sourcedir: str, | |
| builddir: str, | |
| opts: str = "", | |
| ) -> None: | |
| sphinx_build = os.environ.get("SPHINXBUILD", "sphinx-build") | |
| command = [ | |
| sphinx_build, | |
| "-M", | |
| target, | |
| sourcedir, | |
| builddir, | |
| *_collect_sphinx_opts(opts), | |
| ] | |
| try: | |
| completed = subprocess.run(command, check=False) | |
| except FileNotFoundError as exc: | |
| raise Exit( | |
| "The 'sphinx-build' command was not found. Set SPHINXBUILD to the " | |
| "full path of the executable or add it to PATH." | |
| ) from exc | |
| if completed.returncode != 0: | |
| raise Exit(code=completed.returncode) | |
| def help( | |
| _ctx, | |
| sourcedir: str = ".", | |
| builddir: str = "_build", | |
| opts: str = "", | |
| ) -> None: | |
| """Show Sphinx make-mode help.""" | |
| _run_sphinx_make_mode( | |
| target="help", | |
| sourcedir=sourcedir, | |
| builddir=builddir, | |
| opts=opts, | |
| ) | |
| def build( | |
| _ctx, | |
| target: str, | |
| sourcedir: str = ".", | |
| builddir: str = "_build", | |
| opts: str = "", | |
| ) -> None: | |
| """Build docs via ``sphinx-build -M``.""" | |
| _run_sphinx_make_mode( | |
| target=target, | |
| sourcedir=sourcedir, | |
| builddir=builddir, | |
| opts=opts, | |
| ) | |
| def html( | |
| _ctx, | |
| sourcedir: str = ".", | |
| builddir: str = "_build", | |
| opts: str = "", | |
| ) -> None: | |
| """Build HTML documentation.""" | |
| build(_ctx, target="html", sourcedir=sourcedir, builddir=builddir, opts=opts) | |
| def clean( | |
| _ctx, | |
| sourcedir: str = ".", | |
| builddir: str = "_build", | |
| opts: str = "", | |
| ) -> None: | |
| """Clean built documentation.""" | |
| build(_ctx, target="clean", sourcedir=sourcedir, builddir=builddir, opts=opts) | |
| def linkcheck( | |
| _ctx, | |
| sourcedir: str = ".", | |
| builddir: str = "_build", | |
| opts: str = "", | |
| ) -> None: | |
| """Check all external links for integrity.""" | |
| build(_ctx, target="linkcheck", sourcedir=sourcedir, builddir=builddir, opts=opts) | |
| def doctest( | |
| _ctx, | |
| sourcedir: str = ".", | |
| builddir: str = "_build", | |
| opts: str = "", | |
| ) -> None: | |
| """Run doctests in the documentation.""" | |
| build(_ctx, target="doctest", sourcedir=sourcedir, builddir=builddir, opts=opts) | |
Xet Storage Details
- Size:
- 2.93 kB
- Xet hash:
- a7f1b021dfbca462fe66eb862e659339e322304c2062e97125b668f49c4eefe4
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.