2008-01-21 14:20:37 -06:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
sphinx.config
|
|
|
|
~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Build configuration file handling.
|
|
|
|
|
2010-01-01 07:09:13 -06:00
|
|
|
:copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS.
|
2009-01-03 05:15:19 -06:00
|
|
|
:license: BSD, see LICENSE for details.
|
2008-01-21 14:20:37 -06:00
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
from os import path
|
|
|
|
|
2008-12-28 17:51:51 -06:00
|
|
|
from sphinx.util import make_filename
|
|
|
|
|
2008-01-21 14:20:37 -06:00
|
|
|
|
|
|
|
class Config(object):
|
|
|
|
"""Configuration file abstraction."""
|
|
|
|
|
2009-02-19 09:15:36 -06:00
|
|
|
# the values are: (default, what needs to be rebuilt if changed)
|
2008-01-21 14:20:37 -06:00
|
|
|
|
2008-02-23 09:24:30 -06:00
|
|
|
# If you add a value here, don't forget to include it in the
|
2008-03-09 13:18:41 -05:00
|
|
|
# quickstart.py file template as well as in the docs!
|
2008-02-23 09:24:30 -06:00
|
|
|
|
2008-01-21 14:20:37 -06:00
|
|
|
config_values = dict(
|
2008-08-08 05:54:00 -05:00
|
|
|
# general options
|
2009-02-19 09:15:36 -06:00
|
|
|
project = ('Python', 'env'),
|
|
|
|
copyright = ('', 'html'),
|
|
|
|
version = ('', 'env'),
|
|
|
|
release = ('', 'env'),
|
|
|
|
today = ('', 'env'),
|
|
|
|
today_fmt = (None, 'env'), # the real default is locale-dependent
|
|
|
|
|
|
|
|
language = (None, 'env'),
|
|
|
|
locale_dirs = ([], 'env'),
|
|
|
|
|
|
|
|
master_doc = ('contents', 'env'),
|
|
|
|
source_suffix = ('.rst', 'env'),
|
2009-05-31 11:58:28 -05:00
|
|
|
source_encoding = ('utf-8-sig', 'env'),
|
2009-02-19 09:15:36 -06:00
|
|
|
unused_docs = ([], 'env'),
|
|
|
|
exclude_dirs = ([], 'env'),
|
|
|
|
exclude_trees = ([], 'env'),
|
|
|
|
exclude_dirnames = ([], 'env'),
|
|
|
|
default_role = (None, 'env'),
|
|
|
|
add_function_parentheses = (True, 'env'),
|
|
|
|
add_module_names = (True, 'env'),
|
|
|
|
trim_footnote_reference_space = (False, 'env'),
|
|
|
|
show_authors = (False, 'env'),
|
|
|
|
pygments_style = (None, 'html'),
|
|
|
|
highlight_language = ('python', 'env'),
|
|
|
|
templates_path = ([], 'html'),
|
|
|
|
template_bridge = (None, 'html'),
|
|
|
|
keep_warnings = (False, 'env'),
|
|
|
|
modindex_common_prefix = ([], 'html'),
|
|
|
|
rst_epilog = (None, 'env'),
|
2009-06-16 14:53:53 -05:00
|
|
|
trim_doctest_flags = (True, 'env'),
|
2009-06-29 10:16:05 -05:00
|
|
|
default_domain = ('py', 'env'),
|
2008-01-21 14:20:37 -06:00
|
|
|
|
|
|
|
# HTML options
|
2009-02-19 09:15:36 -06:00
|
|
|
html_theme = ('default', 'html'),
|
|
|
|
html_theme_path = ([], 'html'),
|
|
|
|
html_theme_options = ({}, 'html'),
|
2008-05-24 13:03:56 -05:00
|
|
|
html_title = (lambda self: '%s v%s documentation' %
|
|
|
|
(self.project, self.release),
|
2009-02-19 09:15:36 -06:00
|
|
|
'html'),
|
|
|
|
html_short_title = (lambda self: self.html_title, 'html'),
|
|
|
|
html_style = (None, 'html'),
|
|
|
|
html_logo = (None, 'html'),
|
|
|
|
html_favicon = (None, 'html'),
|
|
|
|
html_static_path = ([], 'html'),
|
2009-01-10 14:23:39 -06:00
|
|
|
# the real default is locale-dependent
|
2009-02-19 09:15:36 -06:00
|
|
|
html_last_updated_fmt = (None, 'html'),
|
|
|
|
html_use_smartypants = (True, 'html'),
|
|
|
|
html_translator_class = (None, 'html'),
|
|
|
|
html_sidebars = ({}, 'html'),
|
|
|
|
html_additional_pages = ({}, 'html'),
|
|
|
|
html_use_modindex = (True, 'html'),
|
|
|
|
html_add_permalinks = (True, 'html'),
|
|
|
|
html_use_index = (True, 'html'),
|
|
|
|
html_split_index = (False, 'html'),
|
|
|
|
html_copy_source = (True, 'html'),
|
|
|
|
html_show_sourcelink = (True, 'html'),
|
|
|
|
html_use_opensearch = ('', 'html'),
|
|
|
|
html_file_suffix = (None, 'html'),
|
|
|
|
html_link_suffix = (None, 'html'),
|
2009-04-09 14:04:44 -05:00
|
|
|
html_show_copyright = (True, 'html'),
|
2009-02-19 09:15:36 -06:00
|
|
|
html_show_sphinx = (True, 'html'),
|
|
|
|
html_context = ({}, 'html'),
|
2009-06-16 15:19:51 -05:00
|
|
|
html_output_encoding = ('utf-8', 'html'),
|
2008-01-21 14:20:37 -06:00
|
|
|
|
2008-05-06 09:25:29 -05:00
|
|
|
# HTML help only options
|
2009-02-19 09:15:36 -06:00
|
|
|
htmlhelp_basename = (lambda self: make_filename(self.project), None),
|
2008-12-28 17:51:51 -06:00
|
|
|
|
|
|
|
# Qt help only options
|
2009-02-19 09:15:36 -06:00
|
|
|
qthelp_basename = (lambda self: make_filename(self.project), None),
|
2008-01-21 14:20:37 -06:00
|
|
|
|
2009-06-27 11:49:51 -05:00
|
|
|
# Devhelp only options
|
|
|
|
devhelp_basename = (lambda self: make_filename(self.project), None),
|
|
|
|
|
2009-12-29 05:32:42 -06:00
|
|
|
# Epub options
|
|
|
|
epub_basename = (lambda self: make_filename(self.project), None),
|
|
|
|
epub_theme = ('epub', 'html'),
|
|
|
|
epub_title = (lambda self: self.html_title, 'html'),
|
|
|
|
epub_author = ('unknown', 'html'),
|
|
|
|
epub_language = (lambda self: self.language or 'en', 'html'),
|
|
|
|
epub_publisher = ('unknown', 'html'),
|
|
|
|
epub_copyright = (lambda self: self.copyright, 'html'),
|
|
|
|
epub_identifier = ('unknown', 'html'),
|
|
|
|
epub_scheme = ('unknown', 'html'),
|
|
|
|
epub_uid = ('unknown', 'env'),
|
|
|
|
epub_pre_files = ([], 'env'),
|
|
|
|
epub_post_files = ([], 'env'),
|
|
|
|
epub_exclude_files = ([], 'env'),
|
|
|
|
|
2008-01-21 14:20:37 -06:00
|
|
|
# LaTeX options
|
2009-02-19 09:15:36 -06:00
|
|
|
latex_documents = ([], None),
|
|
|
|
latex_logo = (None, None),
|
|
|
|
latex_appendices = ([], None),
|
|
|
|
latex_use_parts = (False, None),
|
|
|
|
latex_use_modindex = (True, None),
|
2008-09-12 08:08:52 -05:00
|
|
|
# paper_size and font_size are still separate values
|
|
|
|
# so that you can give them easily on the command line
|
2009-02-19 09:15:36 -06:00
|
|
|
latex_paper_size = ('letter', None),
|
|
|
|
latex_font_size = ('10pt', None),
|
|
|
|
latex_elements = ({}, None),
|
2009-02-20 04:20:15 -06:00
|
|
|
latex_additional_files = ([], None),
|
2009-06-04 10:50:37 -05:00
|
|
|
latex_docclass = ({}, None),
|
2008-09-12 08:08:52 -05:00
|
|
|
# now deprecated - use latex_elements
|
2009-02-19 09:15:36 -06:00
|
|
|
latex_preamble = ('', None),
|
2009-07-03 06:34:08 -05:00
|
|
|
|
|
|
|
# text options
|
|
|
|
text_sectionchars = ('*=-~"+`', 'text'),
|
|
|
|
text_windows_newlines = (False, 'text'),
|
2008-01-21 14:20:37 -06:00
|
|
|
)
|
|
|
|
|
2009-02-19 14:56:34 -06:00
|
|
|
def __init__(self, dirname, filename, overrides, tags):
|
2008-06-04 15:25:27 -05:00
|
|
|
self.overrides = overrides
|
2008-06-05 03:58:43 -05:00
|
|
|
self.values = Config.config_values.copy()
|
2008-11-16 06:29:10 -06:00
|
|
|
config = {}
|
|
|
|
if dirname is not None:
|
|
|
|
config['__file__'] = path.join(dirname, filename)
|
2009-02-19 14:56:34 -06:00
|
|
|
config['tags'] = tags
|
2008-11-16 06:29:10 -06:00
|
|
|
olddir = os.getcwd()
|
|
|
|
try:
|
|
|
|
os.chdir(dirname)
|
|
|
|
execfile(config['__file__'], config)
|
|
|
|
finally:
|
|
|
|
os.chdir(olddir)
|
2008-06-04 15:25:27 -05:00
|
|
|
self._raw_config = config
|
|
|
|
# these two must be preinitialized because extensions can add their
|
|
|
|
# own config values
|
2008-05-24 13:03:56 -05:00
|
|
|
self.setup = config.get('setup', None)
|
2008-06-04 15:25:27 -05:00
|
|
|
self.extensions = config.get('extensions', [])
|
|
|
|
|
|
|
|
def init_values(self):
|
|
|
|
config = self._raw_config
|
2008-11-30 09:33:56 -06:00
|
|
|
for valname, value in self.overrides.iteritems():
|
|
|
|
if '.' in valname:
|
|
|
|
realvalname, key = valname.split('.', 1)
|
|
|
|
config.setdefault(realvalname, {})[key] = value
|
|
|
|
else:
|
|
|
|
config[valname] = value
|
2008-06-05 03:58:43 -05:00
|
|
|
for name in config:
|
|
|
|
if name in self.values:
|
2008-06-04 15:25:27 -05:00
|
|
|
self.__dict__[name] = config[name]
|
|
|
|
del self._raw_config
|
2008-05-24 13:03:56 -05:00
|
|
|
|
|
|
|
def __getattr__(self, name):
|
|
|
|
if name.startswith('_'):
|
|
|
|
raise AttributeError(name)
|
2008-06-05 03:58:43 -05:00
|
|
|
if name not in self.values:
|
2008-05-24 13:03:56 -05:00
|
|
|
raise AttributeError('No such config value: %s' % name)
|
2008-06-05 03:58:43 -05:00
|
|
|
default = self.values[name][0]
|
2009-01-10 13:04:23 -06:00
|
|
|
if hasattr(default, '__call__'):
|
2008-05-24 13:03:56 -05:00
|
|
|
return default(self)
|
|
|
|
return default
|
2008-01-21 14:20:37 -06:00
|
|
|
|
|
|
|
def __getitem__(self, name):
|
|
|
|
return getattr(self, name)
|
2008-02-23 12:47:35 -06:00
|
|
|
|
2008-04-06 12:38:55 -05:00
|
|
|
def __setitem__(self, name, value):
|
|
|
|
setattr(self, name, value)
|
|
|
|
|
|
|
|
def __delitem__(self, name):
|
|
|
|
delattr(self, name)
|
|
|
|
|
2008-02-23 12:47:35 -06:00
|
|
|
def __contains__(self, name):
|
2008-06-05 03:58:43 -05:00
|
|
|
return name in self.values
|