Documentation builders#

This module is the starting point for building documentation, and is responsible to figure out what to build and with which options. The actual documentation build for each individual document is then done in a subprocess call to Sphinx, see builder_helper(). Note that

  • The builders are configured with;

  • The Sphinx subprocesses are configured in

DocBuilder is the base class of all Builders. It has builder helpers html(), latex(), pdf(), inventory(), etc, which are invoked depending on the output type. Each type corresponds with the Sphinx builder format, except that pdf is Sphinx latex builder plus compiling latex to pdf. Note that Sphinx inventory builder is not native to Sphinx but provided by Sage. See sage_docbuild/ext/ The Sphinx inventory builder is a dummy builder with no actual output but produces doctree files in local/share/doctree and inventory.inv inventory files in local/share/inventory.

The reference manual is built in two passes, first by ReferenceBuilder with inventory output type and secondly with``html`` output type. The ReferenceBuilder itself uses ReferenceTopBuilder and ReferenceSubBuilder to build subcomponents of the reference manual. The ReferenceSubBuilder examines the modules included in the subcomponent by comparing the modification times of the module files with the times saved in local/share/doctree/reference.pickle from the previous build. Then new rst files are generated for new and updated modules. See get_new_and_updated_modules().

After github issue #31948, when Sage is built, ReferenceBuilder is not used and its responsibility is now taken by the Makefile in $SAGE_ROOT/src/doc.


Bases: object

A class used to build all of the documentation.


Return a list of all of the documents.

A document is a directory within one of the language subdirectories of SAGE_DOC_SRC specified by the global LANGUAGES variable.


sage: from import AllBuilder
sage: documents = AllBuilder().get_all_documents()
sage: 'en/tutorial' in documents  # optional - sage_spkg
sage: documents[0] == 'en/reference'
class, lang='en')#

Bases: object


  • name - the name of a subdirectory in SAGE_DOC_SRC, such as ‘tutorial’ or ‘bordeaux_2008’

  • lang - (default “en”) the language of the document.

changes(*args, **kwds)#
html(*args, **kwds)#
htmlhelp(*args, **kwds)#
inventory(*args, **kwds)#
json(*args, **kwds)#
latex(*args, **kwds)#
linkcheck(*args, **kwds)#

Build the PDF files for this document.

This is done by first (re)-building the LaTeX output, going into that LaTeX directory, and running ‘make all-pdf’ there.


sage: from import DocBuilder
sage: b = DocBuilder('tutorial')
sage: b.pdf() #not tested
pickle(*args, **kwds)#
web(*args, **kwds)#
class, lang='en')#

Bases: AllBuilder

This class builds the reference manual. It uses DocBuilder to build the top-level page and ReferenceSubBuilder for each sub-component.


Return a list of all reference manual components to build.

We add a component name if it’s a subdirectory of the manual’s directory and contains a file named ‘index.rst’.

We return the largest component (most subdirectory entries) first since they will take the longest to build.


sage: from import ReferenceBuilder
sage: b = ReferenceBuilder('reference')
sage: refdir = os.path.join(os.environ['SAGE_DOC_SRC'], 'en',  # optional - sage_spkg
sage: sorted(b.get_all_documents(refdir))  # optional - sage_spkg
class*args, **kwds)#

Bases: DocBuilder

This class builds sub-components of the reference manual. It is responsible for making sure that the auto generated reST files for the Sage library are up to date.

When building any output, we must first go through and check to see if we need to update any of the autogenerated reST files. There are two cases where this would happen:

  1. A new module gets added to one of the toctrees.

  2. The actual module gets updated and possibly contains a new title.


Return the name of the file associated to a given module


sage: from import ReferenceSubBuilder
sage: ReferenceSubBuilder("reference").auto_rest_filename("sage.combinat.partition")

Return the filename where the pickle of the reference cache is stored.


Remove all autogenerated reST files.


Return an iterator for all modules which are included in the reference manual.


Return an iterator for all rst files which are not autogenerated.


Retrieve the reference cache which contains the options previously used by the reference builder.

If it doesn’t exist, then we just return an empty dictionary. If it is corrupted, return an empty dictionary.


Return an iterator for all the modules that have been modified since the documentation was last built.


Return the title of the module from its docstring.


Given a filename for a reST file, return an iterator for all of the autogenerated reST files that it includes.


Return an iterator for all new and updated modules that appear in the toctrees, and remove obsolete old modules.


Return the Sphinx environment for this project.


Return an iterator for all the modules in the Sage library which are not included in the reference manual.


Print all of the modules that are included in the Sage reference manual.


Print a list of all the modules that have been modified since the documentation was last built.


Print all the modules that appear in the toctrees that are newly included or updated.


Print all of the modules which are not included in the Sage reference manual.


Pickle the current reference cache for later retrieval.


Update the modification times for reST files in the Sphinx environment for this project.


Write the autogenerated reST file for module_name.

class*args, **kwds)#

Bases: DocBuilder

This class builds the top-level page of the reference manual.


Build the top-level document.


Bases: DocBuilder

This is the class used to build the documentation for a single user-specified file. If the file is called ‘’, then the documentation is built in DIR/foo/ if the user passes the command line option “-o DIR”, or in DOT_SAGE/docbuild/foo/ otherwise.

class, lang='en')#

Bases: DocBuilder


When we clean the output for the website index, we need to remove all of the HTML that were placed in the parent directory.

In addition, remove the index file installed into the root doc directory.


After we have finished building the website index page, we copy everything one directory up, that is, to the base diectory html/en.

In addition, an index file is installed into the root doc directory.

Thus we have three index.html files:

html/en/website/index.html (not used) html/en/index.html (base directory) index.html (root doc directory)


Build the website hosting pdf docs., args, processes=None)#

Thin wrapper around \(sage_docbuild.utils.build_many\) which uses the docbuild settings NUM_THREADS and ABORT_ON_ERROR.

Return a function which builds the documentation for output type type.

Return an appropriate Builder object for the document name.

DocBuilder and its subclasses do all the real work in building the documentation.

Return a list of document names the Sage documentation builder will accept as command-line arguments.