From c212f5842cdc85b22f6b3ce56a55173fe261863c Mon Sep 17 00:00:00 2001 From: Keewis Date: Sun, 2 Aug 2020 14:05:09 +0200 Subject: [PATCH] allow registering custom get_documenter functions --- sphinx/application.py | 3 +++ sphinx/registry.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/sphinx/application.py b/sphinx/application.py index d84a2c975..493c40607 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -1045,6 +1045,9 @@ class Sphinx: logger.debug('[app] adding autodoc attrgetter: %r', (typ, getter)) self.registry.add_autodoc_attrgetter(typ, getter) + def add_autosummary_get_documenter(self, func: Callable) -> None: + self.registry.add_autosummary_get_documenter(func) + def add_search_language(self, cls: Any) -> None: """Register a new language for the HTML search index. diff --git a/sphinx/registry.py b/sphinx/registry.py index 0aec0a9fd..01203c031 100644 --- a/sphinx/registry.py +++ b/sphinx/registry.py @@ -61,6 +61,9 @@ class SphinxComponentRegistry: #: autodoc documenters; a dict of documenter name -> documenter class self.documenters = {} # type: Dict[str, Type[Documenter]] + #: autosummary documenter functions + self.custom_get_documenter_funcs = [] # type: List[Callable] + #: css_files; a list of tuple of filename and attributes self.css_files = [] # type: List[Tuple[str, Dict[str, str]]] @@ -360,6 +363,9 @@ class SphinxComponentRegistry: attrgetter: Callable[[Any, str, Any], Any]) -> None: self.autodoc_attrgettrs[typ] = attrgetter + def add_autosummary_get_documenter(self, func: Callable) -> None: + self.custom_get_documenter_funcs.append(func) + def add_css_files(self, filename: str, **attributes: str) -> None: self.css_files.append((filename, attributes))