You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if show_root_heading is true, show the top object heading
if show_root_heading is false, you still have a chance to add the object to the ToC with show_root_toc_entry set to true. Adding the ToC entry is required for cross-references to this object to work.
However I agree that the ToC seems broken: it's because I used h6 for the hidden ToC entries. I think it would be best to use the specified heading level. I'll fix this.
This is amazing, everything looks so beautiful and heading_level gives us full control!!! We'll switch to your plugin hopefully today but there is one more critical issue I just noticed.
It seems like dynamically generated (at import time though) methods aren't detected:
Hmmm interesting. Indeed I never tried with dynamically added things. I'll play a bit with your example to see why mkdocstrings (pytkdocs really) does not detect the dynamically set members.
This is what I was suspecting for attributes. But the dynamically added members you're missing are methods no? They should be recognized as such in the get_<object_type>_documentation methods of pytkdocs loader.
If not, and your dynamic members are indeed attributes, yes, Python does not allow to attach a docstring to a variable so we have to parse them using AST, therefore dynamic stuff won't work (code is never executed while parsing attributes and their docstrings).
OK I found why nothing appears. The attributes you set dynamically with setattr are not methods. They are instances of __TransformerDocumentionHelper.
When pytkdocs iterates over the ColumnTransformers or ExtraTransformers classes' members, it has no idea how to handle such objects: they are not classes nor methods.
An idea that popped to mind is that we could inspect the object to see if it has a __doc__ attribute. But then how would we categorize it? The object must be an instance of Module, Class, Method, Function or Attribute. Such an object doesn't fit in any of those 😕
Is there a reason you do not attach directly the transformer instead of creating an object just to store its __doc__?
for name, transformer in sorted(COLUMN_TRANSFORMERS.items()):
setattr(ColumnTransformers, name, transformer)
@pawamoy Also, just at a high level, I think we should support the idea that anything can happen at load time, same as other tools like the extension we're coming from and Sphinx. Can you explain what exactly we need to use the ast module for?
The things you tried didn't work because pytkdocs only collects attributes with docstrings. There's an issue for this on pytkdocs repo: mkdocstrings/pytkdocs#11, feel free to comment or vote!
Activity
pawamoy commentedon Mar 29, 2020
Try this:
Of course if you are writing your API docs like this everwhere, you can set this as default in
mkdocs.yml:Here's how the template works:
show_root_headingis true, show the top object headingshow_root_headingis false, you still have a chance to add the object to the ToC withshow_root_toc_entryset to true. Adding the ToC entry is required for cross-references to this object to work.However I agree that the ToC seems broken: it's because I used
h6for the hidden ToC entries. I think it would be best to use the specified heading level. I'll fix this.All the options are here: https://pawamoy.github.io/mkdocstrings/reference/handlers/python/#mkdocstrings.handlers.python.PythonRenderer.DEFAULT_CONFIG
ofek commentedon Mar 29, 2020
This is amazing, everything looks so beautiful and
heading_levelgives us full control!!! We'll switch to your plugin hopefully today but there is one more critical issue I just noticed.It seems like dynamically generated (at import time though) methods aren't detected:
https://github.com/DataDog/integrations-core/blob/hack-a-doc/datadog_checks_base/datadog_checks/base/utils/db/transform.py#L494-L517
Same for simple properties:
https://github.com/DataDog/integrations-core/blob/hack-a-doc/datadog_checks_base/datadog_checks/base/utils/http.py#L489-L496
The root header shows up of course, but no members at all. Am I missing an option?
pawamoy commentedon Mar 29, 2020
Hmmm interesting. Indeed I never tried with dynamically added things. I'll play a bit with your example to see why mkdocstrings (pytkdocs really) does not detect the dynamically set members.
ofek commentedon Mar 29, 2020
Hmm,
pytkdocsseems to get them:ofek commentedon Mar 29, 2020
Ah, found it.
leafis correct here and is the fully loaded object:https://github.com/pawamoy/pytkdocs/blob/8dfd0bbf2e73977fc1cc9528e62057f3764a5a07/src/pytkdocs/loader.py#L205
but then here:
https://github.com/pawamoy/pytkdocs/blob/8dfd0bbf2e73977fc1cc9528e62057f3764a5a07/src/pytkdocs/loader.py#L207
there are no attributes b/c we parse using the AST of the source code rather than inspecting
leafpawamoy commentedon Mar 29, 2020
This is what I was suspecting for attributes. But the dynamically added members you're missing are methods no? They should be recognized as such in the
get_<object_type>_documentationmethods of pytkdocs loader.If not, and your dynamic members are indeed attributes, yes, Python does not allow to attach a docstring to a variable so we have to parse them using AST, therefore dynamic stuff won't work (code is never executed while parsing attributes and their docstrings).
ofek commentedon Mar 29, 2020
Yup basically we want to document
Foo:ofek commentedon Mar 29, 2020
Keep in mind though that
leaf.objis correct, can we not inspect it without AST?pawamoy commentedon Mar 29, 2020
When I write "attribute" I mean "variable", sorry if this wasn't clear :)
Since you're setting methods with
setattr, they should be picked up while recursing on objects and their members, so I'm not sure what happens here.ofek commentedon Mar 29, 2020
As far as I can tell it comes down to you re-parsing source code vs simply inspecting the loaded object that is already in memory (
leaf.obj)ofek commentedon Mar 29, 2020
See: https://github.com/pawamoy/pytkdocs/blob/8dfd0bbf2e73977fc1cc9528e62057f3764a5a07/src/pytkdocs/parsers/attributes.py#L83-L88
pawamoy commentedon Mar 30, 2020
OK I found why nothing appears. The attributes you set dynamically with
setattrare not methods. They are instances of__TransformerDocumentionHelper.When
pytkdocsiterates over theColumnTransformersorExtraTransformersclasses' members, it has no idea how to handle such objects: they are not classes nor methods.An idea that popped to mind is that we could inspect the object to see if it has a
__doc__attribute. But then how would we categorize it? The object must be an instance of Module, Class, Method, Function or Attribute. Such an object doesn't fit in any of those 😕Is there a reason you do not attach directly the transformer instead of creating an object just to store its
__doc__?ofek commentedon Mar 30, 2020
I was trying to avoid displaying a signature so it appears like an Enum, but yeah I'll do your way for now. Though I can't get the other case to work.
StephenBrown2 commentedon Mar 30, 2020
Why are you setting the attributes that way, and not in the class itself?
ofek commentedon Mar 31, 2020
I need to iterate through all the defined attributes
ofek commentedon Mar 31, 2020
@pawamoy Also, just at a high level, I think we should support the idea that anything can happen at load time, same as other tools like the extension we're coming from and Sphinx. Can you explain what exactly we need to use the
astmodule for?pawamoy commentedon Mar 31, 2020
It's already supported. We do import the code, so module scoped code is executed, and we can inspect it.
To get docstrings for attributes. Python has no way of attaching a docstring to a variable, so we must parse the code to get these pairs.
ofek commentedon Apr 1, 2020
FYI I just tried @StephenBrown2's way, and that also does not work
ofek commentedon Apr 1, 2020
nor does stdlib's
Enumofek commentedon Apr 1, 2020
Got it!
pawamoy commentedon Apr 1, 2020
Nice!
The things you tried didn't work because
pytkdocsonly collects attributes with docstrings. There's an issue for this onpytkdocsrepo: mkdocstrings/pytkdocs#11, feel free to comment or vote!