| 1 |
.. highlight:: rst |
| 2 |
|
| 3 |
Application API |
| 4 |
=============== |
| 5 |
|
| 6 |
.. module:: sphinx.application |
| 7 |
:synopsis: Application class and extensibility interface. |
| 8 |
|
| 9 |
|
| 10 |
Each Sphinx extension is a Python module with at least a :func:`setup` |
| 11 |
function. This function is called at initialization time with one argument, |
| 12 |
the application object representing the Sphinx process. |
| 13 |
|
| 14 |
.. class:: Sphinx |
| 15 |
|
| 16 |
This application object has the public API described in the following. |
| 17 |
|
| 18 |
Extension setup |
| 19 |
--------------- |
| 20 |
|
| 21 |
These methods are usually called in an extension's ``setup()`` function. |
| 22 |
|
| 23 |
Examples of using the Sphinx extension API can be seen in the :mod:`sphinx.ext` |
| 24 |
package. |
| 25 |
|
| 26 |
.. currentmodule:: sphinx.application |
| 27 |
|
| 28 |
.. automethod:: Sphinx.setup_extension |
| 29 |
|
| 30 |
.. automethod:: Sphinx.require_sphinx |
| 31 |
|
| 32 |
.. automethod:: Sphinx.connect |
| 33 |
|
| 34 |
.. automethod:: Sphinx.disconnect |
| 35 |
|
| 36 |
.. automethod:: Sphinx.add_builder |
| 37 |
|
| 38 |
.. automethod:: Sphinx.add_config_value |
| 39 |
|
| 40 |
.. automethod:: Sphinx.add_event |
| 41 |
|
| 42 |
.. automethod:: Sphinx.set_translator |
| 43 |
|
| 44 |
.. automethod:: Sphinx.add_node |
| 45 |
|
| 46 |
.. automethod:: Sphinx.add_enumerable_node |
| 47 |
|
| 48 |
.. automethod:: Sphinx.add_directive |
| 49 |
|
| 50 |
.. automethod:: Sphinx.add_role |
| 51 |
|
| 52 |
.. automethod:: Sphinx.add_generic_role |
| 53 |
|
| 54 |
.. automethod:: Sphinx.add_domain |
| 55 |
|
| 56 |
.. automethod:: Sphinx.add_directive_to_domain |
| 57 |
|
| 58 |
.. automethod:: Sphinx.add_role_to_domain |
| 59 |
|
| 60 |
.. automethod:: Sphinx.add_index_to_domain |
| 61 |
|
| 62 |
.. automethod:: Sphinx.add_object_type |
| 63 |
|
| 64 |
.. automethod:: Sphinx.add_crossref_type |
| 65 |
|
| 66 |
.. automethod:: Sphinx.add_transform |
| 67 |
|
| 68 |
.. automethod:: Sphinx.add_post_transform |
| 69 |
|
| 70 |
.. automethod:: Sphinx.add_js_file |
| 71 |
|
| 72 |
.. automethod:: Sphinx.add_css_file |
| 73 |
|
| 74 |
.. automethod:: Sphinx.add_static_dir |
| 75 |
|
| 76 |
.. automethod:: Sphinx.add_latex_package |
| 77 |
|
| 78 |
.. automethod:: Sphinx.add_lexer |
| 79 |
|
| 80 |
.. automethod:: Sphinx.add_autodocumenter |
| 81 |
|
| 82 |
.. automethod:: Sphinx.add_autodoc_attrgetter |
| 83 |
|
| 84 |
.. automethod:: Sphinx.add_search_language |
| 85 |
|
| 86 |
.. automethod:: Sphinx.add_source_suffix |
| 87 |
|
| 88 |
.. automethod:: Sphinx.add_source_parser |
| 89 |
|
| 90 |
.. automethod:: Sphinx.add_env_collector |
| 91 |
|
| 92 |
.. automethod:: Sphinx.add_html_theme |
| 93 |
|
| 94 |
.. automethod:: Sphinx.add_html_math_renderer |
| 95 |
|
| 96 |
.. automethod:: Sphinx.add_message_catalog |
| 97 |
|
| 98 |
.. automethod:: Sphinx.is_parallel_allowed |
| 99 |
|
| 100 |
.. automethod:: Sphinx.set_html_assets_policy |
| 101 |
|
| 102 |
.. exception:: ExtensionError |
| 103 |
|
| 104 |
All these methods raise this exception if something went wrong with the |
| 105 |
extension API. |
| 106 |
|
| 107 |
|
| 108 |
Emitting events |
| 109 |
--------------- |
| 110 |
|
| 111 |
.. attention:: |
| 112 |
|
| 113 |
Extension developers should prefer using the event manager (``events``) |
| 114 |
object directly, via :meth:`.EventManager.emit` |
| 115 |
and :meth:`.EventManager.emit_firstresult`, |
| 116 |
which have identical behaviour to the methods below. |
| 117 |
|
| 118 |
.. class:: Sphinx |
| 119 |
:no-index: |
| 120 |
|
| 121 |
.. automethod:: emit |
| 122 |
|
| 123 |
.. automethod:: emit_firstresult |
| 124 |
|
| 125 |
|
| 126 |
Sphinx runtime information |
| 127 |
-------------------------- |
| 128 |
|
| 129 |
The application object also provides runtime information as attributes. |
| 130 |
|
| 131 |
.. attribute:: Sphinx.project |
| 132 |
|
| 133 |
Target project. See :class:`.Project`. |
| 134 |
|
| 135 |
.. attribute:: Sphinx.srcdir |
| 136 |
|
| 137 |
Source directory. |
| 138 |
|
| 139 |
.. attribute:: Sphinx.confdir |
| 140 |
|
| 141 |
Directory containing ``conf.py``. |
| 142 |
|
| 143 |
.. attribute:: Sphinx.doctreedir |
| 144 |
|
| 145 |
Directory for storing pickled doctrees. |
| 146 |
|
| 147 |
.. attribute:: Sphinx.outdir |
| 148 |
|
| 149 |
Directory for storing built document. |
| 150 |
|
| 151 |
.. autoattribute:: Sphinx.fresh_env_used |
| 152 |
|
| 153 |
Sphinx core events |
| 154 |
------------------ |
| 155 |
|
| 156 |
.. note:: Moved to :ref:`events`. |
| 157 |
|
| 158 |
Checking the Sphinx version |
| 159 |
--------------------------- |
| 160 |
|
| 161 |
.. currentmodule:: sphinx |
| 162 |
|
| 163 |
Use this to adapt your extension to API changes in Sphinx. |
| 164 |
|
| 165 |
.. autodata:: version_info |
| 166 |
|
| 167 |
|
| 168 |
The Config object |
| 169 |
----------------- |
| 170 |
|
| 171 |
.. currentmodule:: sphinx.config |
| 172 |
|
| 173 |
.. autoclass:: Config |
| 174 |
|
| 175 |
.. py:class:: ENUM |
| 176 |
:no-typesetting: |
| 177 |
|
| 178 |
|
| 179 |
.. _template-bridge: |
| 180 |
|
| 181 |
The template bridge |
| 182 |
------------------- |
| 183 |
|
| 184 |
.. currentmodule:: sphinx.application |
| 185 |
|
| 186 |
.. autoclass:: TemplateBridge |
| 187 |
:members: |
| 188 |
|
| 189 |
|
| 190 |
.. _exceptions: |
| 191 |
|
| 192 |
Exceptions |
| 193 |
---------- |
| 194 |
|
| 195 |
.. module:: sphinx.errors |
| 196 |
|
| 197 |
.. autoexception:: SphinxError |
| 198 |
|
| 199 |
.. autoexception:: ConfigError |
| 200 |
|
| 201 |
.. autoexception:: ExtensionError |
| 202 |
|
| 203 |
.. autoexception:: ThemeError |
| 204 |
|
| 205 |
.. autoexception:: VersionRequirementError |