diff --git a/doc/extdev/builderapi.rst b/doc/extdev/builderapi.rst index ccc0da8c5bd..4aac7e51394 100644 --- a/doc/extdev/builderapi.rst +++ b/doc/extdev/builderapi.rst @@ -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 @@ -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 @@ -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 ` extension will only inject references for an ``html`` builder. diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index 68c62d9d125..1a77785e695 100644 --- a/sphinx/builders/__init__.py +++ b/sphinx/builders/__init__.py @@ -59,14 +59,19 @@ 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`. @@ -74,8 +79,8 @@ class Builder: # 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 @@ -83,9 +88,9 @@ class 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 @@ -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_), @@ -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 `. + + *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: