This is a pre-commit hook that uses graphviz python library to validate and/or render .dot files
This tool requires the system package graphviz to be installed. If you are on Debian, that is:
sudo apt install graphviz
Main goal of this was to auto-generate PNG files from .dot files so that we have both version in the repository and we are sure that both version match and developers don't forget to render the PNG whenever they edit the .dot.
Verify the syntax of .dot files
Is an alias for render-dot-png
, kept for backward compatibility
Render .dot files to png. This command can work in 2 ways
- Called without argument, it will render the .png next to the .dot files (simply appending ".png" to the .dot file path)
--only src1,src2
can be used to select the files to be rendered--only src1:target1,src2:target2
can be used to specify custom locations for the PNG (specified per .dot source)
Same as render-dot-png
but renders to svg. Rendering to svg may be more stable as it is less sensitive to fonts and other dependencies.
Discrepancies were observed when using the png hook between ubuntu 22 and ubuntu 24 for instance.
An example .pre-commit-config.yaml
:
repos:
- repo: https://github.com/bagerard/graphviz-dot-hooks
rev: master
hooks:
- id: check-dot
- id: render-dot-png
# args: ["--only=class_diagram.dot:docs/class_diagram.png"]