xflr6 / graphviz

Simple Python interface for Graphviz
https://graphviz.readthedocs.io
MIT License
1.63k stars 211 forks source link

Adapt for sphinx-gallery: add `_repr_html_` #199

Closed oscargus closed 1 year ago

oscargus commented 1 year ago

It would be really nice if there is a way to scrape the graphs such that they can be included in sphinx-gallery examples.

As it seems like sphinx-gallery suggest that additional support should be added in the package itself, the request goes here.

Edit: an option may be to add _repr_html_ which may be less work.

xflr6 commented 1 year ago

Thanks Oscar,

can you maybe link to an example sphinx-gallery and provide more details on what you are missing?

sphinx-gallery suggest that additional support should be added in the package itself

If this refers to some documentation, bug, or email thread: can you share the reference?

an option may be to add _repr_html_ which may be less work

I took a quick look at https://github.com/xflr6/graphviz/pull/200 and it seems like the current proposal would include all graphs two times, which does not sound appealing.

oscargus commented 1 year ago

Sure, this comes from: https://sphinx-gallery.github.io/stable/advanced.html#write-a-custom-image-scraper

However, I also have a PR for sphinx-gallery that uses _repr_mimebundle_ to extract the information, so maybe that is an easier way to go. https://github.com/sphinx-gallery/sphinx-gallery/pull/1138 (submitted later since the patch here was way easier...).

I do not think it will add it twice, although it depends on how it is done. The idea with the PR is that one will write something like Graph(...) (or the variable) at the end of a section, and then sphinx-gallery will capture the dynamically generated output (as opposed to using .. graphviz::). However, for Jupyter I do not really know. It sounds more like an issue with Jupyter if that happens than with the provided patch. It should be possible to provide an arbitrary number of _repr_*_ and it is up to the "terminal" to select one: https://ipython.readthedocs.io/en/stable/config/integrating.html#custom-methods

Anyway, I think that this is probably better solved with the sphinx-gallery patch.

oscargus commented 1 year ago

Here is a more direct link: https://sphinx-gallery.github.io/stable/advanced.html#integrate-custom-scrapers-with-sphinx-gallery

"Sphinx-Gallery plans to internally maintain only one scraper: matplotlib."

xflr6 commented 1 year ago

Thanks! Superseded by https://github.com/sphinx-gallery/sphinx-gallery/pull/1138