mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Make remaining builtin extensions parallel-read-proof.
This commit is contained in:
parent
52e5316b6e
commit
e3135cfc87
@ -507,7 +507,9 @@ handlers to the events. Example:
|
||||
that have been read in the subprocess.
|
||||
|
||||
For a sample of how to deal with this event, look at the standard
|
||||
``sphinx.ext.viewcode`` extension.
|
||||
``sphinx.ext.todo`` extension. The implementation is often similar to that
|
||||
of :event:`env-purge-doc`, only that information is not removed, but added to
|
||||
the main environment from the other environment.
|
||||
|
||||
.. versionadded:: 1.3
|
||||
|
||||
|
@ -153,8 +153,7 @@ class Builder(object):
|
||||
def compile_catalogs(self, catalogs, message):
|
||||
if not self.config.gettext_auto_build:
|
||||
return
|
||||
self.info(bold('building [mo]: '), nonl=1)
|
||||
self.info(message)
|
||||
self.info(bold('building [mo]: ') + message)
|
||||
for catalog in self.app.status_iterator(
|
||||
catalogs, 'writing output... ', darkgreen, len(catalogs),
|
||||
lambda c: c.mo_path):
|
||||
|
@ -467,13 +467,13 @@ class StandaloneHTMLBuilder(Builder):
|
||||
self.info()
|
||||
|
||||
def gen_additional_pages(self):
|
||||
self.info(bold('writing additional pages...'), nonl=1)
|
||||
|
||||
# pages from extensions
|
||||
for pagelist in self.app.emit('html-collect-pages'):
|
||||
for pagename, context, template in pagelist:
|
||||
self.handle_page(pagename, context, template)
|
||||
|
||||
self.info(bold('writing additional pages...'), nonl=1)
|
||||
|
||||
# additional pages from conf.py
|
||||
for pagename, template in self.config.html_additional_pages.items():
|
||||
self.info(' '+pagename, nonl=1)
|
||||
|
@ -570,4 +570,4 @@ def setup(app):
|
||||
app.connect('doctree-read', process_autosummary_toc)
|
||||
app.connect('builder-inited', process_generate_options)
|
||||
app.add_config_value('autosummary_generate', [], True)
|
||||
return {'version': sphinx.__version__, 'parallel_read_safe': False}
|
||||
return {'version': sphinx.__version__, 'parallel_read_safe': True}
|
||||
|
@ -74,4 +74,4 @@ def doctree_read(app, doctree):
|
||||
def setup(app):
|
||||
app.connect('doctree-read', doctree_read)
|
||||
app.add_config_value('linkcode_resolve', None, '')
|
||||
return {'version': sphinx.__version__, 'parallel_read_safe': False}
|
||||
return {'version': sphinx.__version__, 'parallel_read_safe': True}
|
||||
|
@ -150,6 +150,14 @@ def purge_todos(app, env, docname):
|
||||
if todo['docname'] != docname]
|
||||
|
||||
|
||||
def merge_info(app, env, docnames, other):
|
||||
if not hasattr(other, 'todo_all_todos'):
|
||||
return
|
||||
if not hasattr(env, 'todo_all_todos'):
|
||||
env.todo_all_todos = []
|
||||
env.todo_all_todos.extend(other.todo_all_todos)
|
||||
|
||||
|
||||
def visit_todo_node(self, node):
|
||||
self.visit_admonition(node)
|
||||
|
||||
@ -172,4 +180,5 @@ def setup(app):
|
||||
app.connect('doctree-read', process_todos)
|
||||
app.connect('doctree-resolved', process_todo_nodes)
|
||||
app.connect('env-purge-doc', purge_todos)
|
||||
return {'version': sphinx.__version__, 'parallel_read_safe': False}
|
||||
app.connect('env-merge-info', merge_info)
|
||||
return {'version': sphinx.__version__, 'parallel_read_safe': True}
|
||||
|
@ -20,6 +20,7 @@ from sphinx.locale import _
|
||||
from sphinx.pycode import ModuleAnalyzer
|
||||
from sphinx.util import get_full_modname
|
||||
from sphinx.util.nodes import make_refnode
|
||||
from sphinx.util.console import blue
|
||||
|
||||
|
||||
def _get_full_modname(app, modname, attribute):
|
||||
@ -37,7 +38,7 @@ def _get_full_modname(app, modname, attribute):
|
||||
# It should be displayed only verbose mode.
|
||||
app.verbose(traceback.format_exc().rstrip())
|
||||
app.verbose('viewcode can\'t import %s, failed with error "%s"' %
|
||||
(modname, e))
|
||||
(modname, e))
|
||||
return None
|
||||
|
||||
|
||||
@ -100,6 +101,16 @@ def doctree_read(app, doctree):
|
||||
signode += onlynode
|
||||
|
||||
|
||||
def env_merge_info(app, env, docnames, other):
|
||||
if not hasattr(other, '_viewcode_modules'):
|
||||
return
|
||||
# create a _viewcode_modules dict on the main environment
|
||||
if not hasattr(env, '_viewcode_modules'):
|
||||
env._viewcode_modules = {}
|
||||
# now merge in the information from the subprocess
|
||||
env._viewcode_modules.update(other._viewcode_modules)
|
||||
|
||||
|
||||
def missing_reference(app, env, node, contnode):
|
||||
# resolve our "viewcode" reference nodes -- they need special treatment
|
||||
if node['reftype'] == 'viewcode':
|
||||
@ -116,10 +127,12 @@ def collect_pages(app):
|
||||
|
||||
modnames = set(env._viewcode_modules)
|
||||
|
||||
app.builder.info(' (%d module code pages)' %
|
||||
len(env._viewcode_modules), nonl=1)
|
||||
# app.builder.info(' (%d module code pages)' %
|
||||
# len(env._viewcode_modules), nonl=1)
|
||||
|
||||
for modname, entry in iteritems(env._viewcode_modules):
|
||||
for modname, entry in app.status_iterator(
|
||||
iteritems(env._viewcode_modules), 'highlighting module code... ',
|
||||
blue, len(env._viewcode_modules), lambda x: x[0]):
|
||||
if not entry:
|
||||
continue
|
||||
code, tags, used, refname = entry
|
||||
@ -162,15 +175,14 @@ def collect_pages(app):
|
||||
context = {
|
||||
'parents': parents,
|
||||
'title': modname,
|
||||
'body': _('<h1>Source code for %s</h1>') % modname + \
|
||||
'\n'.join(lines)
|
||||
'body': (_('<h1>Source code for %s</h1>') % modname +
|
||||
'\n'.join(lines)),
|
||||
}
|
||||
yield (pagename, context, 'page.html')
|
||||
|
||||
if not modnames:
|
||||
return
|
||||
|
||||
app.builder.info(' _modules/index', nonl=True)
|
||||
html = ['\n']
|
||||
# the stack logic is needed for using nested lists for submodules
|
||||
stack = ['']
|
||||
@ -190,8 +202,8 @@ def collect_pages(app):
|
||||
html.append('</ul>' * (len(stack) - 1))
|
||||
context = {
|
||||
'title': _('Overview: module code'),
|
||||
'body': _('<h1>All modules for which code is available</h1>') + \
|
||||
''.join(html),
|
||||
'body': (_('<h1>All modules for which code is available</h1>') +
|
||||
''.join(html)),
|
||||
}
|
||||
|
||||
yield ('_modules/index', context, 'page.html')
|
||||
@ -200,8 +212,9 @@ def collect_pages(app):
|
||||
def setup(app):
|
||||
app.add_config_value('viewcode_import', True, False)
|
||||
app.connect('doctree-read', doctree_read)
|
||||
app.connect('env-merge-info', env_merge_info)
|
||||
app.connect('html-collect-pages', collect_pages)
|
||||
app.connect('missing-reference', missing_reference)
|
||||
#app.add_config_value('viewcode_include_modules', [], 'env')
|
||||
#app.add_config_value('viewcode_exclude_modules', [], 'env')
|
||||
return {'version': sphinx.__version__, 'parallel_read_safe': False}
|
||||
# app.add_config_value('viewcode_include_modules', [], 'env')
|
||||
# app.add_config_value('viewcode_exclude_modules', [], 'env')
|
||||
return {'version': sphinx.__version__, 'parallel_read_safe': True}
|
||||
|
Loading…
Reference in New Issue
Block a user