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
Custom template / handller for param.Parameterized classes #515
Comments
Hi @Jhsmit, thanks for the feature request! This sounds like a great case for a Griffe extension! The docs are a bit terse, but I'll try to give more details later this week 🙂 |
So basically Griffe parses the code into an AST (Abstract Syntax Tree) and then visits this tree. You can write a Griffe extension that will add logic by visiting these attributes' values, find the |
Hi @pawamoy , thanks for your help. I'll give the griffe extension a try (when I find the time) How do you go about developing / debugging something like this? Do you have suggestions or a MWE example of how I can make a python script with my example class I want to autodoc and how to generate docs so I can use breakpoints etc without having to rely on |
I debug in VSCode. You could start by writing a dummy Griffe extension that does almost nothing, put a breakpoint in there, and add a VSCode run configuration that runs the |
An MWE would look like: # dummy.py
from griffe.agents.extensions import VisitorExtension, When
class Extension(VisitorExtension):
when = When.after_all # then try with before_all
# see https://mkdocstrings.github.io/griffe/reference/griffe/agents/extensions/#griffe.agents.extensions.When
def visit_assign(self, node) -> None:
print("hello") # <- put breakpoint here,
# with a condition like node.targets[0].id == "fruit"
# or self.current.name == "FruitStallController" Then create a venv, install Griffe and param_docs in it, and run EDIT: even easier, just follow the example in https://mkdocstrings.github.io/griffe/extensions/#extensions and write a script that declares your extension and instantiate the loader with the extension. Running this script should do the trick. |
Is your feature request related to a problem? Please describe.
I have a repository here which generates sphinx docs from
param.Parameterized
classes. These type of classes are frequently used to define widgets / parameters for panel based web applications. The goal is to generate documentation for the web application users (normal human being readable, not API docs) from theparam.Parameter
s defined on the class.When used in
panel
, this class can be used to generate simple web application with a selector, two input widgets and a button. TheI'm now trying to do the same in mkdocs. The desired output is something like this:
This output is acceptable but not the ideal case. Since its aimed towards people who use the web application rather than python code, the line
class ... <etc>
could be emitted. But these are details, the most important is that users can see thelabel
attribute (iebutton.label
) (which is how the widgets is labelled) in connection to thedoc
attribute, second is the additional attributes such asobjects
,bounds
, etc.Describe the solution you'd like
I think ideally I would create a custom template which renders these
param.Parameterized
classes the way I'd like. But after playing around with these for a bit it seems there I only have access toattribute.value
, which does more or less contain the information I have but I don't directly see a way to jinja this into the output I'd like.Is it possible to do what I want via a template?
Describe alternatives you've considered
I've considered a custom handler based on the python handler but if I understand the procedure correctly I'd have to create whole namespace package and deal with a lot of boilerplate.
The other option I've considered is not use mkdocstrings plugin directly but instead manually write a script which import griffe and python handler directly and runs by
mkdocs-gen-files
This might be the most flexible approach but for the end users (which is mostly myself atm) a similar API as currently used in mkdocstrings would be preferable.
If this seems like sensible approach, what would be a good starting point?
Additional context
My current mkdocs_param playground repo is here
The text was updated successfully, but these errors were encountered: