Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions cwltool/command_line_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -1495,8 +1495,21 @@ def collect_output(
)
primary["format"] = format_eval
else:
for primary in aslist(result):
primary["format"] = format_field

def recursively_insert(j_dict: Any, key: Any, val: Any) -> Any:
"""Recursively insert a value into any dictionary."""
if isinstance(j_dict, MutableSequence):
return [recursively_insert(x, key, val) for x in j_dict]
if isinstance(j_dict, MutableMapping):
if j_dict.get("class") == "File":
j_dict[key] = val
else:
return {
x: recursively_insert(y, key, val) for x, y in j_dict.items()
}
return j_dict

result = recursively_insert(result, "format", format_field)
# Ensure files point to local references outside of the run environment
adjustFileObjs(result, revmap)

Expand Down
29 changes: 29 additions & 0 deletions tests/output_2D_file_format.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env cwl-runner
cwlVersion: v1.0

class: CommandLineTool

baseCommand: 'true'

requirements:
InlineJavascriptRequirement: {}

inputs: {}

outputs:
output_array:
type: {"type": "array", "items": {"type": "array", "items": "File"}}
outputBinding:
outputEval: |
${
var out2d = [];
for (var i = 0; i < 2; i++) {
var out1d = [];
for (var j = 0; j < 2; j++) {
out1d.push({"class": "File", "location": "../../filename.txt"});
}
out2d.push(out1d);
}
return out2d;
}
format: some_format
21 changes: 21 additions & 0 deletions tests/test_2D.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from pathlib import Path

from .util import get_data, get_main_output


def test_output_2d_file_format(tmp_path: Path) -> None:
"""A simple test for format tag fix for 2D output arrays."""

# still need to create 'filename.txt' as it is needed in output_2D_file_format.cwl
(tmp_path / "filename.txt").touch()
commands = [
"--cachedir",
str(tmp_path / "foo"), # just so that the relative path of file works out
"--outdir",
str(tmp_path / "out"),
get_data("tests/output_2D_file_format.cwl"),
]

error_code, _, stderr = get_main_output(commands)

assert error_code == 0, stderr