Skip to content

Commit 7ab72e4

Browse files
author
Peter Amstutz
committed
Refactor requirements checking. Add visitor pattern for walking over workflows.
1 parent 5c10f5f commit 7ab72e4

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

cwltool/process.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"MultipleInputFeatureRequirement",
3737
"InlineJavascriptRequirement",
3838
"ShellCommandRequirement",
39-
"StepInputExpressionRequirement"]
39+
"StepInputExpressionRequirement",
40+
"ResourceRequirement"]
4041

4142
cwl_files = ("Workflow.yml",
4243
"CommandLineTool.yml",
@@ -114,15 +115,15 @@ def open(self, fn, mode):
114115
def exists(self, fn):
115116
return os.path.exists(self._abs(fn))
116117

118+
class UnsupportedRequirement(Exception):
119+
pass
120+
117121
def checkRequirements(rec, supportedProcessRequirements):
118122
if isinstance(rec, dict):
119123
if "requirements" in rec:
120124
for r in rec["requirements"]:
121125
if r["class"] not in supportedProcessRequirements:
122-
raise Exception("Unsupported requirement %s" % r["class"])
123-
if "scatter" in rec:
124-
if isinstance(rec["scatter"], list) and rec["scatter"] > 1:
125-
raise Exception("Unsupported complex scatter type '%s'" % rec.get("scatterMethod"))
126+
raise UnsupportedRequirement("Unsupported requirement %s" % r["class"])
126127
for d in rec:
127128
checkRequirements(rec[d], supportedProcessRequirements)
128129
if isinstance(rec, list):
@@ -211,6 +212,7 @@ def __init__(self, toolpath_object, **kwargs):
211212
else:
212213
self.formatgraph = None
213214

215+
checkRequirements(self.tool, supportedProcessRequirements)
214216
self.validate_hints(self.tool.get("hints", []), strict=kwargs.get("strict"))
215217

216218
self.schemaDefs = {}
@@ -270,10 +272,6 @@ def _init_job(self, joborder, input_basedir, **kwargs):
270272
if d not in builder.job and "default" in i:
271273
builder.job[d] = i["default"]
272274

273-
for r in self.requirements:
274-
if r["class"] not in supportedProcessRequirements:
275-
raise WorkflowException("Unsupported process requirement %s" % (r["class"]))
276-
277275
# Validate job order
278276
try:
279277
validate.validate_ex(self.names.get_name("input_record_schema", ""), builder.job)
@@ -363,6 +361,9 @@ def validate_hints(self, hints, strict):
363361
def get_requirement(self, feature):
364362
return get_feature(self, feature)
365363

364+
def visit(self, op):
365+
self.tool = op(self.tool)
366+
366367
def empty_subtree(dirpath):
367368
# Test if a directory tree contains any files (does not count empty
368369
# subdirectories)

cwltool/workflow.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@ def job(self, joborder, basedir, output_callback, **kwargs):
373373
for w in wj.job(builder.job, basedir, output_callback, **kwargs):
374374
yield w
375375

376+
def visit(self, op):
377+
self.tool = op(self.tool)
378+
self.steps = [op(s) for s in self.steps]
376379

377380
class WorkflowStep(Process):
378381
def __init__(self, toolpath_object, pos, **kwargs):

0 commit comments

Comments
 (0)