mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Always prefer dict literals over calls to dict()
Dict literals are always slightly faster and are idiomatic modern Python.
This commit is contained in:
parent
45ad2e41a5
commit
1ae049b2ee
10
setup.py
10
setup.py
@ -153,11 +153,11 @@ else:
|
|||||||
|
|
||||||
with open(js_file, 'wt') as outfile:
|
with open(js_file, 'wt') as outfile:
|
||||||
outfile.write('Documentation.addTranslations(')
|
outfile.write('Documentation.addTranslations(')
|
||||||
dump(dict(
|
dump({
|
||||||
messages=jscatalog,
|
'messages': jscatalog,
|
||||||
plural_expr=catalog.plural_expr,
|
'plural_expr': catalog.plural_expr,
|
||||||
locale=str(catalog.locale)
|
'locale': str(catalog.locale)
|
||||||
), outfile, sort_keys=True)
|
}, outfile, sort_keys=True)
|
||||||
outfile.write(');')
|
outfile.write(');')
|
||||||
|
|
||||||
cmdclass['compile_catalog'] = compile_catalog_plusjs
|
cmdclass['compile_catalog'] = compile_catalog_plusjs
|
||||||
|
@ -265,13 +265,13 @@ class MessageCatalogBuilder(I18nBuilder):
|
|||||||
def finish(self):
|
def finish(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
I18nBuilder.finish(self)
|
I18nBuilder.finish(self)
|
||||||
data = dict(
|
data = {
|
||||||
version = self.config.version,
|
'version': self.config.version,
|
||||||
copyright = self.config.copyright,
|
'copyright': self.config.copyright,
|
||||||
project = self.config.project,
|
'project': self.config.project,
|
||||||
ctime = datetime.fromtimestamp(
|
'ctime': datetime.fromtimestamp(
|
||||||
timestamp, ltz).strftime('%Y-%m-%d %H:%M%z'),
|
timestamp, ltz).strftime('%Y-%m-%d %H:%M%z'),
|
||||||
)
|
}
|
||||||
for textdomain, catalog in status_iterator(self.catalogs.items(), # type: ignore
|
for textdomain, catalog in status_iterator(self.catalogs.items(), # type: ignore
|
||||||
__("writing message catalogs... "),
|
__("writing message catalogs... "),
|
||||||
"darkgreen", len(self.catalogs),
|
"darkgreen", len(self.catalogs),
|
||||||
|
@ -552,35 +552,35 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
else:
|
else:
|
||||||
stylename = 'default.css'
|
stylename = 'default.css'
|
||||||
|
|
||||||
self.globalcontext = dict(
|
self.globalcontext = {
|
||||||
embedded = self.embedded,
|
'embedded': self.embedded,
|
||||||
project = self.config.project,
|
'project': self.config.project,
|
||||||
release = return_codes_re.sub('', self.config.release),
|
'release': return_codes_re.sub('', self.config.release),
|
||||||
version = self.config.version,
|
'version': self.config.version,
|
||||||
last_updated = self.last_updated,
|
'last_updated': self.last_updated,
|
||||||
copyright = self.config.copyright,
|
'copyright': self.config.copyright,
|
||||||
master_doc = self.config.master_doc,
|
'master_doc': self.config.master_doc,
|
||||||
use_opensearch = self.config.html_use_opensearch,
|
'use_opensearch': self.config.html_use_opensearch,
|
||||||
docstitle = self.config.html_title,
|
'docstitle': self.config.html_title,
|
||||||
shorttitle = self.config.html_short_title,
|
'shorttitle': self.config.html_short_title,
|
||||||
show_copyright = self.config.html_show_copyright,
|
'show_copyright': self.config.html_show_copyright,
|
||||||
show_sphinx = self.config.html_show_sphinx,
|
'show_sphinx': self.config.html_show_sphinx,
|
||||||
has_source = self.config.html_copy_source,
|
'has_source': self.config.html_copy_source,
|
||||||
show_source = self.config.html_show_sourcelink,
|
'show_source': self.config.html_show_sourcelink,
|
||||||
sourcelink_suffix = self.config.html_sourcelink_suffix,
|
'sourcelink_suffix': self.config.html_sourcelink_suffix,
|
||||||
file_suffix = self.out_suffix,
|
'file_suffix': self.out_suffix,
|
||||||
script_files = self.script_files,
|
'script_files': self.script_files,
|
||||||
language = self.config.language,
|
'language': self.config.language,
|
||||||
css_files = self.css_files,
|
'css_files': self.css_files,
|
||||||
sphinx_version = __display_version__,
|
'sphinx_version': __display_version__,
|
||||||
style = stylename,
|
'style': stylename,
|
||||||
rellinks = rellinks,
|
'rellinks': rellinks,
|
||||||
builder = self.name,
|
'builder': self.name,
|
||||||
parents = [],
|
'parents': [],
|
||||||
logo = logo,
|
'logo': logo,
|
||||||
favicon = favicon,
|
'favicon': favicon,
|
||||||
html5_doctype = self.config.html_experimental_html5_writer and html5_ready,
|
'html5_doctype': self.config.html_experimental_html5_writer and html5_ready,
|
||||||
) # type: Dict[unicode, Any]
|
} # type: Dict[unicode, Any]
|
||||||
if self.theme:
|
if self.theme:
|
||||||
self.globalcontext.update(
|
self.globalcontext.update(
|
||||||
('theme_' + key, val) for (key, val) in
|
('theme_' + key, val) for (key, val) in
|
||||||
@ -652,21 +652,21 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
self_toc = TocTree(self.env).get_toc_for(docname, self)
|
self_toc = TocTree(self.env).get_toc_for(docname, self)
|
||||||
toc = self.render_partial(self_toc)['fragment']
|
toc = self.render_partial(self_toc)['fragment']
|
||||||
|
|
||||||
return dict(
|
return {
|
||||||
parents = parents,
|
'parents': parents,
|
||||||
prev = prev,
|
'prev': prev,
|
||||||
next = next,
|
'next': next,
|
||||||
title = title,
|
'title': title,
|
||||||
meta = meta,
|
'meta': meta,
|
||||||
body = body,
|
'body': body,
|
||||||
metatags = metatags,
|
'metatags': metatags,
|
||||||
rellinks = rellinks,
|
'rellinks': rellinks,
|
||||||
sourcename = sourcename,
|
'sourcename': sourcename,
|
||||||
toc = toc,
|
'toc': toc,
|
||||||
# only display a TOC if there's more than one item to show
|
# only display a TOC if there's more than one item to show
|
||||||
display_toc = (self.env.toc_num_entries[docname] > 1),
|
'display_toc': (self.env.toc_num_entries[docname] > 1),
|
||||||
page_source_suffix = source_suffix,
|
'page_source_suffix': source_suffix,
|
||||||
)
|
}
|
||||||
|
|
||||||
def write_doc(self, docname, doctree):
|
def write_doc(self, docname, doctree):
|
||||||
# type: (unicode, nodes.Node) -> None
|
# type: (unicode, nodes.Node) -> None
|
||||||
@ -757,11 +757,11 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
indexcounts.append(sum(1 + len(subitems)
|
indexcounts.append(sum(1 + len(subitems)
|
||||||
for _, (_, subitems, _) in entries))
|
for _, (_, subitems, _) in entries))
|
||||||
|
|
||||||
genindexcontext = dict(
|
genindexcontext = {
|
||||||
genindexentries = genindex,
|
'genindexentries': genindex,
|
||||||
genindexcounts = indexcounts,
|
'genindexcounts': indexcounts,
|
||||||
split_index = self.config.html_split_index,
|
'split_index': self.config.html_split_index,
|
||||||
)
|
}
|
||||||
logger.info(' genindex', nonl=1)
|
logger.info(' genindex', nonl=1)
|
||||||
|
|
||||||
if self.config.html_split_index:
|
if self.config.html_split_index:
|
||||||
@ -780,11 +780,11 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
def write_domain_indices(self):
|
def write_domain_indices(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
for indexname, indexcls, content, collapse in self.domain_indices:
|
for indexname, indexcls, content, collapse in self.domain_indices:
|
||||||
indexcontext = dict(
|
indexcontext = {
|
||||||
indextitle = indexcls.localname,
|
'indextitle': indexcls.localname,
|
||||||
content = content,
|
'content': content,
|
||||||
collapse_index = collapse,
|
'collapse_index': collapse,
|
||||||
)
|
}
|
||||||
logger.info(' ' + indexname, nonl=1)
|
logger.info(' ' + indexname, nonl=1)
|
||||||
self.handle_page(indexname, indexcontext, 'domainindex.html')
|
self.handle_page(indexname, indexcontext, 'domainindex.html')
|
||||||
|
|
||||||
@ -1332,20 +1332,20 @@ class SingleFileHTMLBuilder(StandaloneHTMLBuilder):
|
|||||||
else:
|
else:
|
||||||
toc = ''
|
toc = ''
|
||||||
display_toc = False
|
display_toc = False
|
||||||
return dict(
|
return {
|
||||||
parents = [],
|
'parents': [],
|
||||||
prev = None,
|
'prev': None,
|
||||||
next = None,
|
'next': None,
|
||||||
docstitle = None,
|
'docstitle': None,
|
||||||
title = self.config.html_title,
|
'title': self.config.html_title,
|
||||||
meta = None,
|
'meta': None,
|
||||||
body = body,
|
'body': body,
|
||||||
metatags = metatags,
|
'metatags': metatags,
|
||||||
rellinks = [],
|
'rellinks': [],
|
||||||
sourcename = '',
|
'sourcename': '',
|
||||||
toc = toc,
|
'toc': toc,
|
||||||
display_toc = display_toc,
|
'display_toc': display_toc,
|
||||||
)
|
}
|
||||||
|
|
||||||
def write(self, *ignored):
|
def write(self, *ignored):
|
||||||
# type: (Any) -> None
|
# type: (Any) -> None
|
||||||
|
100
sphinx/config.py
100
sphinx/config.py
@ -97,63 +97,63 @@ class Config:
|
|||||||
# If you add a value here, don't forget to include it in the
|
# If you add a value here, don't forget to include it in the
|
||||||
# quickstart.py file template as well as in the docs!
|
# quickstart.py file template as well as in the docs!
|
||||||
|
|
||||||
config_values = dict(
|
config_values = {
|
||||||
# general options
|
# general options
|
||||||
project = ('Python', 'env', []),
|
'project': ('Python', 'env', []),
|
||||||
author = ('unknown', 'env', []),
|
'author': ('unknown', 'env', []),
|
||||||
copyright = ('', 'html', []),
|
'copyright': ('', 'html', []),
|
||||||
version = ('', 'env', []),
|
'version': ('', 'env', []),
|
||||||
release = ('', 'env', []),
|
'release': ('', 'env', []),
|
||||||
today = ('', 'env', []),
|
'today': ('', 'env', []),
|
||||||
# the real default is locale-dependent
|
# the real default is locale-dependent
|
||||||
today_fmt = (None, 'env', string_classes),
|
'today_fmt': (None, 'env', string_classes),
|
||||||
|
|
||||||
language = (None, 'env', string_classes),
|
'language': (None, 'env', string_classes),
|
||||||
locale_dirs = (['locales'], 'env', []),
|
'locale_dirs': (['locales'], 'env', []),
|
||||||
figure_language_filename = (u'{root}.{language}{ext}', 'env', [str]),
|
'figure_language_filename': (u'{root}.{language}{ext}', 'env', [str]),
|
||||||
|
|
||||||
master_doc = ('index', 'env', []),
|
'master_doc': ('index', 'env', []),
|
||||||
source_suffix = ({'.rst': 'restructuredtext'}, 'env', Any),
|
'source_suffix': ({'.rst': 'restructuredtext'}, 'env', Any),
|
||||||
source_encoding = ('utf-8-sig', 'env', []),
|
'source_encoding': ('utf-8-sig', 'env', []),
|
||||||
source_parsers = ({}, 'env', []),
|
'source_parsers': ({}, 'env', []),
|
||||||
exclude_patterns = ([], 'env', []),
|
'exclude_patterns': ([], 'env', []),
|
||||||
default_role = (None, 'env', string_classes),
|
'default_role': (None, 'env', string_classes),
|
||||||
add_function_parentheses = (True, 'env', []),
|
'add_function_parentheses': (True, 'env', []),
|
||||||
add_module_names = (True, 'env', []),
|
'add_module_names': (True, 'env', []),
|
||||||
trim_footnote_reference_space = (False, 'env', []),
|
'trim_footnote_reference_space': (False, 'env', []),
|
||||||
show_authors = (False, 'env', []),
|
'show_authors': (False, 'env', []),
|
||||||
pygments_style = (None, 'html', string_classes),
|
'pygments_style': (None, 'html', string_classes),
|
||||||
highlight_language = ('default', 'env', []),
|
'highlight_language': ('default', 'env', []),
|
||||||
highlight_options = ({}, 'env', []),
|
'highlight_options': ({}, 'env', []),
|
||||||
templates_path = ([], 'html', []),
|
'templates_path': ([], 'html', []),
|
||||||
template_bridge = (None, 'html', string_classes),
|
'template_bridge': (None, 'html', string_classes),
|
||||||
keep_warnings = (False, 'env', []),
|
'keep_warnings': (False, 'env', []),
|
||||||
suppress_warnings = ([], 'env', []),
|
'suppress_warnings': ([], 'env', []),
|
||||||
modindex_common_prefix = ([], 'html', []),
|
'modindex_common_prefix': ([], 'html', []),
|
||||||
rst_epilog = (None, 'env', string_classes),
|
'rst_epilog': (None, 'env', string_classes),
|
||||||
rst_prolog = (None, 'env', string_classes),
|
'rst_prolog': (None, 'env', string_classes),
|
||||||
trim_doctest_flags = (True, 'env', []),
|
'trim_doctest_flags': (True, 'env', []),
|
||||||
primary_domain = ('py', 'env', [NoneType]), # type: ignore
|
'primary_domain': ('py', 'env', [NoneType]), # type: ignore
|
||||||
needs_sphinx = (None, None, string_classes),
|
'needs_sphinx': (None, None, string_classes),
|
||||||
needs_extensions = ({}, None, []),
|
'needs_extensions': ({}, None, []),
|
||||||
manpages_url = (None, 'env', []),
|
'manpages_url': (None, 'env', []),
|
||||||
nitpicky = (False, None, []),
|
'nitpicky': (False, None, []),
|
||||||
nitpick_ignore = ([], None, []),
|
'nitpick_ignore': ([], None, []),
|
||||||
numfig = (False, 'env', []),
|
'numfig': (False, 'env', []),
|
||||||
numfig_secnum_depth = (1, 'env', []),
|
'numfig_secnum_depth': (1, 'env', []),
|
||||||
numfig_format = ({}, 'env', []), # will be initialized in init_numfig_format()
|
'numfig_format': ({}, 'env', []), # will be initialized in init_numfig_format()
|
||||||
|
|
||||||
math_number_all = (False, 'env', []),
|
'math_number_all': (False, 'env', []),
|
||||||
math_eqref_format = (None, 'env', string_classes),
|
'math_eqref_format': (None, 'env', string_classes),
|
||||||
math_numfig = (True, 'env', []),
|
'math_numfig': (True, 'env', []),
|
||||||
tls_verify = (True, 'env', []),
|
'tls_verify': (True, 'env', []),
|
||||||
tls_cacerts = (None, 'env', []),
|
'tls_cacerts': (None, 'env', []),
|
||||||
smartquotes = (True, 'env', []),
|
'smartquotes': (True, 'env', []),
|
||||||
smartquotes_action = ('qDe', 'env', []),
|
'smartquotes_action': ('qDe', 'env', []),
|
||||||
smartquotes_excludes = ({'languages': ['ja'],
|
'smartquotes_excludes': ({'languages': ['ja'],
|
||||||
'builders': ['man', 'text']},
|
'builders': ['man', 'text']},
|
||||||
'env', []),
|
'env', []),
|
||||||
) # type: Dict[unicode, Tuple]
|
} # type: Dict[unicode, Tuple]
|
||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
# type: (Any) -> None
|
# type: (Any) -> None
|
||||||
|
@ -417,28 +417,28 @@ def main(argv=sys.argv[1:]):
|
|||||||
continue
|
continue
|
||||||
prev_module = module
|
prev_module = module
|
||||||
text += ' %s\n' % module
|
text += ' %s\n' % module
|
||||||
d = dict(
|
d = {
|
||||||
path = args.destdir,
|
'path': args.destdir,
|
||||||
sep = False,
|
'sep': False,
|
||||||
dot = '_',
|
'dot': '_',
|
||||||
project = args.header,
|
'project': args.header,
|
||||||
author = args.author or 'Author',
|
'author': args.author or 'Author',
|
||||||
version = args.version or '',
|
'version': args.version or '',
|
||||||
release = args.release or args.version or '',
|
'release': args.release or args.version or '',
|
||||||
suffix = '.' + args.suffix,
|
'suffix': '.' + args.suffix,
|
||||||
master = 'index',
|
'master': 'index',
|
||||||
epub = True,
|
'epub': True,
|
||||||
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode',
|
'extensions': ['sphinx.ext.autodoc', 'sphinx.ext.viewcode',
|
||||||
'sphinx.ext.todo'],
|
'sphinx.ext.todo'],
|
||||||
makefile = True,
|
'makefile': True,
|
||||||
batchfile = True,
|
'batchfile': True,
|
||||||
make_mode = True,
|
'make_mode': True,
|
||||||
mastertocmaxdepth = args.maxdepth,
|
'mastertocmaxdepth': args.maxdepth,
|
||||||
mastertoctree = text,
|
'mastertoctree': text,
|
||||||
language = 'en',
|
'language': 'en',
|
||||||
module_path = rootpath,
|
'module_path': rootpath,
|
||||||
append_syspath = args.append_syspath,
|
'append_syspath': args.append_syspath,
|
||||||
)
|
}
|
||||||
if args.extensions:
|
if args.extensions:
|
||||||
d['extensions'].extend(args.extensions)
|
d['extensions'].extend(args.extensions)
|
||||||
|
|
||||||
|
@ -35,12 +35,12 @@ def doctree_read(app, doctree):
|
|||||||
raise LinkcodeError(
|
raise LinkcodeError(
|
||||||
"Function `linkcode_resolve` is not given in conf.py")
|
"Function `linkcode_resolve` is not given in conf.py")
|
||||||
|
|
||||||
domain_keys = dict(
|
domain_keys = {
|
||||||
py=['module', 'fullname'],
|
'py': ['module', 'fullname'],
|
||||||
c=['names'],
|
'c': ['names'],
|
||||||
cpp=['names'],
|
'cpp': ['names'],
|
||||||
js=['object', 'fullname'],
|
'js': ['object', 'fullname'],
|
||||||
)
|
}
|
||||||
|
|
||||||
for objnode in doctree.traverse(addnodes.desc):
|
for objnode in doctree.traverse(addnodes.desc):
|
||||||
domain = objnode.get('domain')
|
domain = objnode.get('domain')
|
||||||
|
@ -38,15 +38,15 @@ if False:
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
lexers = dict(
|
lexers = {
|
||||||
none = TextLexer(stripnl=False),
|
'none': TextLexer(stripnl=False),
|
||||||
python = PythonLexer(stripnl=False),
|
'python': PythonLexer(stripnl=False),
|
||||||
python3 = Python3Lexer(stripnl=False),
|
'python3': Python3Lexer(stripnl=False),
|
||||||
pycon = PythonConsoleLexer(stripnl=False),
|
'pycon': PythonConsoleLexer(stripnl=False),
|
||||||
pycon3 = PythonConsoleLexer(python3=True, stripnl=False),
|
'pycon3': PythonConsoleLexer(python3=True, stripnl=False),
|
||||||
rest = RstLexer(stripnl=False),
|
'rest': RstLexer(stripnl=False),
|
||||||
c = CLexer(stripnl=False),
|
'c': CLexer(stripnl=False),
|
||||||
) # type: Dict[unicode, Lexer]
|
} # type: Dict[unicode, Lexer]
|
||||||
for _lexer in lexers.values():
|
for _lexer in lexers.values():
|
||||||
_lexer.add_filter('raiseonerror')
|
_lexer.add_filter('raiseonerror')
|
||||||
|
|
||||||
|
@ -446,12 +446,12 @@ class IndexBuilder:
|
|||||||
|
|
||||||
def context_for_searchtool(self):
|
def context_for_searchtool(self):
|
||||||
# type: () -> Dict[unicode, Any]
|
# type: () -> Dict[unicode, Any]
|
||||||
return dict(
|
return {
|
||||||
search_language_stemming_code = self.lang.js_stemmer_code,
|
'search_language_stemming_code': self.lang.js_stemmer_code,
|
||||||
search_language_stop_words = jsdump.dumps(sorted(self.lang.stopwords)),
|
'search_language_stop_words': jsdump.dumps(sorted(self.lang.stopwords)),
|
||||||
search_scorer_tool = self.js_scorer_code,
|
'search_scorer_tool': self.js_scorer_code,
|
||||||
search_word_splitter_code = self.js_splitter_code,
|
'search_word_splitter_code': self.js_splitter_code,
|
||||||
)
|
}
|
||||||
|
|
||||||
def get_js_stemmer_rawcode(self):
|
def get_js_stemmer_rawcode(self):
|
||||||
# type: () -> unicode
|
# type: () -> unicode
|
||||||
|
Loading…
Reference in New Issue
Block a user