11"""Visualize a CWL workflow.""" 
22
33from  collections .abc  import  Iterator 
4- from  pathlib  import  Path 
4+ from  importlib . resources  import  files 
55from  typing  import  cast 
66from  urllib .parse  import  urlparse 
77
88import  pydot 
99import  rdflib 
1010
11- _queries_dir  =  (Path (__file__ ).parent  /  "rdfqueries" ).resolve ()
12- _get_inner_edges_query_path  =  _queries_dir  /  "get_inner_edges.sparql" 
13- _get_input_edges_query_path  =  _queries_dir  /  "get_input_edges.sparql" 
14- _get_output_edges_query_path  =  _queries_dir  /  "get_output_edges.sparql" 
15- _get_root_query_path  =  _queries_dir  /  "get_root.sparql" 
11+ 
12+ def  _get_inner_edges_query () ->  str :
13+     return  files ("cwltool" ).joinpath ("rdfqueries/get_inner_edges.sparql" ).read_text ()
14+ 
15+ 
16+ def  _get_input_edges_query () ->  str :
17+     return  files ("cwltool" ).joinpath ("rdfqueries/get_input_edges.sparql" ).read_text ()
18+ 
19+ 
20+ def  _get_output_edges_query () ->  str :
21+     return  files ("cwltool" ).joinpath ("rdfqueries/get_output_edges.sparql" ).read_text ()
22+ 
23+ 
24+ def  _get_root_query () ->  str :
25+     return  files ("cwltool" ).joinpath ("rdfqueries/get_root.sparql" ).read_text ()
1626
1727
1828class  CWLViewer :
@@ -33,8 +43,7 @@ def _load_cwl_graph(self, rdf_description: str) -> rdflib.graph.Graph:
3343        return  rdf_graph 
3444
3545    def  _set_inner_edges (self ) ->  None :
36-         with  open (_get_inner_edges_query_path ) as  f :
37-             get_inner_edges_query  =  f .read ()
46+         get_inner_edges_query  =  _get_inner_edges_query ()
3847        inner_edges  =  cast (
3948            Iterator [rdflib .query .ResultRow ],
4049            self ._rdf_graph .query (
@@ -96,8 +105,7 @@ def _set_inner_edges(self) -> None:
96105            )
97106
98107    def  _set_input_edges (self ) ->  None :
99-         with  open (_get_input_edges_query_path ) as  f :
100-             get_input_edges_query  =  f .read ()
108+         get_input_edges_query  =  _get_input_edges_query ()
101109        inputs_subgraph  =  pydot .Subgraph (graph_name = "cluster_inputs" )
102110        self ._dot_graph .add_subgraph (inputs_subgraph )
103111        inputs_subgraph .set ("rank" , "same" )
@@ -124,8 +132,7 @@ def _set_input_edges(self) -> None:
124132            self ._dot_graph .add_edge (pydot .Edge (str (input_row ["input" ]), str (input_row ["step" ])))
125133
126134    def  _set_output_edges (self ) ->  None :
127-         with  open (_get_output_edges_query_path ) as  f :
128-             get_output_edges  =  f .read ()
135+         get_output_edges  =  _get_output_edges_query ()
129136        outputs_graph  =  pydot .Subgraph (graph_name = "cluster_outputs" )
130137        self ._dot_graph .add_subgraph (outputs_graph )
131138        outputs_graph .set ("rank" , "same" )
@@ -152,8 +159,7 @@ def _set_output_edges(self) -> None:
152159            self ._dot_graph .add_edge (pydot .Edge (output_edge_row ["step" ], output_edge_row ["output" ]))
153160
154161    def  _get_root_graph_uri (self ) ->  rdflib .term .Identifier :
155-         with  open (_get_root_query_path ) as  f :
156-             get_root_query  =  f .read ()
162+         get_root_query  =  _get_root_query ()
157163        root  =  cast (
158164            list [rdflib .query .ResultRow ],
159165            list (
0 commit comments