Skip to content

Commit

Permalink
bpo-40742: Doc: fix parallel build. (pythonGH-21237)
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienPalard committed Jul 6, 2020
1 parent 1ac0cbc commit a103e73
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Doc/tools/extensions/pyspecific.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,39 @@ def run(self):

# Support for documenting audit event

def audit_events_purge(app, env, docname):
"""This is to remove from env.all_audit_events old traces of removed
documents.
"""
if not hasattr(env, 'all_audit_events'):
return
fresh_all_audit_events = {}
for name, event in env.all_audit_events.items():
event["source"] = [(d, t) for d, t in event["source"] if d != docname]
if event["source"]:
# Only keep audit_events that have at least one source.
fresh_all_audit_events[name] = event
env.all_audit_events = fresh_all_audit_events


def audit_events_merge(app, env, docnames, other):
"""In Sphinx parallel builds, this merges env.all_audit_events from
subprocesses.
all_audit_events is a dict of names, with values like:
{'source': [(docname, target), ...], 'args': args}
"""
if not hasattr(other, 'all_audit_events'):
return
if not hasattr(env, 'all_audit_events'):
env.all_audit_events = {}
for name, value in other.all_audit_events.items():
if name in env.all_audit_events:
env.all_audit_events[name]["source"].extend(value["source"])
else:
env.all_audit_events[name] = value


class AuditEvent(Directive):

has_content = True
Expand Down Expand Up @@ -589,4 +622,6 @@ def setup(app):
app.add_directive_to_domain('py', 'abstractmethod', PyAbstractMethod)
app.add_directive('miscnews', MiscNews)
app.connect('doctree-resolved', process_audit_events)
app.connect('env-merge-info', audit_events_merge)
app.connect('env-purge-doc', audit_events_purge)
return {'version': '1.0', 'parallel_read_safe': True}

0 comments on commit a103e73

Please sign in to comment.