Skip to content

Commit

Permalink
recursively insert output format
Browse files Browse the repository at this point in the history
  • Loading branch information
jfennick authored and Vasu Jaganath committed Jul 9, 2024
1 parent 46e0405 commit 6f313a5
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cwltool/command_line_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -1495,8 +1495,19 @@ 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 inserts a value into any dictionaries"""
if isinstance(j_dict, List):
return [recursively_insert(x, key, val) for x in j_dict]
if isinstance(j_dict, Dict):
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
17 changes: 17 additions & 0 deletions tests/test_2D.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import subprocess
import sys

from .util import get_data


def test_output_2D_file_format() -> None:
"""Test format tag for 2D output arrays."""

params = [
sys.executable,
"-m",
"cwltool",
get_data("tests/output_2D_file_format.cwl"),
]

assert subprocess.check_call(params) == 0

0 comments on commit 6f313a5

Please sign in to comment.