Skip to content

Commit

Permalink
Improve builder API doc
Browse files Browse the repository at this point in the history
  • Loading branch information
timhoffm committed Oct 11, 2024
1 parent 2f1d775 commit b618917
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
8 changes: 4 additions & 4 deletions doc/extdev/builderapi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Builder API

.. rubric:: Overridable Attributes

These attributes should be set on builder sub-classes:
These class attributes should be set on builder sub-classes:

.. autoattribute:: name
.. autoattribute:: format
Expand All @@ -29,8 +29,7 @@ Builder API

.. rubric:: Core Methods

These methods are predefined and should generally not be overridden,
since they form the core of the build process:
These methods are define the core build workflow and cannot be overridden:

.. automethod:: build_all
.. automethod:: build_specific
Expand Down Expand Up @@ -70,9 +69,10 @@ Builder API

.. rubric:: Overridable Attributes (extensions)

Builder sub-classes can set these attributes to support built-in extensions:
Builder sub-classes can set these class attributes to support built-in extensions:

.. attribute:: supported_linkcode
:type: str

By default, the :mod:`linkcode <sphinx.ext.linkcode>` extension will
only inject references for an ``html`` builder.
Expand Down
34 changes: 24 additions & 10 deletions sphinx/builders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,33 +59,38 @@ class Builder:
Builds target formats from the reST sources.
"""

#: The builder's name, for the -b command line option.
name = ''
#: The builder's name. This is the name used for the
#: :option:`sphinx-build -b` command line option.
name: str = ''
#: The builder's output format, or '' if no document output is produced.
format = ''
#: This is commonly the file extension, e.g. "html", but can technically
#: be any string. Its value can be used by various components such as
#: :class:`.SphinxPostTransform` or extensions to determine whether they
#: can work with the builder.
format: str = ''
#: The message emitted upon successful build completion. This can be a
#: printf-style template string with the following keys: ``outdir``,
#: ``project``
epilog = ''
epilog: str = ''

#: default translator class for the builder. This can be overridden by
#: :py:meth:`~sphinx.application.Sphinx.set_translator`.
default_translator_class: type[nodes.NodeVisitor]
# doctree versioning method
versioning_method = 'none'
versioning_compare = False
#: allow parallel write_doc() calls
allow_parallel = False
#: Whether it is safe to make parallel :meth:`~.Builder.write_doc()` calls.
allow_parallel: bool = False
# support translation
use_message_catalog = True

#: The list of MIME types of image formats supported by the builder.
#: Image files are searched in the order in which they appear here.
supported_image_types: list[str] = []
#: The builder can produce output documents that may fetch external images when opened.
supported_remote_images = False
supported_remote_images: bool = False
#: The file format produced by the builder allows images to be embedded using data-URIs.
supported_data_uri_images = False
supported_data_uri_images: bool = False

def __init__(self, app: Sphinx, env: BuildEnvironment) -> None:
self.srcdir = app.srcdir
Expand Down Expand Up @@ -159,7 +164,7 @@ def get_target_uri(self, docname: str, typ: str | None = None) -> str:
def get_relative_uri(self, from_: str, to: str, typ: str | None = None) -> str:
"""Return a relative URI between two source filenames.
May raise environment.NoUri if there's no way to return a sensible URI.
Raise :exc:`!sphinx.errors.NoUri` if there's no way to return a sensible URI.
"""
return relative_uri(
self.get_target_uri(from_),
Expand Down Expand Up @@ -789,7 +794,16 @@ def copy_assets(self) -> None:
pass

def write_doc(self, docname: str, doctree: nodes.document) -> None:
"""Where you actually write something to the filesystem."""
"""
Write the output file for the document given by
:term:`docname <document name>`.
*doctree* defines the content to be written.
The output filename must be determined within this method, typically by
calling :meth:`~.Builder.get_target_uri` or
:meth:`~.Builder.get_relative_uri`.
"""
raise NotImplementedError

def write_doc_serialized(self, docname: str, doctree: nodes.document) -> None:
Expand Down

0 comments on commit b618917

Please sign in to comment.