The 配置目录 must contain a file named conf.py. This file (containing Python code) is called the “build configuration file” and contains all configuration needed to customize Sphinx input and output behavior.
The configuration file is executed as Python code at build time (using execfile(), and with the current directory set to its containing directory), and therefore can execute arbitrarily complex code. Sphinx then reads simple names from the file’s namespace as its configuration.
Important points to note:
A list of strings that are module names of Sphinx extensions. These can be extensions coming with Sphinx (named sphinx.ext.*) or custom ones.
Note that you can extend sys.path within the conf file if your extensions live in another directory – but make sure you use absolute paths. If your extension path is relative to the 配置目录, use os.path.abspath() like so:
import sys, os
sys.path.append(os.path.abspath('sphinxext'))
extensions = ['extname']
That way, you can load an extension called extname from the subdirectory sphinxext.
The configuration file itself can be an extension; for that, you only need to provide a setup() function in it.
The file name extension of source files. Only files with this suffix will be read as sources. Default is '.rst'.
The encoding of all reST source files. The recommended encoding, and the default value, is 'utf-8-sig'.
0.5 新版功能: Previously, Sphinx accepted only UTF-8 encoded sources.
The document name of the “master” document, that is, the document that contains the root toctree directive. Default is 'contents'.
A list of glob-style patterns that should be excluded when looking for source files. [1] They are matched against the source file names relative to the source directory, using slashes as directory separators on all platforms.
Example patterns:
exclude_patterns is also consulted when looking for static files in html_static_path.
1.0 新版功能.
A list of document names that are present, but not currently included in the toctree. Use this setting to suppress the warning that is normally emitted in that case.
1.0 版后已移除: Use exclude_patterns instead.
A list of directory paths, relative to the source directory, that are to be recursively excluded from the search for source files, that is, their subdirectories won’t be searched too. The default is [].
0.4 新版功能.
1.0 版后已移除: Use exclude_patterns instead.
A list of directory names that are to be excluded from any recursive operation Sphinx performs (e.g. searching for source files or copying static files). This is useful, for example, to exclude version-control-specific directories like 'CVS'. The default is [].
0.5 新版功能.
1.0 版后已移除: Use exclude_patterns instead.
A list of paths that contain extra templates (or templates that overwrite builtin/theme-specific templates). Relative paths are taken as relative to the 配置目录.
A string with the fully-qualified name of a callable (or simply a class) that returns an instance of TemplateBridge. This instance is then used to render HTML documents, and possibly the output of other builders (currently the changes builder). (Note that the template bridge must be made theme-aware if HTML themes are to be used.)
A string of reStructuredText that will be included at the end of every source file that is read. This is the right place to add substitutions that should be available in every file. An example:
rst_epilog = """
.. |psf| replace:: Python Software Foundation
"""
0.6 新版功能.
A string of reStructuredText that will be included at the beginning of every source file that is read.
1.0 新版功能.
The name of the default domain. Can also be None to disable a default domain. The default is 'py'. Those objects in other domains (whether the domain name is given explicitly, or selected by a default-domain directive) will have the domain name explicitly prepended when named (e.g., when the default domain is C, Python functions will be named “Python function”, not just “function”).
1.0 新版功能.
The name of a reST role (builtin or Sphinx extension) to use as the default role, that is, for text marked up `like this`. This can be set to 'py:obj' to make `filter` a cross-reference to the Python function “filter”. The default is None, which doesn’t reassign the default role.
The default role can always be set within individual documents using the standard reST default-role directive.
0.4 新版功能.
If true, keep warnings as “system message” paragraphs in the built documents. Regardless of this setting, warnings are always written to the standard error stream when sphinx-build is run.
The default is False, the pre-0.5 behavior was to always keep them.
0.5 新版功能.
If set to a major.minor version string like '1.1', Sphinx will compare it with its version and refuse to build if it is too old. Default is no requirement.
1.0 新版功能.
If true, Sphinx will warn about all references where the target cannot be found. Default is False. You can activate this mode temporarily using the -n command-line switch.
1.0 新版功能.
A list of (type, target) tuples (by default empty) that should be ignored when generating warnings in “nitpicky mode”. Note that type should include the domain name. An example entry would be ('py:func', 'int').
1.1 新版功能.
The documented project’s name.
A copyright statement in the style '2008, Author Name'.
The major project version, used as the replacement for |version|. For example, for the Python documentation, this may be something like 2.6.
The full project version, used as the replacement for |release| and e.g. in the HTML templates. For example, for the Python documentation, this may be something like 2.6.0rc1.
If you don’t need the separation provided between version and release, just set them both to the same value.
These values determine how to format the current date, used as the replacement for |today|.
The default is no today and a today_fmt of '%B %d, %Y' (or, if translation is enabled with language, an equivalent %format for the selected locale).
The default language to highlight source code in. The default is 'python'. The value should be a valid Pygments lexer name, see 展示代码实例 for more details.
0.5 新版功能.
The style name to use for Pygments highlighting of source code. The default style is selected by the theme for HTML output, and 'sphinx' otherwise.
在 0.3 版更改: If the value is a fully-qualified name of a custom Pygments style class, this is then used as custom style.
A boolean that decides whether parentheses are appended to function and method role text (e.g. the content of :func:`input`) to signify that the name is callable. Default is True.
A boolean that decides whether module names are prepended to all 项目 names (for object types where a “module” of some kind is defined), e.g. for py:function directives. Default is True.
A boolean that decides whether codeauthor and sectionauthor directives produce any output in the built files.
A list of prefixes that are ignored for sorting the Python module index (e.g., if this is set to ['foo.'], then foo.bar is shown under B, not F). This can be handy if you document a project that consists of a single package. Works only for the HTML builder currently. Default is [].
0.6 新版功能.
Trim spaces before footnote references that are necessary for the reST parser to recognize the footnote, but do not look too nice in the output.
0.6 新版功能.
If true, doctest flags (comments looking like # doctest: FLAG, ...) at the ends of lines and <BLANKLINE> markers are removed for all code blocks showing interactive Python sessions (i.e. doctests). Default is true. See the extension doctest for more possibilities of including doctests.
1.0 新版功能.
在 1.1 版更改: Now also removes <BLANKLINE>.
These options influence Sphinx’ Native Language Support. See the documentation on 国际化 for details.
The code for the language the docs are written in. Any text automatically generated by Sphinx will be in that language. Also, Sphinx will try to substitute individual paragraphs from your documents with the translation sets obtained from locale_dirs. In the LaTeX builder, a suitable language will be selected as an option for the Babel package. Default is None, which means that no translation will be done.
0.5 新版功能.
Currently supported languages by Sphinx are:
0.5 新版功能.
Directories in which to search for additional message catalogs (see language), relative to the source directory. The directories on this path are searched by the standard gettext module.
Internal messages are fetched from a text domain of sphinx; so if you add the directory ./locale to this settting, the message catalogs (compiled from .po format using msgfmt) must be in ./locale/language/LC_MESSAGES/sphinx.mo. The text domain of individual documents depends on gettext_compact.
The default is [].
1.1 新版功能.
If true, a document’s text domain is its docname if it is a top-level project file and its very base directory otherwise.
By default, the document markup/code.rst ends up in the markup text domain. With this option set to False, it is markup/code.
These options influence HTML as well as HTML Help output, and other builders that use Sphinx’ HTMLWriter class.
The “theme” that the HTML output should use. See the section about theming. The default is 'default'.
0.6 新版功能.
A dictionary of options that influence the look and feel of the selected theme. These are theme-specific. For the options understood by the builtin themes, see this section.
0.6 新版功能.
A list of paths that contain custom themes, either as subdirectories or as zip files. Relative paths are taken as relative to the configuration directory.
0.6 新版功能.
The style sheet to use for HTML pages. A file of that name must exist either in Sphinx’ static/ path, or in one of the custom paths given in html_static_path. Default is the stylesheet given by the selected theme. If you only want to add or override a few things compared to the theme’s stylesheet, use CSS @import to import the theme’s stylesheet.
The “title” for HTML documentation generated with Sphinx’ own templates. This is appended to the <title> tag of individual pages, and used in the navigation bar as the “topmost” element. It defaults to '<project> v<revision> documentation', where the placeholders are replaced by the config values of the same name.
A shorter “title” for the HTML docs. This is used in for links in the header and in the HTML Help docs. If not given, it defaults to the value of html_title.
0.4 新版功能.
A dictionary of values to pass into the template engine’s context for all pages. Single values can also be put in this dictionary using the -A command-line option of sphinx-build.
0.5 新版功能.
If given, this must be the name of an image file that is the logo of the docs. It is placed at the top of the sidebar; its width should therefore not exceed 200 pixels. Default: None.
0.4.1 新版功能: The image file will be copied to the _static directory of the output HTML, so an already existing file with that name will be overwritten.
If given, this must be the name of an image file (within the static path, see below) that is the favicon of the docs. Modern browsers use this as icon for tabs, windows and bookmarks. It should be a Windows-style icon file (.ico), which is 16x16 or 32x32 pixels large. Default: None.
0.4 新版功能.
A list of paths that contain custom static files (such as style sheets or script files). Relative paths are taken as relative to the configuration directory. They are copied to the output directory after the theme’s static files, so a file named default.css will overwrite the theme’s default.css.
在 0.4 版更改: The paths in html_static_path can now contain subdirectories.
在 1.0 版更改: The entries in html_static_path can now be single files.
If this is not the empty string, a ‘Last updated on:’ timestamp is inserted at every page bottom, using the given strftime() format. Default is '%b %d, %Y' (or a locale-dependent equivalent).
If true, SmartyPants will be used to convert quotes and dashes to typographically correct entities. Default: True.
Sphinx will add “permalinks” for each heading and description environment as paragraph signs that become visible when the mouse hovers over them.
This value determines the text for the permalink; it defaults to "¶". Set it to None or the empty string to disable permalinks.
0.6 新版功能: Previously, this was always activated.
在 1.1 版更改: This can now be a string to select the actual text of the link. Previously, only boolean values were accepted.
Custom sidebar templates, must be a dictionary that maps document names to template names.
The keys can contain glob-style patterns [1], in which case all matching documents will get the specified sidebars. (A warning is emitted when a more than one glob-style pattern matches for any document.)
The values can be either lists or single strings.
If a value is a list, it specifies the complete list of sidebar templates to include. If all or some of the default sidebars are to be included, they must be put into this list as well.
The default sidebars (for documents that don’t match any pattern) are: ['localtoc.html', 'relations.html', 'sourcelink.html', 'searchbox.html'].
If a value is a single string, it specifies a custom sidebar to be added between the 'sourcelink.html' and 'searchbox.html' entries. This is for compatibility with Sphinx versions before 1.0.
Builtin sidebar templates that can be rendered are:
Example:
html_sidebars = {
'**': ['globaltoc.html', 'sourcelink.html', 'searchbox.html'],
'using/windows': ['windowssidebar.html', 'searchbox.html'],
}
This will render the custom template windowssidebar.html and the quick search box within the sidebar of the given document, and render the default sidebars for all other pages (except that the local TOC is replaced by the global TOC).
1.0 新版功能: The ability to use globbing keys and to specify multiple sidebars.
Note that this value only has no effect if the chosen theme does not possess a sidebar, like the builtin scrolls and haiku themes.
Additional templates that should be rendered to HTML pages, must be a dictionary that maps document names to template names.
Example:
html_additional_pages = {
'download': 'customdownload.html',
}
This will render the template customdownload.html as the page download.html.
If true, generate domain-specific indices in addition to the general index. For e.g. the Python domain, this is the global module index. Default is True.
This value can be a bool or a list of index names that should be generated. To find out the index name for a specific index, look at the HTML file name. For example, the Python module index has the name 'py-modindex'.
1.0 新版功能.
If true, add a module index to the HTML documents. Default is True.
1.0 版后已移除: Use html_domain_indices.
If true, add an index to the HTML documents. Default is True.
0.4 新版功能.
If true, the index is generated twice: once as a single page with all the entries, and once as one page per starting letter. Default is False.
0.4 新版功能.
If true, the reST sources are included in the HTML build as _sources/name. The default is True.
警告
If this config value is set to False, the JavaScript search function will only display the titles of matching documents, and no excerpt from the matching contents.
If true (and html_copy_source is true as well), links to the reST sources will be added to the sidebar. The default is True.
0.6 新版功能.
If nonempty, an OpenSearch <http://opensearch.org> description file will be output, and all pages will contain a <link> tag referring to it. Since OpenSearch doesn’t support relative URLs for its search page location, the value of this option must be the base URL from which these documents are served (without trailing slash), e.g. "http://docs.python.org". The default is ''.
This is the file name suffix for generated HTML files. The default is ".html".
0.4 新版功能.
Suffix for generated links to HTML files. The default is whatever html_file_suffix is set to; it can be set differently (e.g. to support different web server setups).
0.6 新版功能.
A string with the fully-qualified name of a HTML Translator class, that is, a subclass of Sphinx’ HTMLTranslator, that is used to translate document trees to HTML. Default is None (use the builtin translator).
If true, “(C) Copyright ...” is shown in the HTML footer. Default is True.
1.0 新版功能.
If true, “Created using Sphinx” is shown in the HTML footer. Default is True.
0.4 新版功能.
Encoding of HTML output files. Default is 'utf-8'. Note that this encoding name must both be a valid Python encoding name and a valid HTML charset value.
1.0 新版功能.
If true, list items containing only a single paragraph will not be rendered with a <p> element. This is standard docutils behavior. Default: True.
1.0 新版功能.
Suffix for section numbers. Default: ". ". Set to " " to suppress the final dot on section numbers.
1.0 新版功能.
Language to be used for generating the HTML full-text search index. This defaults to the global language selected with language. If there is no support for this language, "en" is used which selects the English language.
Support is present for these languages:
1.1 新版功能.
A dictionary with options for the search language support, empty by default. The meaning of these options depends on the language selected.
The English support has no options.
The Japanese support has these options:
1.1 新版功能.
The name of a javascript file (relative to the 配置目录) that implements a search results scorer. If empty, the default will be used.
1.2 新版功能.
Output file base name for HTML help builder. Default is 'pydoc'.
These options influence the epub output. As this builder derives from the HTML builder, the HTML options also apply where appropriate. The actual values for some of the options is not really important, they just have to be entered into the Dublin Core metadata.
The HTML theme for the epub output. Since the default themes are not optimized for small screen space, using the same theme for HTML and epub output is usually not wise. This defaults to 'epub', a theme designed to save visual space.
A dictionary of options that influence the look and feel of the selected theme. These are theme-specific. For the options understood by the builtin themes, see this section.
1.2 新版功能.
The title of the document. It defaults to the html_title option but can be set independently for epub creation.
The author of the document. This is put in the Dublin Core metadata. The default value is 'unknown'.
The language of the document. This is put in the Dublin Core metadata. The default is the language option or 'en' if unset.
The publisher of the document. This is put in the Dublin Core metadata. You may use any sensible string, e.g. the project homepage. The default value is 'unknown'.
The copyright of the document. It defaults to the copyright option but can be set independently for epub creation.
An identifier for the document. This is put in the Dublin Core metadata. For published documents this is the ISBN number, but you can also use an alternative scheme, e.g. the project homepage. The default value is 'unknown'.
The publication scheme for the epub_identifier. This is put in the Dublin Core metadata. For published books the scheme is 'ISBN'. If you use the project homepage, 'URL' seems reasonable. The default value is 'unknown'.
A unique identifier for the document. This is put in the Dublin Core metadata. You may use a random string. The default value is 'unknown'.
The cover page information. This is a tuple containing the filenames of the cover image and the html template. The rendered html cover page is inserted as the first item in the spine in content.opf. If the template filename is empty, no html cover page is created. No cover at all is created if the tuple is empty. Examples:
epub_cover = ('_static/cover.png', 'epub-cover.html')
epub_cover = ('_static/cover.png', '')
epub_cover = ()
The default value is ().
1.1 新版功能.
Meta data for the guide element of content.opf. This is a sequence of tuples containing the type, the uri and the title of the optional guide information. See the OPF documentation at http://idpf.org/epub for details. If possible, default entries for the cover and toc types are automatically inserted. However, the types can be explicitely overwritten if the default entries are not appropriate. Example:
epub_guide = (('cover', 'cover.html', u'Cover Page'),)
The default value is ().
Additional files that should be inserted before the text generated by Sphinx. It is a list of tuples containing the file name and the title. If the title is empty, no entry is added to toc.ncx. Example:
epub_pre_files = [
('index.html', 'Welcome'),
]
The default value is [].
Additional files that should be inserted after the text generated by Sphinx. It is a list of tuples containing the file name and the title. This option can be used to add an appendix. If the title is empty, no entry is added to toc.ncx. The default value is [].
A list of files that are generated/copied in the build directory but should not be included in the epub file. The default value is [].
The depth of the table of contents in the file toc.ncx. It should be an integer greater than zero. The default value is 3. Note: A deeply nested table of contents may be difficult to navigate.
This flag determines if a toc entry is inserted again at the beginning of it’s nested toc listing. This allows easier navitation to the top of a chapter, but can be confusing because it mixes entries of differnet depth in one list. The default value is True.
This flag determines if sphinx should try to fix image formats that are not supported by some epub readers. At the moment palette images with a small color table are upgraded. You need the Python Image Library (PIL) installed to use this option. The default value is False because the automatic conversion may lose information.
1.2 新版功能.
This option specifies the maximum width of images. If it is set to a value greater than zero, images with a width larger than the given value are scaled accordingly. If it is zero, no scaling is performed. The default value is 0. You need the Python Image Library (PIL) installed to use this option.
1.2 新版功能.
These options influence LaTeX output.
This value determines how to group the document tree into LaTeX source files. It must be a list of tuples (startdocname, targetname, title, author, documentclass, toctree_only), where the items are:
0.3 新版功能: The 6th item toctree_only. Tuples with 5 items are still accepted.
If given, this must be the name of an image file (relative to the 配置目录) that is the logo of the docs. It is placed at the top of the title page. Default: None.
If true, the topmost sectioning unit is parts, else it is chapters. Default: False.
0.3 新版功能.
A list of document names to append as an appendix to all manuals.
If true, generate domain-specific indices in addition to the general index. For e.g. the Python domain, this is the global module index. Default is True.
This value can be a bool or a list of index names that should be generated, like for html_domain_indices.
1.0 新版功能.
If true, add a module index to LaTeX documents. Default is True.
1.0 版后已移除: Use latex_domain_indices.
If true, add page references after internal references. This is very useful for printed copies of the manual. Default is False.
1.0 新版功能.
Control whether to display URL addresses. This is very useful for printed copies of the manual. The setting can have the following values:
1.0 新版功能.
在 1.1 版更改: This value is now a string; previously it was a boolean value, and a true value selected the 'inline' display. For backwards compatibility, True is still accepted.
0.5 新版功能.
A dictionary that contains LaTeX snippets that override those Sphinx usually puts into the generated .tex files.
Keep in mind that backslashes must be doubled in Python string literals to avoid interpretation as escape sequences.
Keys that you may want to override include:
Paper size option of the document class ('a4paper' or 'letterpaper'), default 'letterpaper'.
Point size option of the document class ('10pt', '11pt' or '12pt'), default '10pt'.
“babel” package inclusion, default '\\usepackage{babel}'.
Font package inclusion, default '\\usepackage{times}' (which uses Times and Helvetica). You can set this to '' to use the Computer Modern fonts.
Inclusion of the “fncychap” package (which makes fancy chapter titles), default '\\usepackage[Bjarne]{fncychap}' for English documentation, '\\usepackage[Sonny]{fncychap}' for internationalized docs (because the “Bjarne” style uses numbers spelled out in English). Other “fncychap” styles you can try include “Lenny”, “Glenn”, “Conny” and “Rejne”. You can also set this to '' to disable fncychap.
Additional preamble content, default empty.
Additional footer content (before the indices), default empty.
Keys that don’t need be overridden unless in special cases are:
“inputenc” package inclusion, default '\\usepackage[utf8]{inputenc}'.
“fontenc” package inclusion, default '\\usepackage[T1]{fontenc}'.
“maketitle” call, default '\\maketitle'. Override if you want to generate a differently-styled title page.
“tableofcontents” call, default '\\tableofcontents'. Override if you want to generate a different table of contents or put content between the title page and the TOC.
“printindex” call, the last thing in the file, default '\\printindex'. Override if you want to generate the index differently or append some content after the index.
Keys that are set by other options and therefore should not be overridden are:
'docclass' 'classoptions' 'title' 'date' 'release' 'author' 'logo' 'releasename' 'makeindex' 'shorthandoff'
A dictionary mapping 'howto' and 'manual' to names of real document classes that will be used as the base for the two Sphinx classes. Default is to use 'article' for 'howto' and 'report' for 'manual'.
1.0 新版功能.
A list of file names, relative to the 配置目录, to copy to the build directory when building LaTeX output. This is useful to copy files that Sphinx doesn’t copy automatically, e.g. if they are referenced in custom LaTeX added in latex_elements. Image files that are referenced in source files (e.g. via .. image::) are copied automatically.
You have to make sure yourself that the filenames don’t collide with those of any automatically copied files.
0.6 新版功能.
Additional LaTeX markup for the preamble.
0.5 版后已移除: Use the 'preamble' key in the latex_elements value.
The output paper size ('letter' or 'a4'). Default is 'letter'.
0.5 版后已移除: Use the 'papersize' key in the latex_elements value.
The font size (‘10pt’, ‘11pt’ or ‘12pt’). Default is '10pt'.
0.5 版后已移除: Use the 'pointsize' key in the latex_elements value.
These options influence text output.
Determines which end-of-line character(s) are used in text output.
Default: 'unix'.
1.1 新版功能.
A string of 7 characters that should be used for underlining sections. The first character is used for first-level headings, the second for second-level headings and so on.
The default is '*=-~"+`'.
1.1 新版功能.
These options influence manual page output.
This value determines how to group the document tree into manual pages. It must be a list of tuples (startdocname, name, description, authors, section), where the items are:
1.0 新版功能.
If true, add URL addresses after links. Default is False.
1.1 新版功能.
These options influence Texinfo output.
This value determines how to group the document tree into Texinfo source files. It must be a list of tuples (startdocname, targetname, title, author, dir_entry, description, category, toctree_only), where the items are:
1.1 新版功能.
A list of document names to append as an appendix to all manuals.
1.1 新版功能.
If true, generate domain-specific indices in addition to the general index. For e.g. the Python domain, this is the global module index. Default is True.
This value can be a bool or a list of index names that should be generated, like for html_domain_indices.
1.1 新版功能.
Control how to display URL addresses.
1.1 新版功能.
A dictionary that contains Texinfo snippets that override those Sphinx usually puts into the generated .texi files.
Keys that you may want to override include:
Number of spaces to indent the first line of each paragraph, default 2. Specify 0 for no indentation.
Number of spaces to indent the lines for examples or literal blocks, default 4. Specify 0 for no indentation.
Texinfo markup inserted near the beginning of the file.
Texinfo markup inserted within the @copying block and displayed after the title. The default value consists of a simple title page identifying the project.
Keys that are set by other options and therefore should not be overridden are:
'author' 'body' 'date' 'direntry' 'filename' 'project' 'release' 'title' 'direntry'
1.1 新版功能.
A list of regular expressions that match URIs that should not be checked when doing a linkcheck build. Example:
linkcheck_ignore = [r'http://localhost:\d+/']
1.1 新版功能.
A timeout value, in seconds, for the linkcheck builder. Only works in Python 2.6 and higher. The default is to use Python’s global socket timeout.
1.1 新版功能.
The number of worker threads to use when checking links. Default is 5 threads.
1.1 新版功能.
True or false, whether to check the validity of #anchors in links. Since this requires downloading the whole document, it’s considerably slower when enabled. Default is True.
1.2 新版功能.
If True, pretty-print the XML. Default is True.
1.2 新版功能.
Footnotes
| [1] | (1, 2) A note on available globbing syntax: you can use the standard shell constructs *, ?, [...] and [!...] with the feature that these all don’t match slashes. A double star ** can be used to match any sequence of characters including slashes. |