Skip to content

Commit f201b2a

Browse files
jfennickVasu Jaganath
authored and
Vasu Jaganath
committed
recursively insert output format
1 parent ca7f768 commit f201b2a

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

cwltool/command_line_tool.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -1495,8 +1495,19 @@ def collect_output(
14951495
)
14961496
primary["format"] = format_eval
14971497
else:
1498-
for primary in aslist(result):
1499-
primary["format"] = format_field
1498+
1499+
def recursively_insert(j_dict: Any, key: Any, val: Any) -> Any:
1500+
"""Recursively inserts a value into any dictionaries"""
1501+
if isinstance(j_dict, List):
1502+
return [recursively_insert(x, key, val) for x in j_dict]
1503+
if isinstance(j_dict, Dict):
1504+
if j_dict.get("class") == "File":
1505+
j_dict[key] = val
1506+
else:
1507+
return {x: recursively_insert(y, key, val) for x, y in j_dict.items()}
1508+
return j_dict
1509+
1510+
result = recursively_insert(result, "format", format_field)
15001511
# Ensure files point to local references outside of the run environment
15011512
adjustFileObjs(result, revmap)
15021513

tests/output_2D_file_format.cwl

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env cwl-runner
2+
cwlVersion: v1.0
3+
4+
class: CommandLineTool
5+
6+
baseCommand: 'true'
7+
8+
requirements:
9+
InlineJavascriptRequirement: {}
10+
11+
inputs: {}
12+
13+
outputs:
14+
output_array:
15+
type: {"type": "array", "items": {"type": "array", "items": "File"}}
16+
outputBinding:
17+
outputEval: |
18+
${
19+
var out2d = [];
20+
for (var i = 0; i < 2; i++) {
21+
var out1d = [];
22+
for (var j = 0; j < 2; j++) {
23+
out1d.push({"class": "File", "location": "../../filename.txt"});
24+
}
25+
out2d.push(out1d);
26+
}
27+
return out2d;
28+
}
29+
format: some_format

tests/test_2D.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import subprocess
2+
import sys
3+
4+
from .util import get_data
5+
6+
7+
def test_output_2D_file_format() -> None:
8+
"""Test format tag for 2D output arrays."""
9+
10+
params = [
11+
sys.executable,
12+
"-m",
13+
"cwltool",
14+
get_data("tests/output_2D_file_format.cwl"),
15+
]
16+
17+
assert subprocess.check_call(params) == 0

0 commit comments

Comments
 (0)