Skip to content

Commit c21ae6e

Browse files
Stopped Loop requirement propagation
1 parent a7c77ed commit c21ae6e

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

cwltool/workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def __init__(
218218
if parent_req["class"] == step_req["class"]:
219219
found_in_step = True
220220
break
221-
if not found_in_step:
221+
if not found_in_step and parent_req.get('class') != 'http://commonwl.org/cwltool#Loop':
222222
loadingContext.requirements.append(parent_req)
223223
loadingContext.requirements.extend(
224224
cast(

tests/loop/multi-source-loop.cwl

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env cwl-runner
2+
cwlVersion: v1.2
3+
class: Workflow
4+
$namespaces:
5+
cwltool: "http://commonwl.org/cwltool#"
6+
requirements:
7+
InlineJavascriptRequirement: {}
8+
ScatterFeatureRequirement: {}
9+
SubworkflowFeatureRequirement: {}
10+
inputs:
11+
i1: int
12+
outputs:
13+
o1:
14+
type: int[]
15+
outputSource: [loop/osmall, loop/obig]
16+
linkMerge: merge_flattened
17+
pickValue: all_non_null
18+
steps:
19+
loop:
20+
run:
21+
class: Workflow
22+
inputs:
23+
i1: int
24+
outputs:
25+
osmall:
26+
type: int?
27+
outputSource: small_values/o1
28+
obig:
29+
type: int?
30+
outputSource: big_values/o1
31+
steps:
32+
small_values:
33+
when: $(inputs.i1 < 5)
34+
run:
35+
class: ExpressionTool
36+
inputs:
37+
i1: int
38+
outputs:
39+
o1: int
40+
expression: >
41+
${return {'o1': inputs.i1 + 1};}
42+
in:
43+
i1: i1
44+
out: [o1]
45+
big_values:
46+
when: $(inputs.i1 >= 5)
47+
run:
48+
class: ExpressionTool
49+
inputs:
50+
i1: int
51+
outputs:
52+
o1: int
53+
expression: >
54+
${return {'o1': inputs.i1 + 3};}
55+
in:
56+
i1: i1
57+
out: [ o1 ]
58+
in:
59+
i1: i1
60+
out: [osmall, obig]
61+
requirements:
62+
cwltool:Loop:
63+
loop_when: $(inputs.i1 < 20)
64+
loop:
65+
i1:
66+
loop_source: [osmall, obig]
67+
pickValue: the_only_non_null
68+
outputMethod: all

tests/test_loop.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,18 @@ def test_nested_loops_all() -> None:
154154
]
155155
main(params, stdout=stream)
156156
expected = {'o1': [[2], [2, 3], [2, 3, 4]]}
157-
assert json.loads(stream.getvalue()) == expected
157+
assert json.loads(stream.getvalue()) == expected
158+
159+
160+
def test_multi_source_loop_input() -> None:
161+
"""Test a loop with two sources, which are selected through a pickValue directive."""
162+
stream = StringIO()
163+
params = [
164+
"--enable-ext",
165+
"--validate",
166+
get_data("tests/loop/multi-source-loop.cwl"),
167+
get_data("tests/loop/single-var-loop-job.yml")
168+
]
169+
main(params, stdout=stream)
170+
expected = {'o1': [2, 3, 4, 5, 8, 11, 14, 17, 20]}
171+
assert json.loads(stream.getvalue()) == expected

0 commit comments

Comments
 (0)