| 1 |
.. _writing-builders: |
| 2 |
|
| 3 |
Builder API |
| 4 |
=========== |
| 5 |
|
| 6 |
.. currentmodule:: sphinx.builders |
| 7 |
|
| 8 |
.. class:: Builder |
| 9 |
|
| 10 |
This is the base class for all builders. |
| 11 |
|
| 12 |
It follows this basic workflow: |
| 13 |
|
| 14 |
.. graphviz:: /_static/diagrams/sphinx_build_flow.dot |
| 15 |
:caption: Call graph for the standard Sphinx build workflow |
| 16 |
|
| 17 |
.. rubric:: Overridable Attributes |
| 18 |
|
| 19 |
These class attributes should be set on builder sub-classes: |
| 20 |
|
| 21 |
.. autoattribute:: name |
| 22 |
.. autoattribute:: format |
| 23 |
.. autoattribute:: epilog |
| 24 |
.. autoattribute:: allow_parallel |
| 25 |
.. autoattribute:: supported_image_types |
| 26 |
.. autoattribute:: supported_remote_images |
| 27 |
.. autoattribute:: supported_data_uri_images |
| 28 |
.. autoattribute:: default_translator_class |
| 29 |
|
| 30 |
.. rubric:: Core Methods |
| 31 |
|
| 32 |
These methods define the core build workflow and must not be overridden: |
| 33 |
|
| 34 |
.. automethod:: build_all |
| 35 |
.. automethod:: build_specific |
| 36 |
.. automethod:: build_update |
| 37 |
.. automethod:: build |
| 38 |
.. automethod:: read |
| 39 |
.. automethod:: read_doc |
| 40 |
.. automethod:: write_doctree |
| 41 |
.. automethod:: write |
| 42 |
|
| 43 |
.. rubric:: Abstract Methods |
| 44 |
|
| 45 |
These must be implemented in builder sub-classes: |
| 46 |
|
| 47 |
.. automethod:: get_outdated_docs |
| 48 |
.. automethod:: write_doc |
| 49 |
.. automethod:: get_target_uri |
| 50 |
|
| 51 |
.. rubric:: Overridable Methods |
| 52 |
|
| 53 |
These methods can be overridden in builder sub-classes: |
| 54 |
|
| 55 |
.. automethod:: init |
| 56 |
.. automethod:: write_documents |
| 57 |
.. automethod:: prepare_writing |
| 58 |
.. automethod:: copy_assets |
| 59 |
.. automethod:: get_relative_uri |
| 60 |
.. automethod:: finish |
| 61 |
|
| 62 |
.. rubric:: Attributes |
| 63 |
|
| 64 |
Attributes that are callable from the builder instance: |
| 65 |
|
| 66 |
.. attribute:: events |
| 67 |
|
| 68 |
An :class:`.EventManager` object. |
| 69 |
|
| 70 |
.. rubric:: Overridable Attributes (extensions) |
| 71 |
|
| 72 |
Builder sub-classes can set these attributes to support built-in extensions: |
| 73 |
|
| 74 |
.. attribute:: supported_linkcode |
| 75 |
:type: str |
| 76 |
|
| 77 |
By default, the :mod:`linkcode <sphinx.ext.linkcode>` extension will |
| 78 |
only inject references for an ``html`` builder. |
| 79 |
The ``supported_linkcode`` class attribute can be defined in a |
| 80 |
non-HTML builder to support managing references generated by linkcode. |
| 81 |
The expected value for this attribute is an expression |
| 82 |
which is compatible with :rst:dir:`only`. |
| 83 |
|
| 84 |
For example, if a builder was named ``custom-builder``, |
| 85 |
the following can be used: |
| 86 |
|
| 87 |
.. code-block:: python |
| 88 |
|
| 89 |
class CustomBuilder(Builder): |
| 90 |
supported_linkcode = 'custom-builder' |
| 91 |
... |