Skip to content
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

Supress Graphviz warnings when rendering in a Jupyter notebook #1016

Open
atlasfoo opened this issue Sep 4, 2024 · 1 comment
Open

Supress Graphviz warnings when rendering in a Jupyter notebook #1016

atlasfoo opened this issue Sep 4, 2024 · 1 comment

Comments

@atlasfoo
Copy link

atlasfoo commented Sep 4, 2024

Hello.

I'm using diagrams in a Jupyter notebook to create software documentation (UML, Cloud Architecture and stuff like that) following the guide.

I'm in the need to deliver this documentation in a non-programmer friendly format, like PDF, so I'm using nbconvert to convert the output of the notebook to PDF, but, the graphviz's warnings get on the way.

image

I need to get rid of these warnings, I've tried using warnings.filterwarnings("ignore"), but this didn't work because graphviz's warnings are not generated by the code in the notebook.

I also tried to use the graph.dot.render() method to pass the quiet param, but this only generates the output file and don't render the diagram inside of the notebook, so it doesn't get exported to the PDF. (https://graphviz.readthedocs.io/en/stable/api.html)

Is there any way to render the diagram inside of the jupyter notebook but without the warnings?

Thanks.

@atlasfoo
Copy link
Author

Solved by creating an Diagram inheriting class and redefining the _repr_png_ method:

from typing import Optional
from diagrams import Diagram


class QuietDiagram(Diagram):
    def __init__(
        self,
        name: str = "",
        filename: str = "",
        direction: str = "LR",
        curvestyle: str = "ortho",
        outformat: str = "png",
        autolabel: bool = False,
        show: bool = True,
        strict: bool = False,
        graph_attr: Optional[dict] = None,
        node_attr: Optional[dict] = None,
        edge_attr: Optional[dict] = None,
    ):
        super().__init__(
            name,
            filename,
            direction,
            curvestyle,
            outformat,
            autolabel,
            show,
            strict,
            graph_attr,
            node_attr,
            edge_attr,
        )

    def _repr_png_(self):
        return self.dot.pipe(format="png", quiet="true")

Maybe is it worth it to add a way to define the quiet parameter inside the default _repr_png_ method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant