Skip to content

Commit 9b5cad1

Browse files
author
Vasu Jaganath
committed
consolidate dict boilerplate into one function
1 parent dee83eb commit 9b5cad1

File tree

8 files changed

+49
-203
lines changed

8 files changed

+49
-203
lines changed

src/sophios/apis/python/api.py

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from sophios import compiler, input_output, plugins, utils_cwl
1616
from sophios import run_local as rl
1717
from sophios import post_compile as pc
18-
from sophios.cli import get_args, get_known_and_unknown_args
18+
from sophios.cli import get_args, get_known_and_unknown_args, get_dicts_for_compilation
1919
from sophios.utils_graphs import get_graph_reps
2020
from sophios.utils import convert_args_dict_to_args_list
2121
from sophios.wic_types import CompilerInfo, RoseTree, StepId, Tool, Tools, YamlTree, Json
@@ -720,28 +720,7 @@ def compile(self, write_to_disk: bool = False) -> CompilerInfo:
720720
steps_config = extract_tools_paths_NONPORTABLE(self.flatten_steps())
721721
global_config = merge(steps_config, global_config, strategy=Strategy.TYPESAFE_REPLACE)
722722

723-
# core compiler options for transformation into CWL
724-
compiler_options: Dict[str, bool] = {}
725-
compiler_options['partial_failure_enable'] = args.partial_failure_enable
726-
compiler_options['inference_use_naming_conventions'] = args.inference_use_naming_conventions
727-
compiler_options['insert_steps_automatically'] = args.insert_steps_automatically
728-
compiler_options['inference_disable'] = args.inference_disable
729-
compiler_options['allow_raw_cwl'] = args.allow_raw_cwl
730-
731-
# to be given to graph util functions
732-
graph_settings: Dict[str, Any] = {}
733-
graph_settings['graph_dark_theme'] = args.graph_dark_theme
734-
graph_settings['graph_inline_depth'] = args.graph_inline_depth
735-
graph_settings['graph_label_edges'] = args.graph_label_edges
736-
graph_settings['graph_label_stepname'] = args.graph_label_stepname
737-
graph_settings['graph_show_outputs'] = args.graph_show_outputs
738-
graph_settings['graph_show_inputs'] = args.graph_show_inputs
739-
740-
# to be given to io absolute_yaml_tags function
741-
yaml_tag_paths: Dict[str, str] = {}
742-
yaml_tag_paths['cachedir'] = args.cachedir
743-
yaml_tag_paths['yaml'] = args.yaml
744-
yaml_tag_paths['homedir'] = args.homedir
723+
compiler_options, graph_settings, yaml_tag_paths = get_dicts_for_compilation()
745724

