Skip to content

Commit b3edc09

Browse files
Iacopo ColonnelliGlassOfWhiskey
Iacopo Colonnelli
authored and
GlassOfWhiskey
committed
Updated outputMethod values
1 parent 4bb5329 commit b3edc09

29 files changed

+65
-55
lines changed

cwltool/checker.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,13 @@ def is_conditional_step(param_to_step: Dict[str, CWLObjectType], parm_id: str) -
517517

518518

519519
def is_all_output_method_loop_step(param_to_step: Dict[str, CWLObjectType], parm_id: str) -> bool:
520-
"""Check if a step contains a `loop` directive with `all` outputMethod."""
520+
"""Check if a step contains a `loop` directive with `all_iterations` outputMethod."""
521521
source_step: Optional[MutableMapping[str, Any]] = param_to_step.get(parm_id)
522522
if source_step is not None:
523-
if source_step.get("loop") is not None and source_step.get("outputMethod") == "all":
523+
if (
524+
source_step.get("loop") is not None
525+
and source_step.get("outputMethod") == "all_iterations"
526+
):
524527
return True
525528
return False
526529

cwltool/errors.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88

99
# flake8: noqa: F401
1010

11-
from cwl_utils.errors import WorkflowException as WorkflowException
12-
13-
1411
from cwl_utils.errors import GraphTargetMissingException as GraphTargetMissingException
12+
from cwl_utils.errors import WorkflowException as WorkflowException
1513

1614

1715
class UnsupportedRequirement(WorkflowException):

cwltool/schemas/v1.3.0-dev1/Workflow.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,8 @@ $graph:
497497
docParent: "#LoopWorkflowStep"
498498
doc: The loop output method, as described in [workflow step loop](#LoopWorkflowStep).
499499
symbols:
500-
- last
501-
- all
500+
- last_iteration
501+
- all_iterations
502502

503503

504504
- name: AbstractWorkflowStep
@@ -705,14 +705,14 @@ $graph:
705705
The `outputMethod` field describes how to deal with loop outputs after
706706
termination:
707707
708-
* **last** specifies that only the last computed element for each output
709-
parameter should be propagated to the subsequent steps. This is the
710-
default value.
708+
* **last_iteration** specifies that only the last computed element for
709+
each output parameter should be propagated to the subsequent steps.
710+
This is the default value.
711711
712-
* **all** specifies that an array with all output values computed at the
713-
end of each loop iteration should be propagated to the subsequent steps.
714-
Elements in the array must be ordered according to the loop iterations
715-
that produced them.
712+
* **all_iterations** specifies that an array with all output values
713+
computed at the end of each loop iteration should be propagated to
714+
the subsequent steps. Elements in the array must be ordered according
715+
to the loop iterations that produced them.
716716
717717
Iterative execution in CWL is an optional feature and is not required
718718
to be implemented by all consumers of CWL documents. An implementation that
@@ -734,9 +734,9 @@ $graph:
734734
mapPredicate: outputSource
735735
- name: outputMethod
736736
doc: |
737-
If not specified, the default method is "last".
737+
If not specified, the default method is "last_iteration".
738738
type: LoopOutputMethod?
739-
default: last
739+
default: last_iteration
740740
jsonldPredicate:
741741
"_id": "cwl:outputMethod"
742742
"_type": "@vocab"
@@ -748,7 +748,8 @@ $graph:
748748
Only run the next iteration when the expression evaluates to `true`.
749749
If the first iteration evaluates to `false` the step is skipped.
750750
A skipped step produces a `null` on each output if the `outputMethod`
751-
is set to `last`, and an empty array if the `outputMethod` is set to `all`.
751+
is set to `last_iteration`, and an empty array if the `outputMethod`
752+
is set to `all_iterations`.
752753
753754
754755
- name: Workflow

cwltool/update.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
cast,
1212
)
1313

14+
from ruamel.yaml.comments import CommentedMap, CommentedSeq
1415
from schema_salad.exceptions import ValidationException
1516
from schema_salad.ref_resolver import Loader
1617
from schema_salad.sourceline import SourceLine
1718

18-
from ruamel.yaml.comments import CommentedMap, CommentedSeq
19-
2019
from .loghandler import _logger
2120
from .utils import CWLObjectType, CWLOutputType, aslist, visit_class, visit_field
2221

