sphinx-build使用¶
The sphinx-build script builds a Sphinx documentation set. It is called like this:
$ sphinx-build [options] sourcedir builddir [filenames]
where sourcedir is the 资源目录, and builddir is the directory in which you want to place the built documentation. Most of the time, you don’t need to specify any filenames.
The sphinx-build script has several options:
-
-bbuildername¶ The most important option: it selects a builder. The most common builders are:
- html
- Build HTML pages. This is the default builder.
- dirhtml
- Build HTML pages, but with a single directory per document. Makes for
prettier URLs (no
.html) if served from a webserver. - singlehtml
- Build a single HTML with the whole content.
- htmlhelp, qthelp, devhelp, epub
- Build HTML files with additional information for building a documentation collection in one of these formats.
- latex
- Build LaTeX sources that can be compiled to a PDF document using pdflatex.
- man
- Build manual pages in groff format for UNIX systems.
- texinfo
- Build Texinfo files that can be processed into Info files using makeinfo.
- text
- Build plain text files.
- gettext
- Build gettext-style message catalogs (
.potfiles). - doctest
- Run all doctests in the documentation, if the
doctestextension is enabled. - linkcheck
- Check the integrity of all external links.
- xml
- Build Docutils-native XML files.
- pseudoxml
- Build compact pretty-printed “pseudo-XML” files displaying the internal structure of the intermediate document trees.
See 构建器 for a list of all builders shipped with Sphinx. Extensions can add their own builders.
-
-a¶ If given, always write all output files. The default is to only write output files for new and changed source files. (This may not apply to all builders.)
-
-E¶ Don’t use a saved 环境 (the structure caching all cross-references), but rebuild it completely. The default is to only read and parse source files that are new or have changed since the last run.
-
-ttag¶ Define the tag tag. This is relevant for
onlydirectives that only include their content if this tag is set.0.6 新版功能.
-
-dpath¶ Since Sphinx has to read and parse all source files before it can write an output file, the parsed source files are cached as “doctree pickles”. Normally, these files are put in a directory called
.doctreesunder the build directory; with this option you can select a different cache directory (the doctrees can be shared between all builders).
-
-cpath¶ Don’t look for the
conf.pyin the source directory, but use the given configuration directory instead. Note that various other files and paths given by configuration values are expected to be relative to the configuration directory, so they will have to be present at this location too.0.3 新版功能.
-
-C¶ Don’t look for a configuration file; only take options via the
-Doption.0.5 新版功能.
-
-Dsetting=value¶ Override a configuration value set in the
conf.pyfile. The value must be a string or dictionary value. For the latter, supply the setting name and key like this:-D latex_elements.docclass=scrartcl. For boolean values, use0or1as the value.在 0.6 版更改: The value can now be a dictionary value.
-
-Aname=value¶ Make the name assigned to value in the HTML templates.
0.5 新版功能.
-
-n¶ Run in nit-picky mode. Currently, this generates warnings for all missing references.
-
-N¶ Do not emit colored output. (On Windows, colored output is disabled in any case.)
-
-v¶ Increase verbosity. This option can be given up to three times to get more debug output. It implies
-T.1.2 新版功能.
-
-q¶ Do not output anything on standard output, only write warnings and errors to standard error.
-
-Q¶ Do not output anything on standard output, also suppress warnings. Only errors are written to standard error.
-
-wfile¶ Write warnings (and errors) to the given file, in addition to standard error.
-
-W¶ Turn warnings into errors. This means that the build stops at the first warning and
sphinx-buildexits with exit status 1.
-
-T¶ Display the full traceback when an unhandled exception occurs. Otherwise, only a summary is displayed and the traceback information is saved to a file for further analysis.
1.2 新版功能.
-
-P¶ (Useful for debugging only.) Run the Python debugger,
pdb, if an unhandled exception occurs while building.
-
-h,--help,--version¶ Display usage summary or Sphinx version.
1.2 新版功能.
You can also give one or more filenames on the command line after the source and build directories. Sphinx will then try to build only these output files (and their dependencies).
Makefile选项¶
The Makefile and make.bat files created by
sphinx-quickstart usually run sphinx-build only with the
-b and -d options. However, they support the following
variables to customize behavior:
-
PAPER The value for
latex_paper_size.
-
SPHINXBUILD The command to use instead of
sphinx-build.
-
BUILDDIR The build directory to use instead of the one chosen in sphinx-quickstart.
-
SPHINXOPTS Additional options for sphinx-build.
使用sphinx-apidoc¶
The sphinx-apidoc generates completely automatic API documentation for a Python package. It is called like this:
$ sphinx-apidoc [options] -o outputdir packagedir [pathnames]
where packagedir is the path to the package to document, and outputdir is the directory where the generated sources are placed. Any pathnames given are paths to be excluded ignored during generation.
The sphinx-apidoc script has several options:
-
-ooutputdir¶ Gives the directory in which to place the generated output.
-
-f,--force¶ Normally, sphinx-apidoc does not overwrite any files. Use this option to force the overwrite of all files that it generates.
-
-n,--dry-run¶ With this option given, no files will be written at all.
-
-ssuffix¶ This option selects the file name suffix of output files. By default, this is
rst.
-
-dmaxdepth¶ This sets the maximum depth of the table of contents, if one is generated.
-
-l,--follow-links¶ This option makes sphinx-apidoc follow symbolic links when recursing the filesystem to discover packages and modules. You may need it if you want to generate documentation from a source directory managed by collective.recipe.omelette. By default, symbolic links are skipped.
1.2 新版功能.
-
-T,--no-toc¶ This prevents the generation of a table-of-contents file
modules.rst. This has no effect when--fullis given.
-
-F,--full¶ This option makes sphinx-apidoc create a full Sphinx project, using the same mechanism as sphinx-quickstart. Most configuration values are set to default values, but you can influence the most important ones using the following options.