diff options
| author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-01-12 00:07:58 +0900 |
|---|---|---|
| committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-01-16 17:04:48 +0900 |
| commit | 2e338aa5cd5ae86f43e074b073c04141528b87a3 (patch) | |
| tree | 4d70dc19c87dcb001851ffd9c837ee684732d95f /sphinx/application.py | |
| parent | f169560395ee266f4e8e812d1803241ab7335fee (diff) | |
| download | sphinx-git-2e338aa5cd5ae86f43e074b073c04141528b87a3.tar.gz | |
Support priority of event handlers
Diffstat (limited to 'sphinx/application.py')
| -rw-r--r-- | sphinx/application.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/sphinx/application.py b/sphinx/application.py index 515d962dc..fbc637e60 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -404,17 +404,25 @@ class Sphinx: raise VersionRequirementError(version) # event interface - def connect(self, event: str, callback: Callable) -> int: + def connect(self, event: str, callback: Callable, priority: int = 500) -> int: """Register *callback* to be called when *event* is emitted. For details on available core events and the arguments of callback functions, please see :ref:`events`. + Registered callbacks will be invoked on event in the order of *priority* and + registration. The priority is ascending order. + The method returns a "listener ID" that can be used as an argument to :meth:`disconnect`. + + .. versionchanged:: 3.0 + + Support *priority* """ - listener_id = self.events.connect(event, callback) - logger.debug('[app] connecting event %r: %r [id=%s]', event, callback, listener_id) + listener_id = self.events.connect(event, callback, priority) + logger.debug('[app] connecting event %r (%d): %r [id=%s]', + event, priority, callback, listener_id) return listener_id def disconnect(self, listener_id: int) -> None: |
