This comment is a description of how the doc system works with some links to code. This is a very general overview that is intended to provide context for anyone working on any of the dependencies filed against this meta bug.
The goal of our doc system is to allow individual teams and developers the ability to create and maintain their own domain specific documentation. We don't want to act as gatekeepers. In order for this to work, we need some mechanism for developers to register a doc dir.
Documentation gets registered by developers via
moz.build files. For example:
There are two variables,
SPHINX_PYTHON_PACKAGE_DIRS and some information on them can be found here:
Documentation is generated using sphinx with some custom tooling to hook in all of the directories that are registered via
moz.build. Aside from sphinx itself, there are 3 pieces to this stage:
This is the command line entry point for generating and uploading docs. It is mostly just a thin wrapper around
sphinx-build, but also acts like the glue that holds the system together.
custom sphinx extension
A custom sphinx extension that acts as a hook from which we can run all our customized operations before the regular 'sphinx-build' kicks in. This module is registered in the main conf.py. This extension adds a couple custom sphinx directives as well, but otherwise isn't very interesting.
A little python module containing the meat of the custom generation code. It is invoked from
sphinx.py above and is responsible for reading the
moz.build variables and copying all of the relevant source files into a staging directory in the objdir. Once all the source files have been copied,
sphinx-build will run against the staging dir.
At a high level, the doc generation process will go something like this:
- User runs
mach doc or
mach doc <subdir>
- Mach command runs
tools/docs/conf.py as the config file.
mozbuild.sphinx extension is registered in this config file.
- This extension has a setup hook which calls into
moztreedocs reads all the
moz.build sphinx variables and copies all the source files to a staging dir.
mozbuild.sphinx extension gets
sphinx-build to build the docs from this staging directory.
sphinx-build resumes as normal, typically a directory next to the staging dir will contain the html output.
Publishing docs is a separate step from generation, but uses the same mach command:
mach doc --upload. This step is much simpler than the generation one. The docs are hosted on a static Amazon S3 bucket behind this domain:
mach doc --upload command uses Amazon's
boto3 library to push the output dir generated in step 7 above up to the static server:
And that's it.
While it is possible to generate docs locally, publishing requires special credentials. Generation and publication are handled by two separate tasks (
DocUp respectively). They are defined here:
These tasks will run whenever someone modifies a doc source file, so changes to the documentation should be automatically picked up and published once the patch lands to mozilla-central. While it's nice to have this automated system, we do still care about running
mach doc locally as developers will typically want to see how their modifications look before pushing.