179
|
1 |
# -*- coding: utf-8 -*-
|
|
2 |
"""
|
|
3 |
sphinx.config
|
|
4 |
~~~~~~~~~~~~~
|
|
5 |
|
|
6 |
Build configuration file handling.
|
|
7 |
|
|
8 |
:copyright: 2008 by Georg Brandl.
|
|
9 |
:license: BSD license.
|
|
10 |
"""
|
|
11 |
|
|
12 |
import os
|
|
13 |
from os import path
|
|
14 |
|
|
15 |
|
|
16 |
class Config(object):
|
|
17 |
"""Configuration file abstraction."""
|
|
18 |
|
|
19 |
# the values are: (default, needs fresh doctrees if changed)
|
|
20 |
|
|
21 |
# If you add a value here, don't forget to include it in the
|
|
22 |
# quickstart.py file template as well as in the docs!
|
|
23 |
|
|
24 |
config_values = dict(
|
|
25 |
# general options
|
|
26 |
project = ('Python', True),
|
|
27 |
copyright = ('', False),
|
|
28 |
version = ('', True),
|
|
29 |
release = ('', True),
|
|
30 |
today = ('', True),
|
|
31 |
today_fmt = (None, True), # the real default is locale-dependent
|
|
32 |
|
|
33 |
language = (None, True),
|
|
34 |
locale_dirs = ([], True),
|
|
35 |
|
|
36 |
master_doc = ('contents', True),
|
|
37 |
source_suffix = ('.rst', True),
|
|
38 |
source_encoding = ('utf-8', True),
|
|
39 |
unused_docs = ([], True),
|
|
40 |
exclude_dirs = ([], True),
|
|
41 |
exclude_trees = ([], True),
|
|
42 |
exclude_dirnames = ([], True),
|
|
43 |
default_role = (None, True),
|
|
44 |
add_function_parentheses = (True, True),
|
|
45 |
add_module_names = (True, True),
|
|
46 |
show_authors = (False, True),
|
|
47 |
pygments_style = ('sphinx', False),
|
|
48 |
highlight_language = ('python', False),
|
|
49 |
templates_path = ([], False),
|
|
50 |
template_bridge = (None, False),
|
|
51 |
keep_warnings = (False, True),
|
|
52 |
|
|
53 |
# HTML options
|
|
54 |
html_title = (lambda self: '%s v%s documentation' %
|
|
55 |
(self.project, self.release),
|
|
56 |
False),
|
|
57 |
html_short_title = (lambda self: self.html_title, False),
|
|
58 |
html_style = ('default.css', False),
|
|
59 |
html_logo = (None, False),
|
|
60 |
html_favicon = (None, False),
|
|
61 |
html_static_path = ([], False),
|
|
62 |
html_last_updated_fmt = (None, False), # the real default is locale-dependent
|
|
63 |
html_use_smartypants = (True, False),
|
|
64 |
html_translator_class = (None, False),
|
|
65 |
html_sidebars = ({}, False),
|
|
66 |
html_additional_pages = ({}, False),
|
|
67 |
html_use_modindex = (True, False),
|
|
68 |
html_use_index = (True, False),
|
|
69 |
html_split_index = (False, False),
|
|
70 |
html_copy_source = (True, False),
|
|
71 |
html_use_opensearch = ('', False),
|
|
72 |
html_file_suffix = (None, False),
|
|
73 |
html_show_sphinx = (True, False),
|
|
74 |
html_context = ({}, False),
|
|
75 |
|
|
76 |
# HTML help only options
|
|
77 |
htmlhelp_basename = ('pydoc', False),
|
|
78 |
|
|
79 |
# LaTeX options
|
|
80 |
latex_documents = ([], False),
|
|
81 |
latex_logo = (None, False),
|
|
82 |
latex_appendices = ([], False),
|
|
83 |
latex_use_parts = (False, False),
|
|
84 |
latex_use_modindex = (True, False),
|
|
85 |
# paper_size and font_size are still separate values
|
|
86 |
# so that you can give them easily on the command line
|
|
87 |
latex_paper_size = ('letter', False),
|
|
88 |
latex_font_size = ('10pt', False),
|
|
89 |
latex_elements = ({}, False),
|
|
90 |
# now deprecated - use latex_elements
|
|
91 |
latex_preamble = ('', False),
|
|
92 |
)
|
|
93 |
|
|
94 |
def __init__(self, dirname, filename, overrides):
|
|
95 |
self.overrides = overrides
|
|
96 |
self.values = Config.config_values.copy()
|
|
97 |
config = {}
|
|
98 |
if dirname is not None:
|
|
99 |
config['__file__'] = path.join(dirname, filename)
|
|
100 |
olddir = os.getcwd()
|
|
101 |
try:
|
|
102 |
os.chdir(dirname)
|
|
103 |
execfile(config['__file__'], config)
|
|
104 |
finally:
|
|
105 |
os.chdir(olddir)
|
|
106 |
self._raw_config = config
|
|
107 |
# these two must be preinitialized because extensions can add their
|
|
108 |
# own config values
|
|
109 |
self.setup = config.get('setup', None)
|
|
110 |
self.extensions = config.get('extensions', [])
|
|
111 |
|
|
112 |
def init_values(self):
|
|
113 |
config = self._raw_config
|
|
114 |
config.update(self.overrides)
|
|
115 |
for name in config:
|
|
116 |
if name in self.values:
|
|
117 |
self.__dict__[name] = config[name]
|
|
118 |
del self._raw_config
|
|
119 |
|
|
120 |
def __getattr__(self, name):
|
|
121 |
if name.startswith('_'):
|
|
122 |
raise AttributeError(name)
|
|
123 |
if name not in self.values:
|
|
124 |
raise AttributeError('No such config value: %s' % name)
|
|
125 |
default = self.values[name][0]
|
|
126 |
if callable(default):
|
|
127 |
return default(self)
|
|
128 |
return default
|
|
129 |
|
|
130 |
def __getitem__(self, name):
|
|
131 |
return getattr(self, name)
|
|
132 |
|
|
133 |
def __setitem__(self, name, value):
|
|
134 |
setattr(self, name, value)
|
|
135 |
|
|
136 |
def __delitem__(self, name):
|
|
137 |
delattr(self, name)
|
|
138 |
|
|
139 |
def __contains__(self, name):
|
|
140 |
return name in self.values
|