Build environment API

class sphinx.environment.BuildEnvironment[source]



Reference to the Sphinx (application) object.


Reference to the Config object.


Target project. See Project.


Source directory.


Directory for storing pickled doctrees.


An EventManager object.


A set of all existing docnames.


Dictionary mapping docnames to “metadata” (see File-wide metadata).


Dictionary mapping docnames to the docutils node for their main title.


Returns the docname of the document currently being parsed.

Utility methods

doc2path(docname: str, base: bool = True) str[source]

Return the filename for the document name.

If base is True, return absolute path under self.srcdir. If base is False, return relative path to self.srcdir.

relfn2path(filename: str, docname: str | None = None) tuple[str, str][source]

Return paths to a file referenced from a document, relative to documentation root and absolute.

In the input “filename”, absolute filenames are taken as relative to the source dir, while relative filenames are relative to the dir of the containing document.

note_dependency(filename: str) None[source]

Add filename as a dependency of the current document.

This means that the document will be rebuilt if this file changes.

filename should be absolute or relative to the source directory.

new_serialno(category: str = '') int[source]

Return a serial number, e.g. for index entry targets.

The number is guaranteed to be unique in the current document.

note_reread() None[source]

Add the current document to the list of documents that will automatically be re-read at the next build.