Skip to content

Commit 98e64c6

Browse files
author
Vasu Jaganath
committed
remove args from inference.py,removing args 2/n
1 parent a2d0396 commit 98e64c6

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

src/sophios/compiler.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ def compile_workflow_once(yaml_tree_ast: YamlTree,
209209

210210
tools_lst: List[Tool] = []
211211

212+
graph_settings = {}
213+
graph_settings['graph_dark_theme'] = args.graph_dark_theme
214+
graph_settings['graph_inline_depth'] = args.graph_inline_depth
215+
graph_settings['graph_label_edges'] = args.graph_label_edges
216+
212217
for i, step_key in enumerate(steps_keys):
213218
step_name_i = utils.step_name_str(yaml_stem, i, step_key)
214219
stem = Path(step_key).stem
@@ -315,7 +320,8 @@ def compile_workflow_once(yaml_tree_ast: YamlTree,
315320
# Use auto-discovery mechanism (with run tag)
316321
tool_i = tools[stepid_runtag]
317322
else:
318-
msg = f"Error! Neither {stepid.stem} nor {stepid_runtag.stem} found!, check your 'search_paths_cwl' in global_config.json"
323+
msg = f"Error! Neither {stepid.stem} nor {
324+
stepid_runtag.stem} found!, check your 'search_paths_cwl' in global_config.json"
319325
raise Exception(msg)
320326
# Programmatically modify tool_i here
321327
graph_dummy = graph # Just use anything here to satisfy mypy
@@ -604,7 +610,7 @@ def compile_workflow_once(yaml_tree_ast: YamlTree,
604610
else:
605611
nss_call = namespaces + [step_name_or_key] + nss_call_embedded
606612

607-
utils_graphs.add_graph_edge(args, graph_init, nss_def, nss_call, label, color='blue')
613+
utils_graphs.add_graph_edge(graph_settings, graph_init, nss_def, nss_call, label, color='blue')
608614
elif isinstance(arg_val, Dict) and 'wic_inline_input' in arg_val:
609615
arg_val = arg_val['wic_inline_input']
610616

@@ -747,7 +753,8 @@ def compile_workflow_once(yaml_tree_ast: YamlTree,
747753
insertions: List[StepId] = []
748754
in_name_in_inputs_file_workflow: bool = (in_name in inputs_file_workflow)
749755
arg_key_in_yaml_tree_inputs: bool = (arg_key in yaml_tree.get('inputs', {}))
750-
steps[i] = inference.perform_edge_inference(args, tools, tools_lst, steps_keys,
756+
inference_use_naming_conventions = args.inference_use_naming_conventions
757+
steps[i] = inference.perform_edge_inference(inference_use_naming_conventions, graph_settings, tools, tools_lst, steps_keys,
751758
yaml_stem, i, steps, arg_key, graph, is_root, namespaces,
752759
vars_workflow_output_internal, input_mapping_copy, output_mapping_copy, inputs_workflow, in_name,
753760
in_name_in_inputs_file_workflow, arg_key_in_yaml_tree_inputs, insertions, wic_steps, testing)

src/sophios/inference.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import argparse
21
from pathlib import Path
32
from typing import Any, Dict, List, Tuple
43

@@ -31,7 +30,8 @@ def types_match(in_type: Any, out_type: Any) -> bool:
3130
return False
3231

3332

34-
def perform_edge_inference(args: argparse.Namespace,
33+
def perform_edge_inference(inference_use_naming_conventions: bool,
34+
graph_settings: Dict[str, Any],
3535
tools: Tools,
3636
tools_lst: List[Tool],
3737
steps_keys: List[str],
@@ -56,7 +56,8 @@ def perform_edge_inference(args: argparse.Namespace,
5656
NOTE: steps[i], vars_workflow_output_internal, inputs_workflow are mutably updated.
5757
5858
Args:
59-
args (argparse.Namespace): The command line arguments
59+
inference_use_naming_conventions (bool): If to do inference using naming conventions
60+
graph_settings(Dict[str,Any]) : The settings needed for graphviz graph generation
6061
tools (Tools): The CWL CommandLineTool definitions found using get_tools_cwl()
6162
tools_lst (List[Tool]): A list of the CWL CommandLineTools or compiled subworkflows for the current workflow.
6263
steps_keys (List[str]): The name of each step in the current CWL workflow
@@ -183,7 +184,7 @@ def perform_edge_inference(args: argparse.Namespace,
183184
# By default, simply choose the first (i.e. most-recent) matching format
184185
out_key = format_matches[0][0]
185186

186-
if args.inference_use_naming_conventions: # default False
187+
if inference_use_naming_conventions: # default False
187188
if len(format_matches) == 1:
188189
# Great! We found a unique format match.
189190
out_key = format_matches[0][0]
@@ -276,7 +277,7 @@ def perform_edge_inference(args: argparse.Namespace,
276277
# TODO: check this
277278
out_key_no_namespace = out_key.split('___')[-1]
278279
label = out_key_no_namespace if tool_j.cwl['class'] == 'Workflow' else out_key
279-
utils_graphs.add_graph_edge(args, graph, nss1, nss2, label)
280+
utils_graphs.add_graph_edge(graph_settings, graph, nss1, nss2, label)
280281

281282
return steps_i # Short circuit
282283

src/sophios/utils_graphs.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import argparse
22
from pathlib import Path
3-
from typing import List
3+
from typing import List, Dict, Any
44

55
import graphviz
66
import networkx as nx
77

88
from .wic_types import (GraphData, GraphReps, Json, Namespaces, Tool, Tools)
99

1010

11-
def add_graph_edge(args: argparse.Namespace, graph: GraphReps,
11+
def add_graph_edge(graph_settings: Dict[str, Any], graph: GraphReps,
1212
nss1: Namespaces, nss2: Namespaces,
1313
label: str, color: str = '') -> None:
1414
"""Adds edges to (all of) our graph representations, with the ability to
@@ -28,10 +28,10 @@ def add_graph_edge(args: argparse.Namespace, graph: GraphReps,
2828
color (str, optional): The edge color
2929
"""
3030
if color == '':
31-
color = 'black' if args.graph_dark_theme else 'white'
32-
nss1 = nss1[:(1 + args.graph_inline_depth)]
31+
color = 'black' if graph_settings['graph_dark_theme'] else 'white'
32+
nss1 = nss1[:(1 + graph_settings['graph_inline_depth'])]
3333
edge_node1 = '___'.join(nss1)
34-
nss2 = nss2[:(1 + args.graph_inline_depth)]
34+
nss2 = nss2[:(1 + graph_settings['graph_inline_depth'])]
3535
edge_node2 = '___'.join(nss2)
3636
graph_gv = graph.graphviz
3737
graph_nx = graph.networkx
@@ -40,7 +40,7 @@ def add_graph_edge(args: argparse.Namespace, graph: GraphReps,
4040
# Hide internal self-edges
4141
if edge_node1 != edge_node2:
4242
attrs = {'color': color}
43-
if args.graph_label_edges:
43+
if graph_settings['graph_label_edges']:
4444
attrs['label'] = label
4545

4646
graph_gv.edge(edge_node1, edge_node2, **attrs)

0 commit comments

Comments
 (0)