The plugin is intentionally lightweight. It integrates with Kedro's CLI, converts a pipeline into a simplified dependency graph, and renders Mermaid markup. Understanding the moving parts makes customisation and contributions easier.
Entry Points
kedro_mermaid.plugin.commandsdefines the rootkedro mermaidcommand group. Kedro discovers it via thekedro.hooksentry point and providesProjectMetadatafor logging and context.kedro_mermaid.cli.generate.generateimplements thekedro mermaid generatecommand. It parses CLI flags, looks up the requested pipeline, and applies Kedro's filtering API (Pipeline.filter).
Graph Construction
kedro_mermaid.lib.graph.DiagramGraph performs the heavy lifting:
- Collect edges – Every Kedro node becomes an edge between each input dataset and output dataset (
DiagramEdge). Self-loops are discarded (input != output). - Parse names – Nodes are wrapped in
DiagramNode, which consultsParsedNameto apply regex patterns from--set-node-attr pattern=.... - Simplify – After filters remove nodes,
DiagramGraph.simplifyreconnects surviving nodes so the diagram remains readable. It traverses from each included node to the next reachable included node, skipping hidden intermediates. - Group categories – When
ParsedNameemits a category, the renderer surrounds the grouped nodes with a subgraph and auto-generates colour accents. - Render –
DiagramGraph.renderemits Markdown-friendly Mermaid blocks. Optional Mermaid config is written as YAML front matter, which Mermaid Live Editor understands out of the box.
Name Parsing
kedro_mermaid.lib.parsed_name.ParsedName centralises regex handling.
- Named capture groups labelled
categorycreate subgraphs. - Named (or numbered) groups labelled
nodeform the rendered node label. - If the regex does not match, the node remains in the graph with its original name but is flagged as
is_match=Falseso simplification can skip it when requested.
The implementation relies on the third-party regex module so advanced features like repeated named groups ((?P<node>...)) are available.
Utilities
kedro_mermaid.lib.utils.parse_listconverts comma-separated CLI options into Python lists (clickuses it as a callback on list-like options).- Tests in
tests/kedro_mermaid/lib/test_parsed_name.pycover the name parsing behaviour to guarantee backwards compatibility when upgrading the regex logic.
Understanding the structure above should give you enough confidence to extend the CLI, add new filters, or alter the rendering step.