//sphinxdocs:sphinx.bzl
Rules to generate Sphinx documentation.
The general usage of the Sphinx rules requires two pieces:
Using
sphinx_docsto define the docs to build and options for building.Defining a
sphinx-buildbinary to run Sphinx with the necessary dependencies to be used by (1); thesphinx_build_binaryrule helps with this.
Defining your own sphinx-build binary is necessary because Sphinx uses
a plugin model to support extensibility.
The Sphinx integration is still experimental.
- sphinx_build_binary(name, py_binary_rule='<function py_binary from //python:py_binary.bzl>', **kwargs)
Create an executable with the sphinx-build command line interface.
The
depsmust contain the sphinx library and any other extensions Sphinx needs at runtime.- Args:
name of the target. The name “sphinx-build” is the conventional name to match what Sphinx itself uses.
py_binary_rule– (callable) (default ‘<function py_binary from //python:py_binary.bzl>’)A
py_binarycompatible callable for creating the target. If not set, the regularpy_binaryrule is used. This allows using the version-aware rules, or other alternative implementations.Additional kwargs to pass onto
py_binary. Thesrcsandmainattributes must not be specified.
- sphinx_docs(*, name, srcs=[], deps=[], renamed_srcs={}, sphinx, config, formats, strip_prefix='', extra_opts=[], tools=[], allow_persistent_workers=True, **kwargs)
Generate docs using Sphinx.
Generates targets:
<name>: The output of this target is a directory for each format Sphinx creates. This target also has a separate output group for each format. e.g.--output_group=htmlwill only build the “html” format files.<name>.serve: A binary that locally serves the HTML output. This allows previewing docs during development.<name>.run: A binary that directly runs the underlying Sphinx command to build the docs. This is a debugging aid.
- Args:
name of the docs rule.
srcs– (list[label]) (default [])The source files for Sphinx to process.
deps– (list[label]) (default [])of
sphinx_docs_librarytargets.renamed_srcs– (dict[label,dict]) (default {})Doc source files for Sphinx that are renamed. This is typically used for files elsewhere, such as top level files in the repo.
the Sphinx tool to use for building documentation. Because Sphinx supports various plugins, you must construct your own binary with the necessary dependencies. The
sphinx_build_binaryrule can be used to define such a binary, but any executable supporting thesphinx-buildcommand line interface can be used (typically somepy_binaryprogram).the Sphinx config file (
conf.py) to use.formats– (list of str) the formats (-bflag) to generate documentation in. Each format will become an output group.strip_prefix– (str) (default “”)A prefix to remove from the file paths of the source files. e.g., given
//docs:foo.md, strippingdocs/makes Sphinx seefoo.mdin its generated source directory. If not specified, thennative.package_nameis used.extra_opts– (list[str]) (default [])Additional options to pass onto Sphinx building. On each provided option, a location expansion is performed. See
- -.tools– (list[label]) (default [])Additional tools that are used by Sphinx and its plugins. This just makes the tools available during Sphinx execution. To locate them, use
extra_optsand$(location).allow_persistent_workers– (bool) (default True)(experimental) If true, allow using persistent workers for running Sphinx, if Bazel decides to do so. This can improve incremental building of docs.
Common attributes to pass onto rules.
- sphinx_inventory(name, src, **kwargs)
Creates a compressed inventory file from an uncompressed on.
The Sphinx inventory format isn’t formally documented, but is understood to be:
# Sphinx inventory version 2 # Project: <project name> # Version: <version string> # The remainder of this file is compressed using zlib name domain:role 1 relative-url display name
Where:
<project name>is a string. e.g.Rules Python<version string>is a string e.g.1.5.3
And there are one or more
name domain:role ...linesname: the name of the symbol. It can contain special characters, but not spaces.domain:role: Thedomainis usually a language, e.g.pyorbzl. Theroleis usually the type of object, e.g.classorfunc. There is no canonical meaning to the values, they are usually domain-specific.1is a number. It affects search priority.relative-urlis a URL path relative to the base url in the confg.py intersphinx config.display nameis a string. It can contain spaces, or simply be the value-to indicate it is the same asname
See also
//sphinxdocs/inventoriesfor inventories of Bazel objects.
- rule sphinx_run(name, builder='html', docs=None)
Directly run the underlying Sphinx command
sphinx_docsuses.This is primarily a debugging tool. It’s useful for directly running the Sphinx command so that debuggers can be attached or output more directly inspected without Bazel interference.