66from collections import defaultdict
77import re
88
9- def inspect_workflow (workflow_file , console , output_json = False ):
9+ def inspect_workflow (workflow_file , source_dir , output_json , console ):
1010 workflow_path = Path (workflow_file )
1111
1212 if output_json :
13- return _inspect_json (workflow_path )
13+ return _inspect_json (workflow_path , source_dir )
1414
15- _inspect_rich (workflow_path , console )
15+ _inspect_rich (workflow_path , source_dir , console )
1616
17- def _inspect_rich (workflow_path , console ):
17+ def _inspect_rich (workflow_path , source_dir , console ):
1818 console .print ()
1919 console .print (f"[bold cyan]Workflow:[/bold cyan] { workflow_path .name } " )
2020 console .print ()
@@ -60,7 +60,7 @@ def _inspect_rich(workflow_path, console):
6060 else :
6161 lang_counts ['Other' ] += 1
6262
63- src_dir = workflow_path .parent / 'src'
63+ src_dir = workflow_path .parent / source_dir
6464 if not (src_dir / filename ).exists ():
6565 missing_files .append (filename )
6666
@@ -77,11 +77,11 @@ def _inspect_rich(workflow_path, console):
7777
7878 for edge in edges :
7979 label_tag = edge .find ('y:EdgeLabel' )
80- if label_tag and label_tag .text :
81- if edge_label_regex .match (label_tag . text . strip () ):
82- zmq_count += 1
83- else :
84- file_count += 1
80+ label_text = label_tag . text . strip () if label_tag and label_tag .text else ""
81+ if label_text and edge_label_regex .match (label_text ):
82+ zmq_count += 1
83+ else :
84+ file_count += 1
8585
8686 if zmq_count > 0 :
8787 edges_branch .add (f"ZMQ: { zmq_count } " )
@@ -126,7 +126,7 @@ def _inspect_rich(workflow_path, console):
126126 }
127127 lang = lang_map .get (ext , 'Other' )
128128
129- src_dir = workflow_path .parent / 'src'
129+ src_dir = workflow_path .parent / source_dir
130130 status = "✓" if (src_dir / filename ).exists () else "✗"
131131
132132 table .add_row (node_id , filename , lang , status )
@@ -166,7 +166,7 @@ def _inspect_rich(workflow_path, console):
166166 except Exception as e :
167167 console .print (f"[red]Inspection failed:[/red] { str (e )} " )
168168
169- def _inspect_json (workflow_path ):
169+ def _inspect_json (workflow_path , source_dir ):
170170 import json
171171
172172 try :
@@ -175,6 +175,10 @@ def _inspect_json(workflow_path):
175175
176176 soup = BeautifulSoup (content , 'xml' )
177177
178+ if not soup .find ('graphml' ):
179+ print (json .dumps ({'error' : 'Not a valid GraphML file' }, indent = 2 ))
180+ return
181+
178182 nodes = soup .find_all ('node' )
179183 edges = soup .find_all ('edge' )
180184
@@ -202,7 +206,7 @@ def _inspect_json(workflow_path):
202206 lang = lang_map .get (ext , 'other' )
203207 lang_counts [lang ] += 1
204208
205- src_dir = workflow_path .parent / 'src'
209+ src_dir = workflow_path .parent / source_dir
206210 exists = (src_dir / filename ).exists ()
207211 if not exists :
208212 missing_files .append (filename )
@@ -223,13 +227,13 @@ def _inspect_json(workflow_path):
223227 target = edge .get ('target' )
224228
225229 label_tag = edge .find ('y:EdgeLabel' )
230+ label_text = label_tag .text .strip () if label_tag and label_tag .text else ""
226231 edge_type = 'file'
227- if label_tag and label_tag .text :
228- if edge_label_regex .match (label_tag .text .strip ()):
229- edge_type = 'zmq'
230- zmq_count += 1
231- else :
232- file_count += 1
232+ if label_text and edge_label_regex .match (label_text ):
233+ edge_type = 'zmq'
234+ zmq_count += 1
235+ else :
236+ file_count += 1
233237
234238 edge_list .append ({
235239 'source' : source ,
0 commit comments