Open aeisenbarth opened 7 months ago
I would like to second this proposal. We were trying to evaluate autosummary
for Bokeh but it currently seems like a non-starter. Bokeh has custom documenter classes like:
class ModelDocumenter(ClassDocumenter):
directivetype = "bokeh-model"
objtype = "model"
priority = 20
@classmethod
def can_document_member(cls, member, membername, isattr, parent):
return isinstance(member, type) and issubclass(member, Model)
but autosummary
hard-codes the objtype
values it collects:
so all of our Model
classes are completely ignored in the generated docs since their objtype
is not 'class'
.
I had intended to ask about a way to specify additional objtypes
(which seems like it would solve our problem) but simply providing all the objtype
information as proposed above would also provide a path for us to create usable templates.
@aeisenbarth I see your existing PR is still marked as a draft. Did you intend to continue on this PR?
This seems like a relatively small change on the Sphinx side but it is currently blocking a major improvement we would like to make on our docs, so I am interested to try and help move it forward. cc @AA-Turner for any thoughts here about requirements from the Sphinx end of things.
The PR is functional but I considered it as a proof of concept and was waiting for feedback on my questions. Afterall, it is a major change and throws out the previous approach to template variables.
Would be great if someone could have a look!
Is your feature request related to a problem? Please describe. When using autodoc_pydantic with recursive autosummary, I must edit the template so that it documents items with objtype
pydantic_model
. The problem is that there is no way to properly select only this object type.Templates have no access to
objtype
of anitem
. The only way to distinguish items by type is to use the variables available in templates, that sort items into some hand-crafted lists. However, this is unreliable because the provided variables don't cover every object type.data
has no variabledatas
pydantic_model
cannot be selected separately. The approach of taking the rest (members
minus all type lists) would combine objtypepydantic_model
withdata
because both are in no existing list. But data cannot be handled as the same. See: https://github.com/mansenfranzen/autodoc_pydantic/issues/33#issuecomment-962894779Describe the solution you'd like
It would be nice to have a more generalized approach.
I would like to propose:
functions
,classes
etc. in sphinx.ext.autosummary.generate:generate_autosummary_content but create dynamic lists for allobjtype
s found by the documenter. For each found type, add it as a key tons
and expose it to templates.all_…
variables. Read all public items into a singlepublic
list. This is simpler and works better with the above generalization. Templates can combine both like{{ for item in classes if item in public }}
.Describe alternatives you've considered
Forking and copy-pasting the source code of autosummary as a custom sphinx extension (see: https://github.com/mansenfranzen/autodoc_pydantic/issues/33#issuecomment-1085211704) .