| 1 |
sphinx-build |
| 2 |
============ |
| 3 |
|
| 4 |
Synopsis |
| 5 |
-------- |
| 6 |
|
| 7 |
**sphinx-build** [*options*] <*sourcedir*> <*outputdir*> [*filenames* ...] |
| 8 |
|
| 9 |
Description |
| 10 |
----------- |
| 11 |
|
| 12 |
:program:`sphinx-build` generates documentation from the files in |
| 13 |
``<sourcedir>`` and places it in the ``<outputdir>``. |
| 14 |
|
| 15 |
:program:`sphinx-build` looks for ``<sourcedir>/conf.py`` for the configuration |
| 16 |
settings. :manpage:`sphinx-quickstart(1)` may be used to generate template |
| 17 |
files, including ``conf.py``. |
| 18 |
|
| 19 |
:program:`sphinx-build` can create documentation in different formats. A |
| 20 |
format is selected by specifying the builder name on the command line; it |
| 21 |
defaults to HTML. Builders can also perform other tasks related to |
| 22 |
documentation processing. For a list of available builders, refer to |
| 23 |
:doc:`/usage/builders/index`. |
| 24 |
|
| 25 |
By default, everything that is outdated is built. Output only for selected |
| 26 |
files can be built by specifying individual filenames. |
| 27 |
|
| 28 |
Options |
| 29 |
------- |
| 30 |
|
| 31 |
.. program:: sphinx-build |
| 32 |
|
| 33 |
.. _make_mode: |
| 34 |
|
| 35 |
.. option:: -M buildername |
| 36 |
|
| 37 |
Select a builder, using the *make-mode*. |
| 38 |
See :doc:`/usage/builders/index` for a list of all of Sphinx's built-in builders. |
| 39 |
Extensions can add their own builders. |
| 40 |
|
| 41 |
.. important:: |
| 42 |
Sphinx only recognizes the ``-M`` option if it is used first, along with |
| 43 |
the source and output directories, before any other options are passed. |
| 44 |
For example:: |
| 45 |
|
| 46 |
sphinx-build -M html ./source ./build --fail-on-warning |
| 47 |
|
| 48 |
The *make-mode* provides the same build functionality as |
| 49 |
a default :ref:`Makefile or Make.bat <makefile_options>`, |
| 50 |
and provides the following additional build pipelines: |
| 51 |
|
| 52 |
*latexpdf* |
| 53 |
Build LaTeX files and run them through :program:`pdflatex`, or as per |
| 54 |
:confval:`latex_engine` setting. |
| 55 |
If :confval:`language` is set to ``'ja'``, will use automatically |
| 56 |
the :program:`platex/dvipdfmx` latex to PDF pipeline. |
| 57 |
|
| 58 |
*info* |
| 59 |
Build Texinfo files and run them through :program:`makeinfo`. |
| 60 |
|
| 61 |
*help* |
| 62 |
Output a list of valid builder targets, and exit. |
| 63 |
|
| 64 |
.. note:: |
| 65 |
|
| 66 |
The default output directory locations when using *make-mode* |
| 67 |
differ from the defaults when using :option:`-b`. |
| 68 |
|
| 69 |
* doctrees are saved to ``<outputdir>/doctrees`` |
| 70 |
* output files are saved to ``<outputdir>/<builder name>`` |
| 71 |
|
| 72 |
.. versionadded:: 1.2.1 |
| 73 |
|
| 74 |
.. option:: -b buildername, --builder buildername |
| 75 |
|
| 76 |
Selects a builder. |
| 77 |
|
| 78 |
See :doc:`/usage/builders/index` for a list of all of Sphinx's built-in builders. |
| 79 |
Extensions can add their own builders. |
| 80 |
|
| 81 |
.. versionchanged:: 7.3 |
| 82 |
Add ``--builder`` long option. |
| 83 |
|
| 84 |
.. option:: -a, --write-all |
| 85 |
|
| 86 |
If given, always write all output files. The default is to only write output |
| 87 |
files for new and changed source files. (This may not apply to all |
| 88 |
builders.) |
| 89 |
|
| 90 |
.. note:: This option does not re-read source files. |
| 91 |
To read and re-process every file, |
| 92 |
use :option:`--fresh-env` instead. |
| 93 |
|
| 94 |
.. versionchanged:: 7.3 |
| 95 |
Add ``--write-all`` long option. |
| 96 |
|
| 97 |
.. option:: -E, --fresh-env |
| 98 |
|
| 99 |
Don't use a saved :term:`environment` (the structure caching all |
| 100 |
cross-references), but rebuild it completely. The default is to only read |
| 101 |
and parse source files that are new or have changed since the last run. |
| 102 |
|
| 103 |
.. versionchanged:: 7.3 |
| 104 |
Add ``--fresh-env`` long option. |
| 105 |
|
| 106 |
.. option:: -t tag, --tag tag |
| 107 |
|
| 108 |
Define the tag *tag*. |
| 109 |
This is relevant for :rst:dir:`only` directives that |
| 110 |
include their content only if certain tags are set. |
| 111 |
See :ref:`including content based on tags <tags>` for further detail. |
| 112 |
|
| 113 |
.. versionadded:: 0.6 |
| 114 |
|
| 115 |
.. versionchanged:: 7.3 |
| 116 |
Add ``--tag`` long option. |
| 117 |
|
| 118 |
.. option:: -d path, --doctree-dir path |
| 119 |
|
| 120 |
Since Sphinx has to read and parse all source files before it can write an |
| 121 |
output file, the parsed source files are cached as "doctree pickles". |
| 122 |
Normally, these files are put in a directory called :file:`.doctrees` under |
| 123 |
the build directory; with this option you can select a different cache |
| 124 |
directory (the doctrees can be shared between all builders). |
| 125 |
|
| 126 |
.. versionchanged:: 7.3 |
| 127 |
Add ``--doctree-dir`` long option. |
| 128 |
|
| 129 |
.. option:: -j N, --jobs N |
| 130 |
|
| 131 |
Distribute the build over *N* processes in parallel, to make building on |
| 132 |
multiprocessor machines more effective. |
| 133 |
This feature only works on systems supporting "fork". Windows is not supported. |
| 134 |
Note that not all parts and not all builders of Sphinx can be parallelized. |
| 135 |
If ``auto`` argument is given, |
| 136 |
Sphinx uses the number of CPUs as *N*. Defaults to 1. |
| 137 |
|
| 138 |
.. versionadded:: 1.2 |
| 139 |
This option should be considered *experimental*. |
| 140 |
|
| 141 |
.. versionchanged:: 1.7 |
| 142 |
Support ``auto`` argument. |
| 143 |
|
| 144 |
.. versionchanged:: 6.2 |
| 145 |
Add ``--jobs`` long option. |
| 146 |
|
| 147 |
.. option:: -c path, --conf-dir path |
| 148 |
|
| 149 |
Don't look for the :file:`conf.py` in the source directory, but use the given |
| 150 |
configuration directory instead. Note that various other files and paths |
| 151 |
given by configuration values are expected to be relative to the |
| 152 |
configuration directory, so they will have to be present at this location |
| 153 |
too. |
| 154 |
|
| 155 |
.. versionadded:: 0.3 |
| 156 |
|
| 157 |
.. versionchanged:: 7.3 |
| 158 |
Add ``--conf-dir`` long option. |
| 159 |
|
| 160 |
.. option:: -C, --isolated |
| 161 |
|
| 162 |
Don't look for a configuration file; only take options via the :option:`--define` option. |
| 163 |
|
| 164 |
.. versionadded:: 0.5 |
| 165 |
|
| 166 |
.. versionchanged:: 7.3 |
| 167 |
Add ``--isolated`` long option. |
| 168 |
|
| 169 |
.. option:: -D setting=value, --define setting=value |
| 170 |
|
| 171 |
Override a configuration value set in the :file:`conf.py` file. The value |
| 172 |
must be a number, string, list or dictionary value. |
| 173 |
|
| 174 |
For lists, you can separate elements with a comma like this: ``-D |
| 175 |
html_theme_path=path1,path2``. |
| 176 |
|
| 177 |
For dictionary values, supply the setting name and key like this: |
| 178 |
``-D latex_elements.docclass=scrartcl``. |
| 179 |
|
| 180 |
For boolean values, use ``0`` or ``1`` as the value. |
| 181 |
|
| 182 |
.. versionchanged:: 0.6 |
| 183 |
The value can now be a dictionary value. |
| 184 |
|
| 185 |
.. versionchanged:: 1.3 |
| 186 |
The value can now also be a list value. |
| 187 |
|
| 188 |
.. versionchanged:: 7.3 |
| 189 |
Add ``--define`` long option. |
| 190 |
|
| 191 |
.. option:: -A name=value, --html-define name=value |
| 192 |
|
| 193 |
Make the *name* assigned to *value* in the HTML templates. |
| 194 |
|
| 195 |
.. versionadded:: 0.5 |
| 196 |
|
| 197 |
.. versionchanged:: 7.3 |
| 198 |
Add ``--html-define`` long option. |
| 199 |
|
| 200 |
.. option:: -n, --nitpicky |
| 201 |
|
| 202 |
Run in nitpicky mode. Currently, this generates warnings for all missing |
| 203 |
references. See the config value :confval:`nitpick_ignore` for a way to |
| 204 |
exclude some references as "known missing". |
| 205 |
|
| 206 |
.. versionchanged:: 7.3 |
| 207 |
Add ``--nitpicky`` long option. |
| 208 |
|
| 209 |
.. option:: -N, --no-color |
| 210 |
|
| 211 |
Do not emit colored output. |
| 212 |
|
| 213 |
.. versionchanged:: 1.6 |
| 214 |
Add ``--no-color`` long option. |
| 215 |
|
| 216 |
.. option:: --color |
| 217 |
|
| 218 |
Emit colored output. Auto-detected by default. |
| 219 |
|
| 220 |
.. versionadded:: 1.6 |
| 221 |
|
| 222 |
.. option:: -v, --verbose |
| 223 |
|
| 224 |
Increase verbosity (log-level). This option can be given up to three times |
| 225 |
to get more debug logging output. It implies :option:`-T`. |
| 226 |
|
| 227 |
.. versionadded:: 1.2 |
| 228 |
|
| 229 |
.. versionchanged:: 7.3 |
| 230 |
Add ``--verbose`` long option. |
| 231 |
|
| 232 |
.. option:: -q, --quiet |
| 233 |
|
| 234 |
Do not output anything on standard output, only write warnings and errors to |
| 235 |
standard error. |
| 236 |
|
| 237 |
.. versionchanged:: 7.3 |
| 238 |
Add ``--quiet`` long option. |
| 239 |
|
| 240 |
.. option:: -Q, --silent |
| 241 |
|
| 242 |
Do not output anything on standard output, also suppress warnings. Only |
| 243 |
errors are written to standard error. |
| 244 |
|
| 245 |
.. versionchanged:: 7.3 |
| 246 |
Add ``--silent`` long option. |
| 247 |
|
| 248 |
.. option:: -w file, --warning-file file |
| 249 |
|
| 250 |
Write warnings (and errors) to the given file, in addition to standard error. |
| 251 |
|
| 252 |
.. versionchanged:: 7.3 |
| 253 |
|
| 254 |
ANSI control sequences are stripped when writing to *file*. |
| 255 |
|
| 256 |
.. versionchanged:: 7.3 |
| 257 |
Add ``--warning-file`` long option. |
| 258 |
|
| 259 |
.. option:: -W, --fail-on-warning |
| 260 |
|
| 261 |
Turn warnings into errors. |
| 262 |
This means that :program:`sphinx-build` exits with exit status 1 |
| 263 |
if any warnings are generated during the build. |
| 264 |
|
| 265 |
.. versionchanged:: 7.3 |
| 266 |
Add ``--fail-on-warning`` long option. |
| 267 |
.. versionchanged:: 8.1 |
| 268 |
:program:`sphinx-build` no longer exits on the first warning, |
| 269 |
but instead runs the entire build and exits with exit status 1 |
| 270 |
if any warnings were generated. |
| 271 |
This behaviour was previously enabled with :option:`--keep-going`. |
| 272 |
|
| 273 |
.. option:: --keep-going |
| 274 |
|
| 275 |
From Sphinx 8.1, :option:`!--keep-going` is always enabled. |
| 276 |
Previously, it was only applicable whilst using :option:`--fail-on-warning`, |
| 277 |
which by default exited :program:`sphinx-build` on the first warning. |
| 278 |
Using :option:`!--keep-going` runs :program:`sphinx-build` to completion |
| 279 |
and exits with exit status 1 if errors are encountered. |
| 280 |
|
| 281 |
.. versionadded:: 1.8 |
| 282 |
.. versionchanged:: 8.1 |
| 283 |
:program:`sphinx-build` no longer exits on the first warning, |
| 284 |
meaning that in effect :option:`!--keep-going` is always enabled. |
| 285 |
The option is retained for compatibility, but may be removed at some |
| 286 |
later date. |
| 287 |
|
| 288 |
.. xref RemovedInSphinx10Warning: deprecate this option in Sphinx 10 |
| 289 |
or no earlier than 2026-01-01. |
| 290 |
|
| 291 |
.. option:: -T, --show-traceback |
| 292 |
|
| 293 |
Display the full traceback when an unhandled exception occurs. Otherwise, |
| 294 |
only a summary is displayed and the traceback information is saved to a file |
| 295 |
for further analysis. |
| 296 |
|
| 297 |
.. versionadded:: 1.2 |
| 298 |
|
| 299 |
.. versionchanged:: 7.3 |
| 300 |
Add ``--show-traceback`` long option. |
| 301 |
|
| 302 |
.. option:: -P, --pdb |
| 303 |
|
| 304 |
(Useful for debugging only.) Run the Python debugger, :mod:`pdb`, if an |
| 305 |
unhandled exception occurs while building. |
| 306 |
|
| 307 |
.. versionchanged:: 7.3 |
| 308 |
Add ``--pdb`` long option. |
| 309 |
|
| 310 |
.. option:: --exception-on-warning |
| 311 |
|
| 312 |
Raise an exception when a warning is emitted during the build. |
| 313 |
This can be useful in combination with :option:`--pdb` to debug warnings. |
| 314 |
|
| 315 |
.. versionadded:: 8.1 |
| 316 |
|
| 317 |
.. option:: -h, --help, --version |
| 318 |
|
| 319 |
Display usage summary or Sphinx version. |
| 320 |
|
| 321 |
.. versionadded:: 1.2 |
| 322 |
|
| 323 |
You can also give one or more filenames on the command line after the source |
| 324 |
and build directories. Sphinx will then try to build only these output files |
| 325 |
(and their dependencies). |
| 326 |
|
| 327 |
Environment Variables |
| 328 |
--------------------- |
| 329 |
|
| 330 |
The :program:`sphinx-build` refers following environment variables: |
| 331 |
|
| 332 |
.. describe:: MAKE |
| 333 |
|
| 334 |
A path to make command. A command name is also allowed. |
| 335 |
:program:`sphinx-build` uses it to invoke sub-build process on make-mode. |
| 336 |
|
| 337 |
.. _makefile_options: |
| 338 |
|
| 339 |
.. rubric:: Makefile Options |
| 340 |
|
| 341 |
The :file:`Makefile` and :file:`make.bat` files created by |
| 342 |
:program:`sphinx-quickstart` usually run :program:`sphinx-build` only with the |
| 343 |
:option:`-b` and :option:`-d` options. However, they support the following |
| 344 |
variables to customize behavior: |
| 345 |
|
| 346 |
.. describe:: PAPER |
| 347 |
|
| 348 |
This sets the ``'papersize'`` key of :confval:`latex_elements`: |
| 349 |
i.e. ``PAPER=a4`` sets it to ``'a4paper'`` and ``PAPER=letter`` to |
| 350 |
``'letterpaper'``. |
| 351 |
|
| 352 |
.. note:: |
| 353 |
|
| 354 |
Usage of this environment variable got broken at Sphinx 1.5 as |
| 355 |
``a4`` or ``letter`` ended up as option to LaTeX document in |
| 356 |
place of the needed ``a4paper``, resp. ``letterpaper``. Fixed at |
| 357 |
1.7.7. |
| 358 |
|
| 359 |
.. describe:: SPHINXBUILD |
| 360 |
|
| 361 |
The command to use instead of ``sphinx-build``. |
| 362 |
|
| 363 |
.. describe:: BUILDDIR |
| 364 |
|
| 365 |
The build directory to use instead of the one chosen in |
| 366 |
:program:`sphinx-quickstart`. |
| 367 |
|
| 368 |
.. describe:: SPHINXOPTS |
| 369 |
|
| 370 |
Additional options for :program:`sphinx-build`. These options can |
| 371 |
also be set via the shortcut variable **O** (capital 'o'). |
| 372 |
|
| 373 |
.. describe:: NO_COLOR |
| 374 |
|
| 375 |
When set (regardless of value), :program:`sphinx-build` will not use color |
| 376 |
in terminal output. ``NO_COLOR`` takes precedence over ``FORCE_COLOR``. See |
| 377 |
`no-color.org <https://no-color.org/>`__ for other libraries supporting this |
| 378 |
community standard. |
| 379 |
|
| 380 |
.. versionadded:: 4.5.0 |
| 381 |
|
| 382 |
.. describe:: FORCE_COLOR |
| 383 |
|
| 384 |
When set (regardless of value), :program:`sphinx-build` will use color in |
| 385 |
terminal output. ``NO_COLOR`` takes precedence over ``FORCE_COLOR``. |
| 386 |
|
| 387 |
.. versionadded:: 4.5.0 |
| 388 |
|
| 389 |
.. _when-deprecation-warnings-are-displayed: |
| 390 |
|
| 391 |
Deprecation Warnings |
| 392 |
-------------------- |
| 393 |
|
| 394 |
If any deprecation warning like ``RemovedInSphinxXXXWarning`` are displayed |
| 395 |
when building a user's document, some Sphinx extension is using deprecated |
| 396 |
features. In that case, please report it to author of the extension. |
| 397 |
|
| 398 |
To disable the deprecation warnings, please set ``PYTHONWARNINGS=`` environment |
| 399 |
variable to your environment. For example: |
| 400 |
|
| 401 |
* ``PYTHONWARNINGS= make html`` (Linux/Mac) |
| 402 |
* ``export PYTHONWARNINGS=`` and do ``make html`` (Linux/Mac) |
| 403 |
* ``set PYTHONWARNINGS=`` and do ``make html`` (Windows) |
| 404 |
* modify your Makefile/make.bat and set the environment variable |
| 405 |
|
| 406 |
See also |
| 407 |
-------- |
| 408 |
|
| 409 |
:manpage:`sphinx-quickstart(1)` |