@@ -51,7 +50,16 @@ def rewrite_loop_requirements(t: CWLObjectType) -> None:
5150
el["outputSource"] = source
5251
s["loop"] = r["loop"]
5352
if "outputMethod" in r:
54-
s["outputMethod"] = r["outputMethod"]
53+
if r["outputMethod"] == "all":
54+
s["outputMethod"] = "all_iterations"
55+
elif r["outputMethod"] == "last":
56+
s["outputMethod"] = "last_iteration"
57+
else:
58+
raise SourceLine(
59+
r, raise_type=ValidationException
60+
).makeError( # pragma: no cover
61+
f"Invalid value {r['outputMethod']} for `outputMethod`."
62+
)
5563
cast(
5664
MutableSequence[CWLObjectType],
5765
s["requirements"],

cwltool/workflow_job.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ def valueFromFunc(k: str, v: Optional[CWLOutputType]) -> Optional[CWLOutputType]
744744
_logger.info("[%s] will be skipped", step.name)
745745
if (
746746
step.tool.get("loop") is not None
747-
and step.tool.get("outputMethod", "last") == "all"
747+
and step.tool.get("outputMethod", "last_iteration") == "all_iterations"
748748
):
749749
callback({k["id"]: [] for k in outputparms}, "skipped")
750750
else:
@@ -874,7 +874,7 @@ def _set_empty_output(self, outputMethod: str) -> None:
874874
for i in self.step.tool["outputs"]:
875875
if "id" in i:
876876
iid = cast(str, i["id"])
877-
if outputMethod == "all":
877+
if outputMethod == "all_iterations":
878878
self.output_buffer[iid] = cast(MutableSequence[Optional[CWLOutputType]], [])
879879
else:
880880
self.output_buffer[iid] = None
@@ -887,7 +887,7 @@ def job(
887887
) -> JobsGeneratorType:
888888
"""Generate a WorkflowJobStep job until the `when` condition evaluates to False."""
889889
self.joborder = joborder
890-
outputMethod = self.step.tool.get("outputMethod", "last")
890+
outputMethod = self.step.tool.get("outputMethod", "last_iteration")
891891

892892
callback = functools.partial(
893893
self.loop_callback,
@@ -953,14 +953,14 @@ def loop_callback(
953953
self.iteration += 1
954954
try:
955955
loop = cast(MutableSequence[CWLObjectType], self.step.tool.get("loop", []))
956-
outputMethod = self.step.tool.get("outputMethod", "last")
956+
outputMethod = self.step.tool.get("outputMethod", "last_iteration")
957957
state: Dict[str, Optional[WorkflowStateItem]] = {}
958958
for i in self.step.tool["outputs"]:
959959
if "id" in i:
960960
iid = cast(str, i["id"])
961961
if iid in jobout:
962962
state[iid] = WorkflowStateItem(i, jobout[iid], processStatus)
963-
if outputMethod == "all":
963+
if outputMethod == "all_iterations":
964964
if iid not in self.output_buffer:
965965
self.output_buffer[iid] = cast(
966966
MutableSequence[Optional[CWLOutputType]], []

tests/loop/all-output-loop-no-iteration.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ steps:
2525
when: $(inputs.i1 < 1)
2626
loop:
2727
i1: o1
28-
outputMethod: all
28+
outputMethod: all_iterations

tests/loop/all-output-loop.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ steps:
2525
when: $(inputs.i1 < 10)
2626
loop:
2727
i1: o1
28-
outputMethod: all
28+
outputMethod: all_iterations

tests/loop/default-value-loop.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ steps:
4444
i1:
4545
outputSource: o1
4646
default: 5
47-
outputMethod: all
47+
outputMethod: all_iterations

tests/loop/invalid-loop-scatter.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ steps:
2626
when: $(inputs.i1 < 10)
2727
loop:
2828
i1: o1
29-
outputMethod: last
29+
outputMethod: last_iteration
3030
in:
3131
i1: i1
3232
i2: i2

tests/loop/invalid-loop-when-exception.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ steps:
2929
}
3030
loop:
3131
i1: o1
32-
outputMethod: last
32+
outputMethod: last_iteration
3333
in:
3434
i1: i1
3535
i2: i2

tests/loop/invalid-loop-when-exception2.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ steps:
3333
}
3434
loop:
3535
i1: o1
36-
outputMethod: last
36+
outputMethod: last_iteration
3737
in:
3838
i1: i1
3939
i2: i2

tests/loop/invalid-multi-source-loop-no-requirement.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ steps:
6161
i1:
6262
loopSource: [osmall, obig]
6363
pickValue: the_only_non_null
64-
outputMethod: all
64+
outputMethod: all_iterations

tests/loop/invalid-no-loopWhen.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ steps:
2525
${return {'o1': inputs.i1 + inputs.i2};}
2626
loop:
2727
i1: o1
28-
outputMethod: last
28+
outputMethod: last_iteration
2929
in:
3030
i1: i1
3131
i2: i2

tests/loop/invalid-non-boolean-loopWhen.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ steps:
2626
when: $(inputs.i1)
2727
loop:
2828
i1: o1
29-
outputMethod: last
29+
outputMethod: last_iteration
3030
in:
3131
i1: i1
3232
i2: i2

tests/loop/invalid-non-boolean-loopWhen2.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ steps:
2626
when: '$(inputs.i1 == 1 ? true : "I am a string")'
2727
loop:
2828
i1: o1
29-
outputMethod: last
29+
outputMethod: last_iteration
3030
in:
3131
i1: i1
3232
i2: i2

tests/loop/invalid-value-from-loop-no-requirement.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ steps:
2929
loop:
3030
i1:
3131
valueFrom: $(inputs.i1 + 1)
32-
outputMethod: last
32+
outputMethod: last_iteration

tests/loop/loop-inside-loop-all.cwl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ steps:
4646
when: $(inputs.i1 <= inputs.i2)
4747
loop:
4848
i1: o1
49-
outputMethod: all
49+
outputMethod: all_iterations
5050
in:
5151
i1: i1
5252
i2: i2
@@ -55,4 +55,4 @@ steps:
5555
loop:
5656
i2:
5757
valueFrom: $(inputs.i2 + 1)
58-
outputMethod: all
58+
outputMethod: all_iterations

tests/loop/loop-inside-loop.cwl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ steps:
4242
when: $(inputs.i1 <= inputs.i2)
4343
loop:
4444
i1: o1
45-
outputMethod: last
45+
outputMethod: last_iteration
4646
in:
4747
i1: i1
4848
i2: i2
@@ -51,4 +51,4 @@ steps:
5151
loop:
5252
i2:
5353
valueFrom: $(inputs.i2 + 1)
54-
outputMethod: all
54+
outputMethod: all_iterations

tests/loop/loop-inside-scatter.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ steps:
4141
when: $(inputs.i1 < 10)
4242
loop:
4343
i1: o1
44-
outputMethod: last
44+
outputMethod: last_iteration
4545
in:
4646
i1: i1
4747
i2: i2

tests/loop/multi-source-loop.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ steps:
6262
i1:
6363
outputSource: [osmall, obig]
6464
pickValue: the_only_non_null
65-
outputMethod: all
65+
outputMethod: all_iterations

tests/loop/opt-var-loop.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ steps:
2727
when: $(inputs.i1 < 10)
2828
loop:
2929
i1: o1
30-
outputMethod: last
30+
outputMethod: last_iteration

tests/loop/scatter-inside-loop.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ steps:
4646
when: $(inputs.i1[0] < 10)
4747
loop:
4848
i1: o1
49-
outputMethod: last
49+
outputMethod: last_iteration

tests/loop/single-var-loop-no-iteration.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ steps:
2626
when: $(inputs.i1 < 1)
2727
loop:
2828
i1: o1
29-
outputMethod: last
29+
outputMethod: last_iteration

tests/loop/single-var-loop.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ steps:
2626
when: $(inputs.i1 < 10)
2727
loop:
2828
i1: o1
29-
outputMethod: last
29+
outputMethod: last_iteration

tests/loop/two-vars-loop-2.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ steps:
2828
when: $(inputs.i1 < 10)
2929
loop:
3030
i1: o1
31-
outputMethod: last
31+
outputMethod: last_iteration

tests/loop/two-vars-loop.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ steps:
3030
loop:
3131
i1: o1
3232
i2: o2
33-
outputMethod: last
33+
outputMethod: last_iteration

tests/loop/value-from-loop.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ steps:
3030
loop:
3131
i1:
3232
valueFrom: $(inputs.i1 + 1)
33-
outputMethod: last
33+
outputMethod: last_iteration

tests/test_loop.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def test_loop_two_variables_single_backpropagation() -> None:
143143

144144

145145
def test_loop_with_all_output_method() -> None:
146-
"""Test a loop case with outputMethod set to all."""
146+
"""Test a loop case with outputMethod set to all_iterations."""
147147
stream = StringIO()
148148
params = [
149149
"--enable-dev",
@@ -156,7 +156,7 @@ def test_loop_with_all_output_method() -> None:
156156

157157

158158
def test_loop_with_all_output_method_no_iteration() -> None:
159-
"""Test a loop case with outputMethod set to all and a false 'when' condition."""
159+
"""Test a loop case with outputMethod set to all_iterations and a false 'when' condition."""
160160
stream = StringIO()
161161
params = [
162162
"--enable-dev",
@@ -244,7 +244,7 @@ def test_nested_loops() -> None:
244244

245245

246246
def test_nested_loops_all() -> None:
247-
"""Test a workflow with two nested loops, both with outputMethod set to all."""
247+
"""Test a workflow with two nested loops, both with outputMethod set to all_iterations."""
248248
stream = StringIO()
249249
params = [
250250
"--enable-dev",

tests/test_path_checks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
from ruamel.yaml.comments import CommentedMap
88
from schema_salad.sourceline import cmap
99

10+
from cwltool.builder import content_limit_respected_read
1011
from cwltool.command_line_tool import CommandLineTool
1112
from cwltool.context import LoadingContext, RuntimeContext
13+
from cwltool.errors import WorkflowException
1214
from cwltool.main import main
1315
from cwltool.stdfsaccess import StdFsAccess
1416
from cwltool.update import INTERNAL_VERSION
15-
from cwltool.utils import CWLObjectType, CONTENT_LIMIT, bytes2str_in_dicts
16-
from cwltool.builder import content_limit_respected_read
17-
from cwltool.errors import WorkflowException
17+
from cwltool.utils import CONTENT_LIMIT, CWLObjectType, bytes2str_in_dicts
1818

1919
from .util import needs_docker
2020

0 commit comments

Comments
 (0)