|
2 | 2 | import sys |
3 | 3 | import copy |
4 | 4 | import shutil |
| 5 | +import hashlib |
5 | 6 | import cwl_utils.parser_v1_0 as cwl |
6 | 7 | from ruamel import yaml |
7 | 8 | from typing import Any, Dict, List, MutableSequence, Optional, Sequence, Text, Tuple, Type, Union |
8 | 9 | from cwltool.expression import do_eval |
9 | 10 | from cwltool.errors import WorkflowException |
10 | 11 | from schema_salad.sourceline import SourceLine |
| 12 | +from schema_salad.utils import json_dumps |
11 | 13 |
|
12 | 14 | SKIP_COMMAND_LINE = True # don't process CommandLineTool.inputs...inputBinding and CommandLineTool.arguments sections |
13 | 15 | SKIP_COMMAND_LINE2 = True # don't process CommandLineTool.outputEval |
@@ -37,6 +39,24 @@ def main(): |
37 | 39 | yaml.round_trip_dump(result_json, sys.stdout) |
38 | 40 |
|
39 | 41 |
|
| 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 | + |
40 | 60 | def escape_expression_field(contents: str) -> str: |
41 | 61 | return contents.replace('${', '$/{').replace('$(', '$/(') |
42 | 62 |
|
@@ -109,6 +129,7 @@ def etool_to_cltool(etool: cwl.ExpressionTool, expressionLib: Optional[List[str] |
109 | 129 |
|
110 | 130 | 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]: |
111 | 131 | if not inside and isinstance(process, cwl.CommandLineTool): |
| 132 | + process = expand_stream_shortcuts(process) |
112 | 133 | wf_inputs = [] |
113 | 134 | wf_outputs = [] |
114 | 135 | step_inputs = [] |
@@ -260,7 +281,7 @@ def example_input(some_type: Any) -> Any: |
260 | 281 | if some_type == 'Directory': |
261 | 282 | return {'class': 'Directory', 'basename': 'example', 'listing': []} |
262 | 283 | if some_type == 'File': |
263 | | - return {'class': 'File', 'basename': 'example'} |
| 284 | + return {'class': 'File', 'basename': 'example.txt', 'nameroot': 'example', 'nameext': 'txt'} |
264 | 285 | return None |
265 | 286 |
|
266 | 287 | def type_for_source(process: cwl.Process, sourcenames: Union[str, List[str]], parent: Optional[cwl.Workflow] = None) -> Any: |
|
0 commit comments