Skip to content

Commit 956c34d

Browse files
committed
Fix for environment with minimal graphviz setup (fallback on SVG export)
1 parent 2c98ba3 commit 956c34d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

swift_code_metrics/_graphics.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ def directed_graph(self, title, list_of_edges):
6363
dir_graph.add_edge(e[0], e[1], label=e[2])
6464

6565
dir_graph.layout('dot')
66-
dir_graph.draw(self.__file_path(title))
66+
try:
67+
dir_graph.draw(self.__file_path(title))
68+
except OSError:
69+
# Fallback for minimal graphviz setup
70+
dir_graph.draw(self.__file_path(title, extension='.svg'))
6771

6872
# Private
6973

@@ -75,8 +79,8 @@ def __render(self, plt, name):
7579
plt.savefig(save_file)
7680
plt.close()
7781

78-
def __file_path(self, name):
79-
filename = Graph.format_filename(name) + '.pdf'
82+
def __file_path(self, name, extension='.pdf'):
83+
filename = Graph.format_filename(name) + extension
8084
return os.path.join(self.path, filename)
8185

8286
@staticmethod

0 commit comments

Comments
 (0)