Skip to content

Commit 4bb5329

Browse files
authored
fix loadContents for File[] (#2036)
1 parent 4046c49 commit 4bb5329

7 files changed

+57
-3
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Generated during tests
22
pytestdebug.log
33
tmp/
4+
*.sif
5+
involucro
46

57
# Python temps
68
__pycache__/
@@ -59,4 +61,3 @@ cwltool/_version.py
5961
cwltool_deps
6062
docs/_build/
6163
docs/autoapi/
62-

cwltool/builder.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def bind_input(
282282
and "itemSeparator" not in binding
283283
):
284284
st["inputBinding"] = {}
285-
for k in ("secondaryFiles", "format", "streamable"):
285+
for k in ("secondaryFiles", "format", "streamable", "loadContents"):
286286
if k in schema:
287287
st[k] = schema[k]
288288
if value_from_expression:
@@ -349,7 +349,7 @@ def bind_input(
349349
"type": schema["items"],
350350
"inputBinding": b2,
351351
}
352-
for k in ("secondaryFiles", "format", "streamable"):
352+
for k in ("secondaryFiles", "format", "streamable", "loadContents"):
353353
if k in schema:
354354
itemschema[k] = schema[k]
355355
bindings.extend(

tests/load_contents-1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

tests/load_contents-2.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2

tests/load_contents-array.cwl

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
cwlVersion: "v1.2"
2+
class: CommandLineTool
3+
baseCommand: echo
4+
requirements:
5+
InlineJavascriptRequirement: {}
6+
inputs:
7+
files:
8+
type:
9+
type: array
10+
items: File
11+
loadContents: true
12+
inputBinding:
13+
valueFrom: |
14+
${
15+
return JSON.stringify({
16+
"data": inputs.files.map(item => parseInt(item.contents))
17+
});
18+
}
19+
outputs:
20+
out:
21+
type: File
22+
outputBinding:
23+
glob: "data.json"
24+
stdout: "data.json"

tests/load_contents-array.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
files:
2+
- class: File
3+
path: load_contents-1.txt
4+
- class: File
5+
path: load_contents-2.txt

tests/test_load_contents.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""Test the loadContents feature."""
2+
3+
import json
4+
from pathlib import Path
5+
6+
from cwltool.main import main
7+
8+
from .util import get_data
9+
10+
11+
def test_load_contents_file_array(tmp_path: Path) -> None:
12+
"""Ensures that a File[] input with loadContents loads each file."""
13+
params = [
14+
"--outdir",
15+
str(tmp_path),
16+
get_data("tests/load_contents-array.cwl"),
17+
str(Path(__file__) / "../load_contents-array.yml"),
18+
]
19+
assert main(params) == 0
20+
with open(tmp_path / "data.json") as out_fd:
21+
data = json.load(out_fd)
22+
assert data == {"data": [1, 2]}

0 commit comments

Comments
 (0)