summaryrefslogtreecommitdiff
path: root/sphinx/environment
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2019-03-09 16:46:41 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2019-04-16 14:06:36 +0900
commit06f86b06399937bb2018841b5dd5fcbf4e54d7a0 (patch)
treecd0425510bb037c443f3b9d567ab3eb2a1f25a29 /sphinx/environment
parent419f2e5fc904ec0819177305270ae1c5c8a38813 (diff)
downloadsphinx-git-06f86b06399937bb2018841b5dd5fcbf4e54d7a0.tar.gz
Make EventManager portable
So far, we need to bypass application object for modules to emit a event. This make EventManager portable and easy to pass event emitter. This brings modules less coupled with application object.
Diffstat (limited to 'sphinx/environment')
-rw-r--r--sphinx/environment/__init__.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/sphinx/environment/__init__.py b/sphinx/environment/__init__.py
index e3d2c1f49..af3b6cf1f 100644
--- a/sphinx/environment/__init__.py
+++ b/sphinx/environment/__init__.py
@@ -37,6 +37,7 @@ if False:
from sphinx.application import Sphinx # NOQA
from sphinx.builders import Builder # NOQA
from sphinx.config import Config # NOQA
+ from sphinx.event import EventManager # NOQA
from sphinx.domains import Domain # NOQA
from sphinx.project import Project # NOQA
@@ -98,6 +99,7 @@ class BuildEnvironment:
self.srcdir = None # type: str
self.config = None # type: Config
self.config_status = None # type: int
+ self.events = None # type: EventManager
self.project = None # type: Project
self.version = None # type: Dict[str, str]
@@ -193,7 +195,7 @@ class BuildEnvironment:
# type: () -> Dict
"""Obtains serializable data for pickling."""
__dict__ = self.__dict__.copy()
- __dict__.update(app=None, domains={}) # clear unpickable attributes
+ __dict__.update(app=None, domains={}, events=None) # clear unpickable attributes
return __dict__
def __setstate__(self, state):
@@ -213,6 +215,7 @@ class BuildEnvironment:
self.app = app
self.doctreedir = app.doctreedir
+ self.events = app.events
self.srcdir = app.srcdir
self.project = app.project
self.version = app.registry.get_envversion(app)
@@ -310,7 +313,7 @@ class BuildEnvironment:
for domainname, domain in self.domains.items():
domain.merge_domaindata(docnames, other.domaindata[domainname])
- app.emit('env-merge-info', self, docnames, other)
+ self.events.emit('env-merge-info', self, docnames, other)
def path2doc(self, filename):
# type: (str) -> Optional[str]
@@ -452,7 +455,7 @@ class BuildEnvironment:
def check_dependents(self, app, already):
# type: (Sphinx, Set[str]) -> Iterator[str]
to_rewrite = [] # type: List[str]
- for docnames in app.emit('env-get-updated', self):
+ for docnames in self.events.emit('env-get-updated', self):
to_rewrite.extend(docnames)
for docname in set(to_rewrite):
if docname not in already:
@@ -600,7 +603,7 @@ class BuildEnvironment:
self.temp_data = backup
# allow custom references to be resolved
- self.app.emit('doctree-resolved', doctree, docname)
+ self.events.emit('doctree-resolved', doctree, docname)
def collect_relations(self):
# type: () -> Dict[str, List[str]]
@@ -656,7 +659,7 @@ class BuildEnvironment:
# call check-consistency for all extensions
for domain in self.domains.values():
domain.check_consistency()
- self.app.emit('env-check-consistency', self)
+ self.events.emit('env-check-consistency', self)
# --------- METHODS FOR COMPATIBILITY --------------------------------------