Skip to content

Commit

Permalink
fix: Make grapher works with graphviz >= 0.18 (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
haidaraM authored Nov 7, 2021
1 parent 3ed9e5c commit cc97613
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- Merge when condition with `and`
- Explicitly set color luminance to avoid bright colors
- Reduce Node ID lengths. No need to use the full UUID
- Make grapher works with graphviz >= 0.18. See [\#91](https://github.com/haidaraM/ansible-playbook-grapher/issues/91)
- test:
- Add Ansible 2.10.7 in the test matrix
- Make test verbose by default with `-vv` in the args
Expand Down
2 changes: 1 addition & 1 deletion ansibleplaybookgrapher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
from .postprocessor import GraphVizPostProcessor
from .renderer import GraphvizRenderer

__version__ = "1.0.0.dev3"
__version__ = "1.0.0.dev4"
__prog__ = "ansible-playbook-grapher"
23 changes: 5 additions & 18 deletions ansibleplaybookgrapher/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,7 @@
from graphviz import Digraph

from ansibleplaybookgrapher.graph import PlaybookNode, EdgeNode, PlayNode, RoleNode, BlockNode
from ansibleplaybookgrapher.utils import clean_name, get_play_colors


class GraphvizCustomDigraph(Digraph):
"""
Custom digraph to avoid quoting issue with node names. Nothing special here except I put some double quotes around
the node and edge names and override some methods.
"""
_head = "digraph \"%s\"{"
_edge = "\t\"%s\" -> \"%s\"%s"
_node = "\t\"%s\"%s"
_subgraph = "subgraph \"%s\"{"
_quote = staticmethod(clean_name)
_quote_edge = staticmethod(clean_name)
from ansibleplaybookgrapher.utils import get_play_colors


class GraphvizRenderer:
Expand All @@ -40,11 +27,11 @@ def __init__(self, playbook_node: 'PlaybookNode', display: Display, graph_format
"""
self.display = display
self.playbook_node = playbook_node
self.digraph = GraphvizCustomDigraph(format=graph_format,
graph_attr=graph_attr or GraphvizRenderer.DEFAULT_GRAPH_ATTR,
edge_attr=edge_attr or GraphvizRenderer.DEFAULT_EDGE_ATTR)
self.digraph = Digraph(format=graph_format,
graph_attr=graph_attr or GraphvizRenderer.DEFAULT_GRAPH_ATTR,
edge_attr=edge_attr or GraphvizRenderer.DEFAULT_EDGE_ATTR)

def render_node(self, graph: GraphvizCustomDigraph, edge: EdgeNode, color: str, node_counter: int,
def render_node(self, graph: Digraph, edge: EdgeNode, color: str, node_counter: int,
shape: str = "octagon", **kwargs):
"""
Render a generic node in the graph
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ansible>=2.9.0
graphviz<1
graphviz>=0.18,<1
colour<1
lxml<5
packaging

0 comments on commit cc97613

Please sign in to comment.