Skip to content

Commit b6269d3

Browse files
timhoffmchrisjsewellAA-Turner
authored
Improve documentation for the Builder API (#13008)
Co-authored-by: Chris Sewell <[email protected]> Co-authored-by: Adam Turner <[email protected]>
1 parent c46abc4 commit b6269d3

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

doc/extdev/builderapi.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Builder API
1616

1717
.. rubric:: Overridable Attributes
1818

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

2121
.. autoattribute:: name
2222
.. autoattribute:: format
@@ -29,8 +29,7 @@ Builder API
2929

3030
.. rubric:: Core Methods
3131

32-
These methods are predefined and should generally not be overridden,
33-
since they form the core of the build process:
32+
These methods define the core build workflow and must not be overridden:
3433

3534
.. automethod:: build_all
3635
.. automethod:: build_specific
@@ -73,11 +72,12 @@ Builder API
7372
Builder sub-classes can set these attributes to support built-in extensions:
7473

7574
.. attribute:: supported_linkcode
75+
:type: str
7676

7777
By default, the :mod:`linkcode <sphinx.ext.linkcode>` extension will
7878
only inject references for an ``html`` builder.
79-
The ``supported_linkcode`` attribute can be defined in a non-HTML builder
80-
to support managing references generated by linkcode.
79+
The ``supported_linkcode`` class attribute can be defined in a
80+
non-HTML builder to support managing references generated by linkcode.
8181
The expected value for this attribute is an expression
8282
which is compatible with :rst:dir:`only`.
8383

sphinx/builders/__init__.py

+28-13
Original file line numberDiff line numberDiff line change
@@ -59,33 +59,39 @@ class Builder:
5959
Builds target formats from the reST sources.
6060
"""
6161

62-
#: The builder's name, for the -b command line option.
63-
name = ''
62+
#: The builder's name.
63+
#: This is the value used to select builders on the command line.
64+
name: str = ''
6465
#: The builder's output format, or '' if no document output is produced.
65-
format = ''
66-
#: The message emitted upon successful build completion. This can be a
67-
#: printf-style template string with the following keys: ``outdir``,
68-
#: ``project``
69-
epilog = ''
66+
#: This is commonly the file extension, e.g. "html",
67+
#: though any string value is accepted.
68+
#: The builder's format string can be used by various components
69+
#: such as :class:`.SphinxPostTransform` or extensions to determine
70+
#: their compatibility with the builder.
71+
format: str = ''
72+
#: The message emitted upon successful build completion.
73+
#: This can be a printf-style template string
74+
#: with the following keys: ``outdir``, ``project``
75+
epilog: str = ''
7076

7177
#: default translator class for the builder. This can be overridden by
7278
#: :py:meth:`~sphinx.application.Sphinx.set_translator`.
7379
default_translator_class: type[nodes.NodeVisitor]
7480
# doctree versioning method
7581
versioning_method = 'none'
7682
versioning_compare = False
77-
#: allow parallel write_doc() calls
78-
allow_parallel = False
83+
#: Whether it is safe to make parallel :meth:`~.Builder.write_doc()` calls.
84+
allow_parallel: bool = False
7985
# support translation
8086
use_message_catalog = True
8187

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

9096
def __init__(self, app: Sphinx, env: BuildEnvironment) -> None:
9197
self.srcdir = app.srcdir
@@ -159,7 +165,7 @@ def get_target_uri(self, docname: str, typ: str | None = None) -> str:
159165
def get_relative_uri(self, from_: str, to: str, typ: str | None = None) -> str:
160166
"""Return a relative URI between two source filenames.
161167
162-
May raise environment.NoUri if there's no way to return a sensible URI.
168+
:raises: :exc:`!NoUri` if there's no way to return a sensible URI.
163169
"""
164170
return relative_uri(
165171
self.get_target_uri(from_),
@@ -789,7 +795,16 @@ def copy_assets(self) -> None:
789795
pass
790796

791797
def write_doc(self, docname: str, doctree: nodes.document) -> None:
792-
"""Where you actually write something to the filesystem."""
798+
"""
799+
Write the output file for the document
800+
801+
:param docname: the :term:`docname <document name>`.
802+
:param doctree: defines the content to be written.
803+
804+
The output filename must be determined within this method,
805+
typically by calling :meth:`~.Builder.get_target_uri`
806+
or :meth:`~.Builder.get_relative_uri`.
807+
"""
793808
raise NotImplementedError
794809

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

0 commit comments

Comments
 (0)