当前位置: 首页 > 文档资料 > Sphinx 中文文档 >

The build configuration file

优质
小牛编辑
118浏览
2023-12-01

The configuration directory 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:

  • If not otherwise documented, values must be strings, and their default is the empty string.
  • The term “fully-qualified name” refers to a string that names an importable Python object inside a module; for example, the FQN "sphinx.builders.Builder" means the Builder class in the sphinx.builders module.
  • Remember that document names use / as the path separator and don’t contain the file name extension.
  • Since conf.py is read as a Python file, the usual rules apply for encodings and Unicode support: declare the encoding using an encoding cookie (a comment like # -*- coding: utf-8 -*-) and use Unicode string literals when you include non-ASCII characters in configuration values.
  • The contents of the config namespace are pickled (so that Sphinx can find out when configuration changes), so it may not contain unpickleable values – delete them from the namespace with del if appropriate. Modules are removed automatically, so you don’t need to del your imports after use.
  • There is a special object named tags available in the config file. It can be used to query and change the tags (see Including content based on tags). Use tags.has('tag') to query, tags.add('tag') and tags.remove('tag') to change.

General configuration

extensions
project

These options influence Sphinx’ Native Language Support. See the documentation on Internationalization for details.

language

These options influence HTML as well as HTML Help output, and other builders that use Sphinx’ HTMLWriter class.

html_theme

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.

epub_basename

These options influence LaTeX output.

latex_documents

These options influence text output.

text_newlines

These options influence manual page output.

man_pages

These options influence Texinfo output.

texinfo_documents
linkcheck_ignore

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+/']

New in version 1.1.

linkcheck_timeout

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.

New in version 1.1.

linkcheck_workers

The number of worker threads to use when checking links. Default is 5 threads.

New in version 1.1.

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.