Skip to content

Commit 63db4dd

Browse files
authored
Merge pull request #491 from common-workflow-language/version_fix
load_tool: when no version or incorrect cwlVersion is found, create fatal error
2 parents 296b70f + c08ebbb commit 63db4dd

File tree

4 files changed

+85
-2
lines changed

4 files changed

+85
-2
lines changed

cwltool/load_tool.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from . import process, update
2323
from .errors import WorkflowException
2424
from .process import Process, shortname
25+
from .update import ALLUPDATES
2526

2627
_logger = logging.getLogger("cwltool")
2728

@@ -161,12 +162,17 @@ def validate_document(document_loader, # type: Loader
161162
if "cwlVersion" in workflowobj:
162163
if not isinstance(workflowobj["cwlVersion"], (str, Text)):
163164
raise Exception("'cwlVersion' must be a string, got %s" % type(workflowobj["cwlVersion"]))
165+
if workflowobj["cwlVersion"] not in list(ALLUPDATES):
166+
# print out all the Supported Versions of cwlVersion
167+
versions = list(ALLUPDATES) # ALLUPDATES is a dict
168+
versions.sort()
169+
raise ValidationException("'cwlVersion' not valid. Supported CWL versions are: \n{}".format("\n".join(versions)))
164170
workflowobj["cwlVersion"] = re.sub(
165171
r"^(?:cwl:|https://w3id.org/cwl/cwl#)", "",
166172
workflowobj["cwlVersion"])
167173
else:
168-
_logger.warning("No cwlVersion found, treating this file as draft-2.")
169-
workflowobj["cwlVersion"] = "draft-2"
174+
raise ValidationException("No cwlVersion found."
175+
"Use the following syntax in your CWL workflow to declare version: cwlVersion: <version>")
170176

171177
if workflowobj["cwlVersion"] == "draft-2":
172178
workflowobj = cast(CommentedMap, cmap(update._draft2toDraft3dev1(

tests/test_cwl_version.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from __future__ import absolute_import
2+
import unittest
3+
4+
from cwltool.main import main
5+
6+
from .util import get_data
7+
8+
class CWL_Version_Checks(unittest.TestCase):
9+
# no cwlVersion in the workflow
10+
def test_missing_cwl_version(self):
11+
self.assertEqual(main([get_data('tests/wf/missing_cwlVersion.cwl')]), 1)
12+
# using cwlVersion: v0.1 in the workflow
13+
def test_incorrect_cwl_version(self):
14+
self.assertEqual(main([get_data('tests/wf/wrong_cwlVersion.cwl')]), 1)

tests/wf/missing_cwlVersion.cwl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env cwl-runner
2+
class: Workflow
3+
4+
label: "Hello World"
5+
doc: "Outputs a message using echo"
6+
7+
inputs: []
8+
9+
outputs:
10+
response:
11+
outputSource: step0/response
12+
type: File
13+
14+
steps:
15+
step0:
16+
run:
17+
class: CommandLineTool
18+
inputs:
19+
message:
20+
type: string
21+
doc: "The message to print"
22+
default: "Hello World"
23+
inputBinding:
24+
position: 1
25+
baseCommand: echo
26+
stdout: response.txt
27+
outputs:
28+
response:
29+
type: stdout
30+
in: []
31+
out: [response]

tests/wf/wrong_cwlVersion.cwl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env cwl-runner
2+
cwlVersion: v0.1
3+
class: Workflow
4+
5+
label: "Hello World"
6+
doc: "Outputs a message using echo"
7+
8+
inputs: []
9+
10+
outputs:
11+
response:
12+
outputSource: step0/response
13+
type: File
14+
15+
steps:
16+
step0:
17+
run:
18+
class: CommandLineTool
19+
inputs:
20+
message:
21+
type: string
22+
doc: "The message to print"
23+
default: "Hello World"
24+
inputBinding:
25+
position: 1
26+
baseCommand: echo
27+
stdout: response.txt
28+
outputs:
29+
response:
30+
type: stdout
31+
in: []
32+
out: [response]

0 commit comments

Comments
 (0)