Skip to content

Commit 9ffe7f5

Browse files
vjaganat90Vasu Jaganath
andauthored
simplify args dependencies (PolusAI#318)
Co-authored-by: Vasu Jaganath <[email protected]>
1 parent fff0da3 commit 9ffe7f5

File tree

6 files changed

+34
-34
lines changed

6 files changed

+34
-34
lines changed

src/sophios/api/http/restapi.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ async def compile_wf(request: Request) -> Json:
9494
print('---------- Compile Workflow! ---------')
9595
# ========= PROCESS REQUEST OBJECT ==========
9696
req: Json = await request.json()
97-
suppliedargs = ['--cwl_inline_runtag', '--generate_cwl_workflow']
97+
suppliedargs = ['--generate_cwl_workflow']
9898
# clean up and convert the incoming object
9999
# schema preserving
100100
req = converter.update_payload_missing_inputs_outputs(req)
@@ -138,8 +138,11 @@ async def compile_wf(request: Request) -> Json:
138138

139139
rose_tree = compiler_info.rose
140140
input_output.write_to_disk(rose_tree, Path('autogenerated/'), True, args.inputs_file)
141-
rose_tree = cwl_inline_runtag(args, rose_tree)
142-
rose_tree = remove_entrypoints(args, rose_tree)
141+
# generating cwl inline within the 'run' tag is post compile
142+
# and always on when compiling and preparing REST return payload
143+
rose_tree = cwl_inline_runtag(rose_tree)
144+
if args.docker_remove_entrypoints:
145+
rose_tree = remove_entrypoints(args.container_engine, rose_tree)
143146
# ======== OUTPUT PROCESSING ================
144147
# ========= PROCESS COMPILED OBJECT =========
145148
sub_node_data: NodeData = rose_tree.data

src/sophios/api/pythonapi.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,6 @@ def get_cwl_workflow(self) -> Json:
752752
Json: Contains the compiled CWL and yaml inputs to the workflow.
753753
"""
754754
compiler_info = self.compile(write_to_disk=False)
755-
self.user_args.append('--cwl_inline_runtag')
756755
args = get_args(self.process_name, self.user_args)
757756
rose_tree = compiler_info.rose
758757

@@ -761,7 +760,7 @@ def get_cwl_workflow(self) -> Json:
761760
# then remove this write_to_disk call here
762761
input_output.write_to_disk(rose_tree, Path('autogenerated/'), True, args.inputs_file)
763762

764-
rose_tree = post_compile.cwl_inline_runtag(args, rose_tree)
763+
rose_tree = post_compile.cwl_inline_runtag(rose_tree)
765764
sub_node_data = rose_tree.data
766765
cwl_ast = sub_node_data.compiled_cwl
767766

@@ -789,8 +788,9 @@ def run(self) -> None:
789788
args = get_args(self.process_name, self.user_args) # Use mock CLI args
790789
rose_tree: RoseTree = compiler_info.rose
791790

792-
post_compile.cwl_docker_extract(args, self.process_name)
793-
rose_tree = post_compile.remove_entrypoints(args, rose_tree)
791+
post_compile.cwl_docker_extract(args.container_engine, args.pull_dir, self.process_name)
792+
if args.docker_remove_entrypoints:
793+
rose_tree = post_compile.remove_entrypoints(args.container_engine, rose_tree)
794794
post_compile.find_and_create_output_dirs(rose_tree)
795795
# Do NOT capture stdout and/or stderr and pipe warnings and errors into a black hole.
796796
retval = run_local_module.run_local(args, rose_tree, args.cachedir, args.cwl_runner, True)

src/sophios/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
parser.add_argument('--homedir', type=str, required=False, default=str(Path().home()),
2929
help='''The users home directory.
3030
This is necessary because CWL clears environment variables (e.g. HOME)''')
31-
parser.add_argument('--singularity_pull_dir', type=str, required=False, default=str(Path().cwd()),
32-
help='''The user specified pull directory for singularity image pull.
31+
parser.add_argument('--pull_dir', type=str, required=False, default=str(Path().cwd()),
32+
help='''The user specified pull directory for (singularity) image pull.
3333
The default is the current working directory i.e. `pwd`''')
3434
parser.add_argument('--insert_steps_automatically', default=False, action="store_true",
3535
help='''Attempt to fix inference failures by speculatively

src/sophios/main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ def main() -> None:
171171

172172
io.write_to_disk(rose_tree, Path('autogenerated/'), True, args.inputs_file)
173173

174-
rose_tree = pc.cwl_inline_runtag(args, rose_tree)
174+
if args.cwl_inline_runtag:
175+
rose_tree = pc.cwl_inline_runtag(rose_tree)
175176
io.write_to_disk(rose_tree, Path('autogenerated/'), True, args.inputs_file)
176177

177178
if args.graphviz:
@@ -193,8 +194,9 @@ def main() -> None:
193194
print("but not the graphviz system package.)")
194195

195196
if args.run_local or args.generate_run_script:
196-
pc.cwl_docker_extract(args, yaml_stem)
197-
rose_tree = pc.remove_entrypoints(args, rose_tree)
197+
pc.cwl_docker_extract(args.container_engine, args.pull_dir, yaml_stem)
198+
if args.docker_remove_entrypoints:
199+
rose_tree = pc.remove_entrypoints(args.container_engine, rose_tree)
198200
io.write_to_disk(rose_tree, Path('autogenerated/'), True, args.inputs_file)
199201
pc.find_and_create_output_dirs(rose_tree)
200202
run_local.run_local(args, rose_tree, args.cachedir, args.cwl_runner, False)

src/sophios/post_compile.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import argparse
21
from pathlib import Path
32
import subprocess as sub
43
from typing import Dict, Union
@@ -8,11 +7,11 @@
87

98
def find_output_dirs(data: Union[RoseTree, Dict, list]) -> list:
109
"""
11-
Recursively searches through a nested structure and finds all dictionaries
10+
Recursively searches through a nested structure and finds all dictionaries
1211
that contain the key 'location', and a key 'class' with a value of 'Directory'.
1312
1413
Args:
15-
data (any): The data to search through, which can be a dictionary, list,
14+
data (any): The data to search through, which can be a dictionary, list,
1615
or any other structure.
1716
1817
Returns:
@@ -53,38 +52,33 @@ def find_and_create_output_dirs(rose_tree: RoseTree, basepath: str = 'autogenera
5352
create_output_dirs(output_dirs, basepath)
5453

5554

56-
def cwl_docker_extract(args: argparse.Namespace, file_name: str) -> None:
55+
def cwl_docker_extract(container_engine: str, pull_dir: str, file_name: str) -> None:
5756
"""Helper function to do the cwl_docker_extract"""
5857
# cwl-docker-extract recursively `docker pull`s all images in all subworkflows.
5958
# This is important because cwltool only uses `docker run` when executing
6059
# workflows, and if there is a local image available,
6160
# `docker run` will NOT query the remote repository for the latest image!
6261
# cwltool has a --force-docker-pull option, but this may cause multiple pulls in parallel.
63-
if args.container_engine == 'singularity':
62+
if container_engine == 'singularity':
6463
cmd = ['cwl-docker-extract', '-s', '--dir',
65-
f'{args.singularity_pull_dir}', f'autogenerated/{file_name}.cwl']
64+
f'{pull_dir}', f'autogenerated/{file_name}.cwl']
6665
else:
6766
cmd = ['cwl-docker-extract', '--force-download', f'autogenerated/{file_name}.cwl']
6867
sub.run(cmd, check=True)
6968

7069

71-
def cwl_inline_runtag(args: argparse.Namespace, rose_tree: RoseTree) -> RoseTree:
70+
def cwl_inline_runtag(rose_tree: RoseTree) -> RoseTree:
7271
"""Transform with cwl inline runtag"""
7372
# this has to happen after at least one write
7473
# so we can copy from local cwl_dapters in autogenerated/
75-
if args.cwl_inline_runtag:
76-
rose_tree = plugins.cwl_update_inline_runtag_rosetree(rose_tree, Path('autogenerated/'), True)
77-
return rose_tree
74+
return plugins.cwl_update_inline_runtag_rosetree(rose_tree, Path('autogenerated/'), True)
7875

7976

80-
def remove_entrypoints(args: argparse.Namespace, rose_tree: RoseTree) -> RoseTree:
77+
def remove_entrypoints(container_engine: str, rose_tree: RoseTree) -> RoseTree:
8178
"""Remove entry points"""
82-
if args.docker_remove_entrypoints:
83-
# Requires root, so guard behind CLI option
84-
if args.container_engine == 'docker':
85-
plugins.remove_entrypoints_docker()
86-
if args.container_engine == 'podman':
87-
plugins.remove_entrypoints_podman()
88-
89-
rose_tree = plugins.dockerPull_append_noentrypoint_rosetree(rose_tree)
90-
return rose_tree
79+
# Requires root, so guard behind CLI option
80+
if container_engine == 'docker':
81+
plugins.remove_entrypoints_docker()
82+
if container_engine == 'podman':
83+
plugins.remove_entrypoints_podman()
84+
return plugins.dockerPull_append_noentrypoint_rosetree(rose_tree)

tests/test_examples.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,11 @@ def run_workflows(yml_path_str: str, yml_path: Path, cwl_runner: str, args: argp
213213
sophios.input_output.write_to_disk(rose_tree, Path('autogenerated/'), True, args.inputs_file)
214214

215215
if docker_pull_only:
216-
cwl_docker_extract(args, Path(yml_path).stem)
216+
cwl_docker_extract(args.container_engine, args.pull_dir, Path(yml_path).stem)
217217
return
218218

219-
rose_tree = remove_entrypoints(args, rose_tree)
219+
if args.docker_remove_entrypoints:
220+
rose_tree = remove_entrypoints(args.container_engine, rose_tree)
220221
sophios.input_output.write_to_disk(rose_tree, Path('autogenerated/'), True, args.inputs_file)
221222

222223
if args.partial_failure_enable:

0 commit comments

Comments
 (0)