746725
# The compile_workflow function is 100% in-memory
747726
compiler_info = compiler.compile_workflow(yaml_tree, compiler_options, graph_settings, yaml_tag_paths,

src/sophios/apis/rest/api.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from pathlib import Path
22
import copy
33
import yaml
4-
from typing import Dict, Any
54

65

76
import uvicorn
@@ -14,7 +13,7 @@
1413
from sophios.utils_yaml import wic_loader
1514
from sophios import utils_cwl
1615
from sophios.post_compile import cwl_inline_runtag
17-
from sophios.cli import get_args
16+
from sophios.cli import get_args, get_dicts_for_compilation
1817
from sophios.wic_types import CompilerInfo, Json, Tool, Tools, StepId, YamlTree, Cwl, NodeData
1918
from sophios.apis.utils import converter
2019
import sophios.plugins as plugins
@@ -112,28 +111,7 @@ async def compile_wf(request: Request) -> Json:
112111
graph = get_graph_reps(wkflw_name)
113112
yaml_tree: YamlTree = YamlTree(StepId(wkflw_name, plugin_ns), workflow_can)
114113

115-
# core compiler options for transformation into CWL
116-
compiler_options: Dict[str, bool] = {}
117-
compiler_options['partial_failure_enable'] = args.partial_failure_enable
118-
compiler_options['inference_use_naming_conventions'] = args.inference_use_naming_conventions
119-
compiler_options['insert_steps_automatically'] = args.insert_steps_automatically
120-
compiler_options['inference_disable'] = args.inference_disable
121-
compiler_options['allow_raw_cwl'] = args.allow_raw_cwl
122-
123-
# to be given to graph util functions
124-
graph_settings: Dict[str, Any] = {}
125-
graph_settings['graph_dark_theme'] = args.graph_dark_theme
126-
graph_settings['graph_inline_depth'] = args.graph_inline_depth
127-
graph_settings['graph_label_edges'] = args.graph_label_edges
128-
graph_settings['graph_label_stepname'] = args.graph_label_stepname
129-
graph_settings['graph_show_outputs'] = args.graph_show_outputs
130-
graph_settings['graph_show_inputs'] = args.graph_show_inputs
131-
132-
# to be given to io absolute_yaml_tags function
133-
yaml_tag_paths: Dict[str, str] = {}
134-
yaml_tag_paths['cachedir'] = args.cachedir
135-
yaml_tag_paths['yaml'] = args.yaml
136-
yaml_tag_paths['homedir'] = args.homedir
114+
compiler_options, graph_settings, yaml_tag_paths = get_dicts_for_compilation()
137115

138116
# ========= COMPILE WORKFLOW ================
139117
compiler_info: CompilerInfo = compiler.compile_workflow(yaml_tree, compiler_options, graph_settings, yaml_tag_paths,

src/sophios/cli.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import argparse
22
import sys
33
from pathlib import Path
4-
from typing import List, Tuple
4+
from typing import List, Tuple, Dict, Any
55
from unittest.mock import patch
66

77
from . import _version
@@ -153,3 +153,36 @@ def get_known_and_unknown_args(yaml_path: str = '', suppliedargs: list[str] = []
153153
with patch.object(sys, 'argv', testargs):
154154
known_args, unknown_args = parser.parse_known_args()
155155
return known_args, unknown_args
156+
157+
158+
def get_dicts_for_compilation() -> Tuple[Dict[str, bool], Dict[str, Any], Dict[str, str]]:
159+
"""This is used to get default command line arguments for compilation
160+
as a tuple of three dictionaries
161+
162+
Returns:
163+
Tuple[Dict[str, bool], Dict[str,Any], Dict[str, str]]: The mocked command line arguments
164+
"""
165+
args = get_args()
166+
# core compiler options for transformation into CWL
167+
compiler_options: Dict[str, bool] = {}
168+
compiler_options['partial_failure_enable'] = args.partial_failure_enable
169+
compiler_options['inference_use_naming_conventions'] = args.inference_use_naming_conventions
170+
compiler_options['insert_steps_automatically'] = args.insert_steps_automatically
171+
compiler_options['inference_disable'] = args.inference_disable
172+
compiler_options['allow_raw_cwl'] = args.allow_raw_cwl
173+
174+
# to be given to graph util functions
175+
graph_settings: Dict[str, Any] = {}
176+
graph_settings['graph_dark_theme'] = args.graph_dark_theme
177+
graph_settings['graph_inline_depth'] = args.graph_inline_depth
178+
graph_settings['graph_label_edges'] = args.graph_label_edges
179+
graph_settings['graph_label_stepname'] = args.graph_label_stepname
180+
graph_settings['graph_show_outputs'] = args.graph_show_outputs
181+
graph_settings['graph_show_inputs'] = args.graph_show_inputs
182+
183+
# to be given to io absolute_yaml_tags function
184+
yaml_tag_paths: Dict[str, str] = {}
185+
yaml_tag_paths['cachedir'] = args.cachedir
186+
yaml_tag_paths['yaml'] = args.yaml
187+
yaml_tag_paths['homedir'] = args.homedir
188+
return (compiler_options, graph_settings, yaml_tag_paths)

src/sophios/cwl_subinterpreter.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -109,35 +109,15 @@ def rerun_cwltool(homedir: str, _directory_realtime: Path, cachedir_path: Path,
109109

110110
# Setup dummy args
111111
args = cli.get_args()
112+
compiler_options, graph_settings, yaml_tag_paths = cli.get_dicts_for_compilation()
112113

113114
# TODO: Support other namespaces
114115
plugin_ns = 'global' # wic['wic'].get('namespace', 'global')
115116
yaml_path = f'{cwl_tool}_only.wic'
116117
stepid = StepId(yaml_path, plugin_ns)
117118
yaml_tree = YamlTree(stepid, yml)
118119
subgraph = GraphReps(graphviz.Digraph(name=yaml_path), nx.DiGraph(), GraphData(yaml_path))
119-
# core compiler options for transformation into CWL
120-
compiler_options: Dict[str, bool] = {}
121-
compiler_options['partial_failure_enable'] = args.partial_failure_enable
122-
compiler_options['inference_use_naming_conventions'] = args.inference_use_naming_conventions
123-
compiler_options['insert_steps_automatically'] = args.insert_steps_automatically
124-
compiler_options['inference_disable'] = args.inference_disable
125-
compiler_options['allow_raw_cwl'] = args.allow_raw_cwl
126-
127-
# to be given to graph util functions
128-
graph_settings: Dict[str, Any] = {}
129-
graph_settings['graph_dark_theme'] = args.graph_dark_theme
130-
graph_settings['graph_inline_depth'] = args.graph_inline_depth
131-
graph_settings['graph_label_edges'] = args.graph_label_edges
132-
graph_settings['graph_label_stepname'] = args.graph_label_stepname
133-
graph_settings['graph_show_outputs'] = args.graph_show_outputs
134-
graph_settings['graph_show_inputs'] = args.graph_show_inputs
135-
136-
# to be given to io absolute_yaml_tags function
137-
yaml_tag_paths: Dict[str, str] = {}
138-
yaml_tag_paths['cachedir'] = args.cachedir
139-
yaml_tag_paths['yaml'] = args.yaml
140-
yaml_tag_paths['homedir'] = args.homedir
120+
141121
compiler_info = compiler.compile_workflow(yaml_tree, compiler_options, graph_settings, yaml_tag_paths,
142122
[], [subgraph], {}, {}, {}, {},
143123
tools_cwl, True, relative_run_path=False, testing=False)

src/sophios/main.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -143,28 +143,7 @@ def main() -> None:
143143
graphdata = GraphData(yaml_path)
144144
subgraph = GraphReps(subgraph_gv, subgraph_nx, graphdata)
145145

146-
# core compiler options for transformation into CWL
147-
compiler_options: Dict[str, bool] = {}
148-
compiler_options['partial_failure_enable'] = args.partial_failure_enable
149-
compiler_options['inference_use_naming_conventions'] = args.inference_use_naming_conventions
150-
compiler_options['insert_steps_automatically'] = args.insert_steps_automatically
151-
compiler_options['inference_disable'] = args.inference_disable
152-
compiler_options['allow_raw_cwl'] = args.allow_raw_cwl
153-
154-
# to be given to graph util functions
155-
graph_settings: Dict[str, Any] = {}
156-
graph_settings['graph_dark_theme'] = args.graph_dark_theme
157-
graph_settings['graph_inline_depth'] = args.graph_inline_depth
158-
graph_settings['graph_label_edges'] = args.graph_label_edges
159-
graph_settings['graph_label_stepname'] = args.graph_label_stepname
160-
graph_settings['graph_show_outputs'] = args.graph_show_outputs
161-
graph_settings['graph_show_inputs'] = args.graph_show_inputs
162-
163-
# to be given to io absolute_yaml_tags function
164-
yaml_tag_paths: Dict[str, str] = {}
165-
yaml_tag_paths['cachedir'] = args.cachedir
166-
yaml_tag_paths['yaml'] = args.yaml
167-
yaml_tag_paths['homedir'] = args.homedir
146+
compiler_options, graph_settings, yaml_tag_paths = cli.get_dicts_for_compilation()
168147

169148
try:
170149
compiler_info = compiler.compile_workflow(yaml_tree, compiler_options, graph_settings, yaml_tag_paths,

src/sophios/schemas/wic_schema.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import sophios
1414
from sophios import ast, compiler, utils_cwl
15-
from sophios.cli import get_args
15+
from sophios.cli import get_args, get_dicts_for_compilation
1616
from sophios.utils_yaml import wic_loader
1717
from sophios.wic_types import GraphData, GraphReps, NodeData, StepId, Yaml, YamlTree
1818
from ..wic_types import Json, Tools
@@ -640,28 +640,8 @@ def compile_workflow_generate_schema(homedir: str,
640640
graph = GraphReps(graph_gv, graph_nx, graphdata)
641641
args = get_args(str(yml_path), ['--allow_raw_cwl'] if allow_raw_cwl else [])
642642

643-
# core compiler options for transformation into CWL
644-
compiler_options: Dict[str, bool] = {}
645-
compiler_options['partial_failure_enable'] = args.partial_failure_enable
646-
compiler_options['inference_use_naming_conventions'] = args.inference_use_naming_conventions
647-
compiler_options['insert_steps_automatically'] = args.insert_steps_automatically
648-
compiler_options['inference_disable'] = args.inference_disable
649-
compiler_options['allow_raw_cwl'] = args.allow_raw_cwl
650-
651-
# to be given to graph util functions
652-
graph_settings: Dict[str, Any] = {}
653-
graph_settings['graph_dark_theme'] = args.graph_dark_theme
654-
graph_settings['graph_inline_depth'] = args.graph_inline_depth
655-
graph_settings['graph_label_edges'] = args.graph_label_edges
656-
graph_settings['graph_label_stepname'] = args.graph_label_stepname
657-
graph_settings['graph_show_outputs'] = args.graph_show_outputs
658-
graph_settings['graph_show_inputs'] = args.graph_show_inputs
659-
660-
# to be given to io absolute_yaml_tags function
661-
yaml_tag_paths: Dict[str, str] = {}
662-
yaml_tag_paths['cachedir'] = args.cachedir
663-
yaml_tag_paths['yaml'] = args.yaml
664-
yaml_tag_paths['homedir'] = args.homedir
643+
compiler_options, graph_settings, yaml_tag_paths = get_dicts_for_compilation()
644+
665645
compiler_info = compiler.compile_workflow(yaml_tree, compiler_options, graph_settings, yaml_tag_paths, [], [graph],
666646
{}, {}, {}, {}, tools_cwl, True, relative_run_path=True, testing=True)
667647
rose_tree = compiler_info.rose

tests/test_examples.py

Lines changed: 4 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -202,28 +202,7 @@ def run_workflows(yml_path_str: str, yml_path: Path, cwl_runner: str, args: argp
202202
with open(f'autogenerated/{Path(yml_path).stem}_tree_merged_inlined.wic', mode='w', encoding='utf-8') as f:
203203
f.write(yaml.dump(yaml_tree.yml))
204204

205-
# core compiler options for transformation into CWL
206-
compiler_options: Dict[str, bool] = {}
207-
compiler_options['partial_failure_enable'] = args.partial_failure_enable
208-
compiler_options['inference_use_naming_conventions'] = args.inference_use_naming_conventions
209-
compiler_options['insert_steps_automatically'] = args.insert_steps_automatically
210-
compiler_options['inference_disable'] = args.inference_disable
211-
compiler_options['allow_raw_cwl'] = args.allow_raw_cwl
212-
213-
# to be given to graph util functions
214-
graph_settings = {}
215-
graph_settings['graph_dark_theme'] = args.graph_dark_theme
216-
graph_settings['graph_inline_depth'] = args.graph_inline_depth
217-
graph_settings['graph_label_edges'] = args.graph_label_edges
218-
graph_settings['graph_label_stepname'] = args.graph_label_stepname
219-
graph_settings['graph_show_outputs'] = args.graph_show_outputs
220-
graph_settings['graph_show_inputs'] = args.graph_show_inputs
221-
222-
# to be given to io absolute_yaml_tags function
223-
yaml_tag_paths: Dict[str, str] = {}
224-
yaml_tag_paths['cachedir'] = args.cachedir
225-
yaml_tag_paths['yaml'] = args.yaml
226-
yaml_tag_paths['homedir'] = args.homedir
205+
compiler_options, graph_settings, yaml_tag_paths = sophios.cli.get_dicts_for_compilation()
227206

228207
graph = get_graph_reps(str(yml_path))
229208
compiler_info = sophios.compiler.compile_workflow(yaml_tree, compiler_options, graph_settings, yaml_tag_paths,
@@ -306,28 +285,8 @@ def test_cwl_embedding_independence(yml_path_str: str, yml_path: Path) -> None:
306285

307286
graph = get_graph_reps(str(yml_path))
308287
is_root = True
309-
# core compiler options for transformation into CWL
310-
compiler_options: Dict[str, bool] = {}
311-
compiler_options['partial_failure_enable'] = args.partial_failure_enable
312-
compiler_options['inference_use_naming_conventions'] = args.inference_use_naming_conventions
313-
compiler_options['insert_steps_automatically'] = args.insert_steps_automatically
314-
compiler_options['inference_disable'] = args.inference_disable
315-
compiler_options['allow_raw_cwl'] = args.allow_raw_cwl
316-
317-
# to be given to graph util functions
318-
graph_settings = {}
319-
graph_settings['graph_dark_theme'] = args.graph_dark_theme
320-
graph_settings['graph_inline_depth'] = args.graph_inline_depth
321-
graph_settings['graph_label_edges'] = args.graph_label_edges
322-
graph_settings['graph_label_stepname'] = args.graph_label_stepname
323-
graph_settings['graph_show_outputs'] = args.graph_show_outputs
324-
graph_settings['graph_show_inputs'] = args.graph_show_inputs
325-
326-
# to be given to io absolute_yaml_tags function
327-
yaml_tag_paths: Dict[str, str] = {}
328-
yaml_tag_paths['cachedir'] = args.cachedir
329-
yaml_tag_paths['yaml'] = args.yaml
330-
yaml_tag_paths['homedir'] = args.homedir
288+
289+
compiler_options, graph_settings, yaml_tag_paths = sophios.cli.get_dicts_for_compilation()
331290

332291
compiler_info = sophios.compiler.compile_workflow(yaml_tree, compiler_options, graph_settings, yaml_tag_paths,
333292
[], [graph], {}, {}, {}, {}, tools_cwl,
@@ -434,28 +393,7 @@ def test_inline_subworkflows(yml_path_str: str, yml_path: Path) -> None:
434393
if namespaces_list == []:
435394
assert True # There's nothing to test
436395

437-
# core compiler options for transformation into CWL
438-
compiler_options: Dict[str, bool] = {}
439-
compiler_options['partial_failure_enable'] = args.partial_failure_enable
440-
compiler_options['inference_use_naming_conventions'] = args.inference_use_naming_conventions
441-
compiler_options['insert_steps_automatically'] = args.insert_steps_automatically
442-
compiler_options['inference_disable'] = args.inference_disable
443-
compiler_options['allow_raw_cwl'] = args.allow_raw_cwl
444-
445-
# to be given to graph util functions
446-
graph_settings: Dict[str, Any] = {}
447-
graph_settings['graph_dark_theme'] = args.graph_dark_theme
448-
graph_settings['graph_inline_depth'] = args.graph_inline_depth
449-
graph_settings['graph_label_edges'] = args.graph_label_edges
450-
graph_settings['graph_label_stepname'] = args.graph_label_stepname
451-
graph_settings['graph_show_outputs'] = args.graph_show_outputs
452-
graph_settings['graph_show_inputs'] = args.graph_show_inputs
453-
454-
# to be given to io absolute_yaml_tags function
455-
yaml_tag_paths: Dict[str, str] = {}
456-
yaml_tag_paths['cachedir'] = args.cachedir
457-
yaml_tag_paths['yaml'] = args.yaml
458-
yaml_tag_paths['homedir'] = args.homedir
396+
compiler_options, graph_settings, yaml_tag_paths = sophios.cli.get_dicts_for_compilation()
459397

460398
graph = get_graph_reps(str(yml_path))
461399
compiler_info = sophios.compiler.compile_workflow(yaml_tree, compiler_options, graph_settings, yaml_tag_paths, [], [graph], {},

tests/test_fuzzy_compile.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from datetime import timedelta
22
from pathlib import Path
3-
from typing import Dict, Any
43
import unittest
54

65
import graphviz
@@ -61,28 +60,8 @@ def test_fuzzy_compile(self, yml: Yaml) -> None:
6160
graph_nx = nx.DiGraph()
6261
graphdata = GraphData(str(yml_path))
6362
graph = GraphReps(graph_gv, graph_nx, graphdata)
64-
# core compiler options for transformation into CWL
65-
compiler_options: Dict[str, bool] = {}
66-
compiler_options['partial_failure_enable'] = args.partial_failure_enable
67-
compiler_options['inference_use_naming_conventions'] = args.inference_use_naming_conventions
68-
compiler_options['insert_steps_automatically'] = args.insert_steps_automatically
69-
compiler_options['inference_disable'] = args.inference_disable
70-
compiler_options['allow_raw_cwl'] = args.allow_raw_cwl
7163

72-
# to be given to graph util functions
73-
graph_settings: Dict[str, Any] = {}
74-
graph_settings['graph_dark_theme'] = args.graph_dark_theme
75-
graph_settings['graph_inline_depth'] = args.graph_inline_depth
76-
graph_settings['graph_label_edges'] = args.graph_label_edges
77-
graph_settings['graph_label_stepname'] = args.graph_label_stepname
78-
graph_settings['graph_show_outputs'] = args.graph_show_outputs
79-
graph_settings['graph_show_inputs'] = args.graph_show_inputs
80-
81-
# to be given to io absolute_yaml_tags function
82-
yaml_tag_paths: Dict[str, str] = {}
83-
yaml_tag_paths['cachedir'] = args.cachedir
84-
yaml_tag_paths['yaml'] = args.yaml
85-
yaml_tag_paths['homedir'] = args.homedir
64+
compiler_options, graph_settings, yaml_tag_paths = sophios.cli.get_dicts_for_compilation()
8665

8766
try:
8867
compiler_info = sophios.compiler.compile_workflow(yaml_tree, compiler_options, graph_settings,

0 commit comments

Comments
 (0)