New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
register custom autosummary get_documenter functions #8038
Conversation
@tk0miya: any chance this can be included in 3.2.0? It would really help me with fixing my extension, but I totally understand if you want to think about this for a bit longer. |
I can't imagine what extension this helps except yours. I understand your extension need to access the
|
that would work, too, but it would make all extensions using this mechanism conflict with each other. Not sure if that's an issue, though. |
I just noticed that moving diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py
index c1d0febe0..32d49ca29 100644
--- a/sphinx/ext/autosummary/__init__.py
+++ b/sphinx/ext/autosummary/__init__.py
@@ -281,6 +281,10 @@ class Autosummary(SphinxDirective):
return nodes
+ def get_documenter(self, app: Sphinx, obj: Any,
+ parent: Any, name: str) -> "Type[Documenter]":
+ return get_documenter(app, obj, parent)
+
def get_items(self, names: List[str]) -> List[Tuple[str, str, str, str]]:
"""Try to import the given names, and return a list of
``[(name, signature, summary_string, real_name), ...]``.
@@ -313,7 +317,7 @@ class Autosummary(SphinxDirective):
full_name = modname + '::' + full_name[len(modname) + 1:]
# NB. using full_name here is important, since Documenters
# handle module prefixes slightly differently
- doccls = get_documenter(self.env.app, obj, parent)
+ doccls = self.get_documenter(self.env.app, obj, parent, real_name)
documenter = doccls(self.bridge, full_name)
if not documenter.parse_name():
logger.warning(__('failed to parse name %s'), real_name, (I seem to really need |
Sorry, I can't understand your proposal. Even if we added The |
I feel strange to add |
some functions in
sure, that sounds good. |
Understand. I didn't mean to remove |
okay, then that was my bad. I'll rewrite the PR. |
If the way it is now is acceptable, I think we should discuss the way this is meant to be overridden. While forcibly overriding the def register_create_documenter(func):
original_func = Autosummary.create_documenter
@functools.wraps(func)
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
if result is not NotImplemented:
return result
else:
return original_func(*args, **kwargs)
Autosummary.create_documenter = wrapper
return wrapper of course, that will still break as soon as someone overrides the Is this something you would consider including? |
No. It's too much. Let's discuss again after another extension appeared. I can't imagine the extension what needs to hook this. I just made a new method only for you. |
sure
thank you very much for that! |
Merged! |
thanks a lot, @tk0miya. 🎉 |
Feature or Bugfix
Purpose
get_documenter
functionsThis is a rough draft of the feature I proposed in #7908. Using this to override
get_documenter
would allow me to rewrite my hack to something likeand then to register it:
I don't really need all the information from the
Autosummary
class (onlyautosummary.env.app
,autosummary.config.autosummary_context
(maybe? I don't really understand that value),autosummary.options
andreal_name
), but I thought the hook should be pretty general so it doesn't only solve my own use case. So as long as I have access to that information, I'm happy to change the signature.Also, if there's any way to solve my problem without overriding
get_documenter
(I can't usecan_document_member
andpriority
because there's no way to decide fromobj
whether the documenter is appropriate), I won't insist on this feature.