From 4bb5329997cb84562a40733b5c2f55600b1a741a Mon Sep 17 00:00:00 2001 From: Francis Charette-Migneault Date: Mon, 9 Sep 2024 12:49:51 -0400 Subject: [PATCH] fix `loadContents` for `File[]` (#2036) --- .gitignore | 3 ++- cwltool/builder.py | 4 ++-- tests/load_contents-1.txt | 1 + tests/load_contents-2.txt | 1 + tests/load_contents-array.cwl | 24 ++++++++++++++++++++++++ tests/load_contents-array.yml | 5 +++++ tests/test_load_contents.py | 22 ++++++++++++++++++++++ 7 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 tests/load_contents-1.txt create mode 100644 tests/load_contents-2.txt create mode 100644 tests/load_contents-array.cwl create mode 100644 tests/load_contents-array.yml create mode 100644 tests/test_load_contents.py diff --git a/.gitignore b/.gitignore index 5941627f8..fbe4b24fc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ # Generated during tests pytestdebug.log tmp/ +*.sif +involucro # Python temps __pycache__/ @@ -59,4 +61,3 @@ cwltool/_version.py cwltool_deps docs/_build/ docs/autoapi/ - diff --git a/cwltool/builder.py b/cwltool/builder.py index ff1c099e5..2ba1e6543 100644 --- a/cwltool/builder.py +++ b/cwltool/builder.py @@ -282,7 +282,7 @@ def bind_input( and "itemSeparator" not in binding ): st["inputBinding"] = {} - for k in ("secondaryFiles", "format", "streamable"): + for k in ("secondaryFiles", "format", "streamable", "loadContents"): if k in schema: st[k] = schema[k] if value_from_expression: @@ -349,7 +349,7 @@ def bind_input( "type": schema["items"], "inputBinding": b2, } - for k in ("secondaryFiles", "format", "streamable"): + for k in ("secondaryFiles", "format", "streamable", "loadContents"): if k in schema: itemschema[k] = schema[k] bindings.extend( diff --git a/tests/load_contents-1.txt b/tests/load_contents-1.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/tests/load_contents-1.txt @@ -0,0 +1 @@ +1 diff --git a/tests/load_contents-2.txt b/tests/load_contents-2.txt new file mode 100644 index 000000000..0cfbf0888 --- /dev/null +++ b/tests/load_contents-2.txt @@ -0,0 +1 @@ +2 diff --git a/tests/load_contents-array.cwl b/tests/load_contents-array.cwl new file mode 100644 index 000000000..f6b786ec6 --- /dev/null +++ b/tests/load_contents-array.cwl @@ -0,0 +1,24 @@ +cwlVersion: "v1.2" +class: CommandLineTool +baseCommand: echo +requirements: + InlineJavascriptRequirement: {} +inputs: + files: + type: + type: array + items: File + loadContents: true + inputBinding: + valueFrom: | + ${ + return JSON.stringify({ + "data": inputs.files.map(item => parseInt(item.contents)) + }); + } +outputs: + out: + type: File + outputBinding: + glob: "data.json" +stdout: "data.json" diff --git a/tests/load_contents-array.yml b/tests/load_contents-array.yml new file mode 100644 index 000000000..b7a919340 --- /dev/null +++ b/tests/load_contents-array.yml @@ -0,0 +1,5 @@ +files: + - class: File + path: load_contents-1.txt + - class: File + path: load_contents-2.txt diff --git a/tests/test_load_contents.py b/tests/test_load_contents.py new file mode 100644 index 000000000..36e9da2ab --- /dev/null +++ b/tests/test_load_contents.py @@ -0,0 +1,22 @@ +"""Test the loadContents feature.""" + +import json +from pathlib import Path + +from cwltool.main import main + +from .util import get_data + + +def test_load_contents_file_array(tmp_path: Path) -> None: + """Ensures that a File[] input with loadContents loads each file.""" + params = [ + "--outdir", + str(tmp_path), + get_data("tests/load_contents-array.cwl"), + str(Path(__file__) / "../load_contents-array.yml"), + ] + assert main(params) == 0 + with open(tmp_path / "data.json") as out_fd: + data = json.load(out_fd) + assert data == {"data": [1, 2]}