Skip to content

Commit 1c6c0d8

Browse files
authored
Generalize "overrides" by putting them under "requirements" field. (#590)
* Generalize "overrides" by putting them under "requirements" field.
1 parent c2f9c45 commit 1c6c0d8

File tree

9 files changed

+38
-34
lines changed

9 files changed

+38
-34
lines changed

README.rst

+10-10
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Running tests locally
6565
To run the basis tests after installing `cwltool` execute the following:
6666

6767
.. code:: bash
68-
68+
6969
pip install pytest mock
7070
py.test --ignore cwltool/schemas/ --pyarg cwltool
7171
@@ -399,17 +399,16 @@ environment or with a particular dataset. To avoid the need to modify the
399399
underlying workflow, cwltool supports requirement "overrides".
400400

401401
The format of the "overrides" object is a mapping of item identifier (workflow,
402-
workflow step, or command line tool) followed by a list of ProcessRequirements
403-
that should be applied.
402+
workflow step, or command line tool) to the process requirements that should be applied.
404403

405404
.. code:: yaml
406405
407406
cwltool:overrides:
408407
echo.cwl:
409-
- class: EnvVarRequirement
410-
envDef:
411-
MESSAGE: override_value
412-
408+
requirements:
409+
EnvVarRequirement:
410+
envDef:
411+
MESSAGE: override_value
413412
414413
Overrides can be specified either on the command line, or as part of the job
415414
input document. Workflow steps are identified using the name of the workflow
@@ -426,9 +425,10 @@ Override identifiers are relative to the toplevel workflow document.
426425
input_parameter2: value2
427426
cwltool:overrides:
428427
workflow.cwl#step1:
429-
- class: EnvVarRequirement
430-
envDef:
431-
MESSAGE: override_value
428+
requirements:
429+
EnvVarRequirement:
430+
envDef:
431+
MESSAGE: override_value
432432
433433
.. code:: bash
434434

cwltool/load_tool.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@
4545
u"overrides": {
4646
"@id": "cwltool:overrides",
4747
"mapSubject": "overrideTarget",
48-
"mapPredicate": "override"
4948
},
50-
u"override": {
51-
"@id": "cwltool:override",
49+
"requirements": {
50+
"@id": "https://w3id.org/cwl/cwl#requirements",
5251
"mapSubject": "class"
5352
}
5453
} # type: ContextType

cwltool/process.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,13 @@ def avroize_type(field_type, name_prefix=""):
422422
avroize_type(field_type["items"], name_prefix)
423423
return field_type
424424

425-
def get_overrides(overrides, toolid): # type: (List[Dict[Text, Any]], Text) -> List[Dict[Text, Any]]
426-
req = [] # type: List[Dict[Text, Any]]
425+
def get_overrides(overrides, toolid): # type: (List[Dict[Text, Any]], Text) -> Dict[Text, Any]
426+
req = {} # type: Dict[Text, Any]
427427
if not isinstance(overrides, list):
428428
raise validate.ValidationException("Expected overrides to be a list, but was %s" % type(overrides))
429429
for ov in overrides:
430430
if ov["overrideTarget"] == toolid:
431-
req.extend(ov["override"])
431+
req.update(ov)
432432
return req
433433

434434
class Process(six.with_metaclass(abc.ABCMeta, object)):
@@ -467,7 +467,7 @@ def __init__(self, toolpath_object, **kwargs):
467467
self.tool = toolpath_object
468468
self.requirements = (kwargs.get("requirements", []) +
469469
self.tool.get("requirements", []) +
470-
get_overrides(kwargs.get("overrides", []), self.tool["id"]))
470+
get_overrides(kwargs.get("overrides", []), self.tool["id"]).get("requirements", []))
471471
self.hints = kwargs.get("hints", []) + self.tool.get("hints", [])
472472
self.formatgraph = None # type: Graph
473473
if "loader" in kwargs:

cwltool/workflow.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ def __init__(self, toolpath_object, pos, **kwargs):
673673

674674
kwargs["requirements"] = (kwargs.get("requirements", []) +
675675
toolpath_object.get("requirements", []) +
676-
get_overrides(kwargs.get("overrides", []), self.id))
676+
get_overrides(kwargs.get("overrides", []), self.id).get("requirements", []))
677677
kwargs["hints"] = kwargs.get("hints", []) + toolpath_object.get("hints", [])
678678

679679
try:

tests/override/echo-job-ov.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
m1: zing
22
cwltool:overrides:
33
echo.cwl:
4-
- class: EnvVarRequirement
5-
envDef:
6-
MESSAGE: hello3
4+
requirements:
5+
EnvVarRequirement:
6+
envDef:
7+
MESSAGE: hello3

tests/override/echo-job-ov2.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
m1: zing
22
cwltool:overrides:
33
echo.cwl:
4-
- class: EnvVarRequirement
5-
envDef:
6-
MESSAGE: hello4
4+
requirements:
5+
EnvVarRequirement:
6+
envDef:
7+
MESSAGE: hello4
78
cwl:tool: echo.cwl

tests/override/ov.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
cwltool:overrides:
22
echo.cwl:
3-
- class: EnvVarRequirement
4-
envDef:
5-
MESSAGE: hello2
3+
requirements:
4+
EnvVarRequirement:
5+
envDef:
6+
MESSAGE: hello2

tests/override/ov2.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
cwltool:overrides:
22
"echo-wf.cwl#step1":
3-
- class: EnvVarRequirement
4-
envDef:
5-
MESSAGE: hello5
3+
requirements:
4+
EnvVarRequirement:
5+
envDef:
6+
MESSAGE: hello5

tests/override/ov3.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
cwltool:overrides:
2-
"echo-wf.cwl":
3-
- class: EnvVarRequirement
4-
envDef:
5-
MESSAGE: hello6
2+
echo-wf.cwl:
3+
requirements:
4+
EnvVarRequirement:
5+
envDef:
6+
MESSAGE: hello6

0 commit comments

Comments
 (0)