Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve builder API doc #13008

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Improve builder API doc
  • Loading branch information
timhoffm committed Oct 11, 2024
commit b6189170900f07ed2228b0ca37b7a74f0545e126
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:
timhoffm marked this conversation as resolved.
Show resolved Hide resolved

.. 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
AA-Turner marked this conversation as resolved.
Show resolved Hide resolved
# 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.
timhoffm marked this conversation as resolved.
Show resolved Hide resolved
"""
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.
timhoffm marked this conversation as resolved.
Show resolved Hide resolved

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
Loading