[DOC] Add automated mini-gallery examples for API pages#3334
[DOC] Add automated mini-gallery examples for API pages#3334Kaustbh wants to merge 2 commits intoaeon-toolkit:mainfrom
Conversation
Thank you for contributing to
|
|
Thanks for the PR. This looks like a useful feature, and the core structure seems sensible. The main thing I wanted to ask about is how notebooks are matched to classes and estimators. Could you explain that part a bit more? For example, I would expect classifiers to link to the classification notebook, and I was not clear whether the current matching guarantees that. |
|
During the documentation build, each example notebook is analyzed using Python’s Abstract Syntax Tree (AST) module. Instead of executing the notebooks, the AST parser inspects the code cells and identifies which aeon classes or functions are actually used in the code (not just imported). Based on this analysis, the system constructs a mapping that links each aeon object to the example notebooks in which it appears. For thumbnails, instead of trying to infer image names automatically, the system reads the Both of these mappings—the Later, when the documentation pages are rendered, the custom mini-gallery directive is encountered on an API page. At that point, the directive retrieves the mappings from the Sphinx environment, determines which example notebooks correspond to the API object being documented, and generates the gallery cards with the correct thumbnails and links to the example pages. Importantly, this mapping is only needed during the build process. The gallery HTML is generated at build time and written directly into the final documentation pages. Once the build is complete, the mappings themselves are no longer required, because the resulting HTML pages already contain the rendered gallery with the example links and images. When a user later opens an API page in the browser, it simply displays the pre-generated HTML content rather than recomputing the mappings.
To clarify, we are not linking classes based on their category (like "classifiers go to classification notebooks"). Instead, the matching is based entirely on actual usage. |
|
Thanks, the overall approach makes sense and your explanation of the AST-based matching was helpful. I have a question. At the moment the directive matches examples using only the short object name and takes the first key.endswith(f".{object_name}") hit. Since the templates pass only {{ objname }}, this looks ambiguous for any duplicate class or function names across modules, which we try avoid but is possible. Could you change this to use the fully qualified name instead, for example by passing module + objname from the template and matching exactly? Also, the gallery section is created before thumbnails are filtered, so pages could end up with an empty “Gallery Examples” heading if matched notebooks are missing thumbnail entries. It would be good to skip the section entirely in that case. One minor cleanup point: aeon_gallery.css seems to be added both in setup() and in html_css_files, so only one of those should be needed. |
|
Hi, thanks for the PR. This is a very useful addition to the documentation, and from what I can see it generates what we want. We may want to move it up further so it is not at the bottom of the page, but not for this PR. My main concern is whether we need some of this, and if adding our own From previous discussion the main issue is that Is there anything this PR is doing that we wouldn't get from the above, or would the above be more complex in practice? Fine with this approach over nothing, but feel we should consider a simpler alternative if it is possible. |
|
Hello Matthew, I explored the notebook to script conversion approach using both I ran into a few issues with the conversion step. The generated Another concern is that if we rely on I also experimented with a hybrid approach: converting notebooks to scripts without execution and using what approach would you recommend I proceed with from here? |
This PR adds a custom Sphinx extension that automatically displays mini-gallery example cards on all API reference pages. When users visit documentation for any class or function, they see a grid of notebook examples that demonstrate that object.
Reference Issues/PRs
Fixes #164
What does this implement/fix? Explain your changes.
Does your contribution introduce a new dependency? If yes, which one?
Any other comments?
PR checklist
For all contributions
For new estimators and functions
__maintainer__at the top of relevant files and want to be contacted regarding its maintenance. Unmaintained files may be removed. This is for the full file, and you should not add yourself if you are just making minor changes or do not want to help maintain its contents.For developers with write access