Skip to content

Commit 60229bf

Browse files
committed
handle stdout
1 parent aa6fad9 commit 60229bf

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

cwl_utils/etools_to_clt.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
import sys
33
import copy
44
import shutil
5+
import hashlib
56
import cwl_utils.parser_v1_0 as cwl
67
from ruamel import yaml
78
from typing import Any, Dict, List, MutableSequence, Optional, Sequence, Text, Tuple, Type, Union
89
from cwltool.expression import do_eval
910
from cwltool.errors import WorkflowException
1011
from schema_salad.sourceline import SourceLine
12+
from schema_salad.utils import json_dumps
1113

1214
SKIP_COMMAND_LINE = True # don't process CommandLineTool.inputs...inputBinding and CommandLineTool.arguments sections
1315
SKIP_COMMAND_LINE2 = True # don't process CommandLineTool.outputEval
@@ -37,6 +39,24 @@ def main():
3739
yaml.round_trip_dump(result_json, sys.stdout)
3840

3941

42+
def expand_stream_shortcuts(process: cwl.CommandLineTool) -> cwl.CommandLineTool:
43+
if not process.outputs:
44+
return process
45+
result = None
46+
for index, output in enumerate(process.outputs):
47+
if output.type == 'stdout':
48+
if not result:
49+
result = copy.deepcopy(process)
50+
stdout_path = process.stdout
51+
if not stdout_path:
52+
stdout_path = str(hashlib.sha1(json_dumps(cwl.save(process)).encode('utf-8')).hexdigest())
53+
result.stdout = stdout_path
54+
result.outputs[index].type = 'File'
55+
output.outputBinding = cwl.CommandOutputBinding(stdout_path, None, None)
56+
if result:
57+
return result
58+
return process
59+
4060
def escape_expression_field(contents: str) -> str:
4161
return contents.replace('${', '$/{').replace('$(', '$/(')
4262

@@ -109,6 +129,7 @@ def etool_to_cltool(etool: cwl.ExpressionTool, expressionLib: Optional[List[str]
109129

110130
def traverse(process: Union[cwl.Process, cwl.CommandLineTool, cwl.ExpressionTool, cwl.Workflow], replace_etool=False, inside=False) -> Tuple[Union[cwl.Process, cwl.CommandLineTool, cwl.ExpressionTool, cwl.Workflow], bool]:
111131
if not inside and isinstance(process, cwl.CommandLineTool):
132+
process = expand_stream_shortcuts(process)
112133
wf_inputs = []
113134
wf_outputs = []
114135
step_inputs = []
@@ -260,7 +281,7 @@ def example_input(some_type: Any) -> Any:
260281
if some_type == 'Directory':
261282
return {'class': 'Directory', 'basename': 'example', 'listing': []}
262283
if some_type == 'File':
263-
return {'class': 'File', 'basename': 'example'}
284+
return {'class': 'File', 'basename': 'example.txt', 'nameroot': 'example', 'nameext': 'txt'}
264285
return None
265286

266287
def type_for_source(process: cwl.Process, sourcenames: Union[str, List[str]], parent: Optional[cwl.Workflow] = None) -> Any:

0 commit comments

Comments
 (0)