Skip to content

Commit 2823031

Browse files
vjaganat90Vasu Jaganath
andauthored
add mechanism for passthrough flags for Toil (PolusAI#323)
Co-authored-by: Vasu Jaganath <[email protected]>
1 parent c723dc8 commit 2823031

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

src/sophios/api/pythonapi.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from sophios import compiler, input_output, plugins, utils_cwl, post_compile
1515
from sophios import run_local as run_local_module
16-
from sophios.cli import get_args
16+
from sophios.cli import get_args, get_known_and_unknown_args
1717
from sophios.utils_graphs import get_graph_reps
1818
from sophios.wic_types import CompilerInfo, RoseTree, StepId, Tool, Tools, YamlTree, Json
1919

@@ -785,15 +785,19 @@ def run(self) -> None:
785785
logger.info(f"Running {self.process_name}")
786786
plugins.logging_filters()
787787
compiler_info = self.compile(write_to_disk=True)
788-
args = get_args(self.process_name, self.user_args) # Use mock CLI args
788+
args, unknown_args = get_known_and_unknown_args(self.process_name, self.user_args) # Use mock CLI args
789789
rose_tree: RoseTree = compiler_info.rose
790790

791791
post_compile.cwl_docker_extract(args.container_engine, args.pull_dir, self.process_name)
792792
if args.docker_remove_entrypoints:
793793
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.
796-
retval = run_local_module.run_local(args, rose_tree, args.cachedir, args.cwl_runner, True)
796+
if args.toil_passthrough_flags == 'yes':
797+
run_local_module.run_local(args, rose_tree, args.cachedir, args.cwl_runner,
798+
True, passthrough_args=unknown_args)
799+
else:
800+
run_local_module.run_local(args, rose_tree, args.cachedir, args.cwl_runner, True)
797801

798802
# Finally, since there is an output file copying bug in cwltool,
799803
# we need to copy the output files manually. See comment above.

src/sophios/cli.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import argparse
22
import sys
33
from pathlib import Path
4+
from typing import List, Tuple
45
from unittest.mock import patch
56

67
from . import _version
@@ -124,6 +125,11 @@
124125
help='Changees the color of the fonts and edges from white to black.')
125126
parser.add_argument('--custom_net', type=str, required=False,
126127
help='Passes --custom-net flag to cwltool.')
128+
parser.add_argument('--toil_passthrough_flags', type=str, default='no', required=False,
129+
help='''Indicates that the user is passing flags to the Toil backend.
130+
No checks are done on the flags or values passed. User must verify that they are sending correct flags.
131+
only two valid values of this flag 'yes' or 'no'.
132+
If set to 'no' (default) passthrough flags won't be sent to the Toil backend.''')
127133

128134

129135
def get_args(yaml_path: str = '', suppliedargs: list[str] = []) -> argparse.Namespace:
@@ -137,3 +143,16 @@ def get_args(yaml_path: str = '', suppliedargs: list[str] = []) -> argparse.Name
137143
with patch.object(sys, 'argv', testargs):
138144
args = parser.parse_args()
139145
return args
146+
147+
148+
def get_known_and_unknown_args(yaml_path: str = '', suppliedargs: list[str] = []) -> Tuple[argparse.Namespace, List[str]]:
149+
"""This is used to get mock command line arguments, default + suppled args
150+
151+
Returns:
152+
argparse.Namespace: The mocked command line arguments
153+
"""
154+
defaultargs = ['sophios', '--yaml', yaml_path] # ignore --yaml
155+
testargs = defaultargs + suppliedargs
156+
with patch.object(sys, 'argv', testargs):
157+
known_args, unknown_args = parser.parse_known_args()
158+
return known_args, unknown_args

src/sophios/main.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
def main() -> None:
2121
"""See docs/userguide.md"""
22-
args = cli.parser.parse_args()
22+
args, unknown_args = cli.parser.parse_known_args()
2323
plugins.logging_filters()
2424

2525
# User may specify a different homedir
@@ -199,7 +199,10 @@ def main() -> None:
199199
rose_tree = pc.remove_entrypoints(args.container_engine, rose_tree)
200200
io.write_to_disk(rose_tree, Path('autogenerated/'), True, args.inputs_file)
201201
pc.find_and_create_output_dirs(rose_tree)
202-
run_local.run_local(args, rose_tree, args.cachedir, args.cwl_runner, False)
202+
if args.toil_passthrough_flags == 'yes':
203+
run_local.run_local(args, rose_tree, args.cachedir, args.cwl_runner, False, passthrough_args=unknown_args)
204+
else:
205+
run_local.run_local(args, rose_tree, args.cachedir, args.cwl_runner, False)
203206

204207
# Finally, since there is an output file copying bug in cwltool,
205208
# we need to copy the output files manually. See comment above.

src/sophios/run_local.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def generate_run_script(cmdline: str) -> None:
5050

5151

5252
def run_local(args: argparse.Namespace, rose_tree: RoseTree, cachedir: Optional[str], cwl_runner: str,
53-
use_subprocess: bool) -> int:
53+
use_subprocess: bool, passthrough_args: List[str] = []) -> int:
5454
"""This function runs the compiled workflow locally.
5555
5656
Args:
@@ -250,9 +250,8 @@ def run_local(args: argparse.Namespace, rose_tree: RoseTree, cachedir: Optional[
250250
date_time = now.strftime("%Y%m%d%H%M%S")
251251
cmd += ['--outdir', f'outdir_toil_{yaml_stem}_{date_time}',
252252
'--jobStore', f'file:./jobStore_{yaml_stem}', # NOTE: This is the equivalent of --cachedir
253-
# TODO: Check --clean, --cleanWorkDir, --restart
254-
'--clean', 'always', # This effectively disables caching, but is reproducible
255253
f'autogenerated/{yaml_stem}.cwl', f'autogenerated/{yaml_stem}_inputs.yml']
254+
cmd += passthrough_args
256255
cmdline = ' '.join(cmd)
257256

258257
if args.generate_run_script:

0 commit comments

Comments
 (0)