From 164f835d775f42096518ce636b053b918060e983 Mon Sep 17 00:00:00 2001 From: Rafael Ferreira da Silva Date: Tue, 19 Mar 2024 10:52:15 -0400 Subject: [PATCH] #38: generate a WfInstance from a .dot file --- README.md | 7 +++++++ wfcommons/common/workflow.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/README.md b/README.md index 7b975d0..c2b66a7 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,13 @@ Then you can install pygraphviz by running: python3 -m pip install pygraphviz ``` +#### pydot +WfCommons uses _pydot_ for reading and writing DOT files. If you want to enable +this feature, you will have to install the pydot package: +``` +python3 -m pip install pydot +``` + ## Get in Touch The main channel to reach the WfCommons team is via the support email: diff --git a/wfcommons/common/workflow.py b/wfcommons/common/workflow.py index 3031498..55980c1 100644 --- a/wfcommons/common/workflow.py +++ b/wfcommons/common/workflow.py @@ -9,6 +9,7 @@ # (at your option) any later version. import getpass +import importlib import json import networkx as nx import pathlib @@ -181,6 +182,12 @@ def read_dot(self, dot_file_path: Optional[pathlib.Path] = None) -> None: """ if not dot_file_path: raise FileNotFoundError(f"Not able to find the dot file: {dot_file_path}.") + + graphviz_found = importlib.util.find_spec('pydot') + if graphviz_found is None: + raise ModuleNotFoundError( + f"\'pydot\' package not found: call to {type(self).__name__}.read_dot() failed.") + graph = nx.drawing.nx_pydot.read_dot(dot_file_path) tasks_map = {}