From 676ee0619edf5e8d5ec7f4e7324fabf1d4cd64d8 Mon Sep 17 00:00:00 2001 From: Francis Charette Migneault Date: Mon, 26 Aug 2024 17:50:20 -0400 Subject: [PATCH 1/5] fix loadContents for File[] --- 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 +++++ 5 files changed, 33 insertions(+), 2 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 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 From c8318c022378123018edf45d3c0eae3e9985ef23 Mon Sep 17 00:00:00 2001 From: Francis Charette Migneault Date: Tue, 27 Aug 2024 12:40:28 -0400 Subject: [PATCH 2/5] add pytest for loadContents File[] --- .gitignore | 3 ++- tests/test_load_contents.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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/tests/test_load_contents.py b/tests/test_load_contents.py new file mode 100644 index 000000000..fbbeb88fc --- /dev/null +++ b/tests/test_load_contents.py @@ -0,0 +1,20 @@ +"""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"), + "tests/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]} From fd127eec246594121c01b1d0fbb43b92369258b8 Mon Sep 17 00:00:00 2001 From: Francis Charette Migneault Date: Tue, 27 Aug 2024 13:53:55 -0400 Subject: [PATCH 3/5] fix lint --- tests/test_load_contents.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_load_contents.py b/tests/test_load_contents.py index fbbeb88fc..33050a2f7 100644 --- a/tests/test_load_contents.py +++ b/tests/test_load_contents.py @@ -1,4 +1,5 @@ """Test the loadContents feature.""" + import json from pathlib import Path @@ -10,7 +11,8 @@ 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), + "--outdir", + str(tmp_path), get_data("tests/load_contents-array.cwl"), "tests/load_contents-array.yml", ] From 62e584a8032d68a22ca8ab1de844b58c831912c2 Mon Sep 17 00:00:00 2001 From: Francis Charette Migneault Date: Tue, 27 Aug 2024 16:55:46 -0400 Subject: [PATCH 4/5] use absolute path in test to avoid invalid resolution --- tests/test_load_contents.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_load_contents.py b/tests/test_load_contents.py index 33050a2f7..0f1fa9b59 100644 --- a/tests/test_load_contents.py +++ b/tests/test_load_contents.py @@ -1,4 +1,5 @@ """Test the loadContents feature.""" +import os.path import json from pathlib import Path @@ -14,7 +15,7 @@ def test_load_contents_file_array(tmp_path: Path) -> None: "--outdir", str(tmp_path), get_data("tests/load_contents-array.cwl"), - "tests/load_contents-array.yml", + str(Path(__file__) / "../load_contents-array.yml"), ] assert main(params) == 0 with open(tmp_path / "data.json") as out_fd: From a492285aff6d3f3e70449849875ec5d790655545 Mon Sep 17 00:00:00 2001 From: Francis Charette Migneault Date: Tue, 27 Aug 2024 17:12:36 -0400 Subject: [PATCH 5/5] fix lint --- tests/test_load_contents.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_load_contents.py b/tests/test_load_contents.py index 0f1fa9b59..36e9da2ab 100644 --- a/tests/test_load_contents.py +++ b/tests/test_load_contents.py @@ -1,5 +1,4 @@ """Test the loadContents feature.""" -import os.path import json from pathlib import Path