From 538c061e7c2589d00377669bc0b8e1667387a3e1 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Mon, 16 Apr 2018 00:16:18 +0900 Subject: [PATCH] Change priority of doctree-read event --- CHANGES | 3 ++- sphinx/environment/__init__.py | 4 ---- sphinx/io.py | 4 ++-- sphinx/transforms/__init__.py | 9 +++++++++ 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index 642325847..9c730c410 100644 --- a/CHANGES +++ b/CHANGES @@ -17,7 +17,8 @@ Incompatible changes a ``conf.py`` file sphinx-build generates. * The ``gettext_compact`` attribute is removed from ``document.settings`` object. Please use ``config.gettext_compact`` instead. -* The processing order of smart_quotes and sphinx domains are changed. For more +* The processing order on reading phase is changed. smart_quotes, sphinx + domains and :event:`doctree-read` event are invoked earlier. For more details, please read a description of :py:meth:`.Sphinx.add_transform()` Deprecated diff --git a/sphinx/environment/__init__.py b/sphinx/environment/__init__.py index af76c7ab1..96c98d2dc 100644 --- a/sphinx/environment/__init__.py +++ b/sphinx/environment/__init__.py @@ -570,10 +570,6 @@ class BuildEnvironment(object): with sphinx_domains(self), rst.default_role(docname, self.config.default_role): doctree = read_doc(self.app, self, self.doc2path(docname)) - # allow extension-specific post-processing - if app: - app.emit('doctree-read', doctree) - # store time of reading, for outdated files detection # (Some filesystems have coarse timestamp resolution; # therefore time.time() can be older than filesystem's timestamp. diff --git a/sphinx/io.py b/sphinx/io.py index d9b28bed3..2c80fb4b3 100644 --- a/sphinx/io.py +++ b/sphinx/io.py @@ -24,7 +24,7 @@ from sphinx.transforms import ( ApplySourceWorkaround, ExtraTranslatableNodes, CitationReferences, DefaultSubstitutions, MoveModuleTargets, HandleCodeBlocks, SortIds, AutoNumbering, AutoIndexUpgrader, FilterSystemMessages, - UnreferencedFootnotesDetector, SphinxSmartQuotes, ManpageLink + UnreferencedFootnotesDetector, SphinxSmartQuotes, DoctreeReadEvent, ManpageLink ) from sphinx.transforms import SphinxTransformer from sphinx.transforms.compact_bullet_list import RefOnlyBulletListTransform @@ -95,7 +95,7 @@ class SphinxStandaloneReader(SphinxBaseReader): HandleCodeBlocks, AutoNumbering, AutoIndexUpgrader, SortIds, RemoveTranslatableInline, FilterSystemMessages, RefOnlyBulletListTransform, UnreferencedFootnotesDetector, SphinxSmartQuotes, ManpageLink, - SphinxDomains, + SphinxDomains, DoctreeReadEvent, ] # type: List[Transform] def __init__(self, app, *args, **kwargs): diff --git a/sphinx/transforms/__init__.py b/sphinx/transforms/__init__.py index 4f3d15752..ab69f981a 100644 --- a/sphinx/transforms/__init__.py +++ b/sphinx/transforms/__init__.py @@ -399,6 +399,15 @@ class SphinxSmartQuotes(SmartQuotes, SphinxTransform): yield (texttype[notsmartquotable], txtnode.astext()) +class DoctreeReadEvent(SphinxTransform): + """Emit :event:`doctree-read` event.""" + default_priority = 880 + + def apply(self): + # type: () -> None + self.app.emit('doctree-read', self.document) + + class ManpageLink(SphinxTransform): """Find manpage section numbers and names""" default_priority = 999