Skip to content

Commit fb7aa41

Browse files
committed
single-process: handle step-level req collisions
1 parent 0c39dcc commit fb7aa41

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

Diff for: cwltool/workflow.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,19 @@ def __init__(
207207

208208
loadingContext = loadingContext.copy()
209209

210+
parent_requirements = copy.deepcopy(getdefault(loadingContext.requirements, []))
210211
loadingContext.requirements = copy.deepcopy(
211-
getdefault(loadingContext.requirements, [])
212+
toolpath_object.get("requirements", [])
212213
)
213214
assert loadingContext.requirements is not None # nosec
214-
loadingContext.requirements.extend(toolpath_object.get("requirements", []))
215+
for parent_req in parent_requirements:
216+
found_in_step = False
217+
for step_req in loadingContext.requirements:
218+
if parent_req["class"] == step_req["class"]:
219+
found_in_step = True
220+
break
221+
if not found_in_step:
222+
loadingContext.requirements.append(parent_req)
215223
loadingContext.requirements.extend(
216224
cast(
217225
List[CWLObjectType],

Diff for: tests/subgraph/steplevel-resreq.cwl

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env cwl-runner
2+
class: Workflow
3+
cwlVersion: v1.2
4+
5+
requirements:
6+
ResourceRequirement:
7+
coresMin: 4
8+
coresMax: 4
9+
10+
inputs: []
11+
12+
steps:
13+
step1:
14+
requirements:
15+
ResourceRequirement:
16+
coresMin: 1
17+
coresMax: 1
18+
run:
19+
class: CommandLineTool
20+
inputs: []
21+
outputs:
22+
output:
23+
type: stdout
24+
baseCommand: echo
25+
stdout: cores.txt
26+
arguments: [ $(runtime.cores) ]
27+
in: []
28+
out: [output]
29+
30+
outputs:
31+
out:
32+
type: File
33+
outputSource: step1/output

Diff for: tests/test_subgraph.py

+16
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,22 @@ def test_single_process_inherit_reqs_collision() -> None:
140140
)
141141

142142

143+
def test_single_process_inherit_reqs_step_collision() -> None:
144+
"""Inherit reqs and hints --single-process reqs collision."""
145+
err_code, stdout, stderr = get_main_output(
146+
[
147+
"--single-process",
148+
"step1",
149+
get_data("tests/subgraph/steplevel-resreq.cwl"),
150+
]
151+
)
152+
assert err_code == 0
153+
assert (
154+
json.loads(stdout)["output"]["checksum"]
155+
== "sha1$e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e"
156+
)
157+
158+
143159
def test_single_process_inherit_reqs_hints_collision() -> None:
144160
"""Inherit reqs and hints --single-process reqs + hints collision."""
145161
err_code, stdout, stderr = get_main_output(

0 commit comments

Comments
 (0)