Skip to content

Commit a19877e

Browse files
authored
Merge branch 'master' into fix-force-docker-pull
2 parents 59f9f85 + 0c8e2ee commit a19877e

File tree

4 files changed

+56
-22
lines changed

4 files changed

+56
-22
lines changed

cwltool/load_tool.py

+29-21
Original file line numberDiff line numberDiff line change
@@ -123,24 +123,30 @@ def _convert_stdstreams_to_files(workflowobj):
123123

124124
if isinstance(workflowobj, dict):
125125
if workflowobj.get('class') == 'CommandLineTool':
126-
for out in workflowobj.get('outputs', []):
127-
if type(out) is not CommentedMap:
128-
with SourceLine(workflowobj, "outputs", ValidationException, _logger.isEnabledFor(logging.DEBUG)):
129-
raise ValidationException("Output '%s' is not a valid OutputParameter." % out)
130-
for streamtype in ['stdout', 'stderr']:
131-
if out.get('type') == streamtype:
132-
if 'outputBinding' in out:
133-
raise ValidationException(
134-
"Not allowed to specify outputBinding when"
135-
" using %s shortcut." % streamtype)
136-
if streamtype in workflowobj:
137-
filename = workflowobj[streamtype]
138-
else:
139-
filename = Text(hashlib.sha1(json.dumps(workflowobj,
140-
sort_keys=True).encode('utf-8')).hexdigest())
141-
workflowobj[streamtype] = filename
142-
out['type'] = 'File'
143-
out['outputBinding'] = cmap({'glob': filename})
126+
with SourceLine(workflowobj, "outputs", ValidationException,
127+
_logger.isEnabledFor(logging.DEBUG)):
128+
outputs = workflowobj.get('outputs', [])
129+
if not isinstance(outputs, CommentedSeq):
130+
raise ValidationException('"outputs" section is not '
131+
'valid.')
132+
for out in workflowobj.get('outputs', []):
133+
if type(out) is not CommentedMap:
134+
raise ValidationException("Output '{}' is not a "
135+
"valid OutputParameter.".format(out))
136+
for streamtype in ['stdout', 'stderr']:
137+
if out.get('type') == streamtype:
138+
if 'outputBinding' in out:
139+
raise ValidationException(
140+
"Not allowed to specify outputBinding when"
141+
" using %s shortcut." % streamtype)
142+
if streamtype in workflowobj:
143+
filename = workflowobj[streamtype]
144+
else:
145+
filename = Text(hashlib.sha1(json.dumps(workflowobj,
146+
sort_keys=True).encode('utf-8')).hexdigest())
147+
workflowobj[streamtype] = filename
148+
out['type'] = 'File'
149+
out['outputBinding'] = cmap({'glob': filename})
144150
for inp in workflowobj.get('inputs', []):
145151
if inp.get('type') == 'stdin':
146152
if 'inputBinding' in inp:
@@ -219,9 +225,11 @@ def validate_document(document_loader, # type: Loader
219225
workflowobj['cwlVersion'] = metadata['cwlVersion']
220226
else:
221227
raise ValidationException(
222-
"No cwlVersion found. "
223-
"Use the following syntax in your CWL document to declare the version: cwlVersion: <version>.\n"
224-
"Note: if this is a CWL draft-2 (pre v1.0) document then it will need to be upgraded first.")
228+
"No cwlVersion found. "
229+
"Use the following syntax in your CWL document to declare "
230+
"the version: cwlVersion: <version>.\n"
231+
"Note: if this is a CWL draft-2 (pre v1.0) document then it "
232+
"will need to be upgraded first.")
225233

226234
if not isinstance(workflowobj["cwlVersion"], (str, Text)):
227235
raise Exception("'cwlVersion' must be a string, got %s" % type(workflowobj["cwlVersion"]))

cwltool/validate_js.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ def is_expression(tool, schema):
2525
# type: (Union[CommentedMap, Any], avro.schema.Schema) -> bool
2626
return isinstance(schema, avro.schema.EnumSchema) and schema.name == "Expression" and isinstance(tool, (str, Text))
2727

28+
class SuppressLog(logging.Filter):
29+
def __init__(self, name): # type: (Text) -> None
30+
name = str(name)
31+
super(SuppressLog, self).__init__(name)
32+
33+
def filter(self, record):
34+
return False
35+
36+
_logger_validation_warnings = logging.getLogger("cwltool.validation_warnings")
37+
_logger_validation_warnings.addFilter(SuppressLog("cwltool.validation_warnings"))
38+
2839
def get_expressions(tool, schema, source_line=None):
2940
# type: (Union[CommentedMap, Any], avro.schema.Schema, SourceLine) -> List[Tuple[Text, SourceLine]]
3041
if is_expression(tool, schema):
@@ -35,7 +46,7 @@ def get_expressions(tool, schema, source_line=None):
3546
for possible_schema in schema.schemas:
3647
if is_expression(tool, possible_schema):
3748
return [(tool, source_line)]
38-
elif validate_ex(possible_schema, tool, raise_ex=False):
49+
elif validate_ex(possible_schema, tool, raise_ex=False, logger=_logger_validation_warnings):
3950
valid_schema = possible_schema
4051

4152
return get_expressions(tool, valid_schema, source_line)

tests/echo_broken_outputs.cwl

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env cwl-runner
2+
cwlVersion: v1.0
3+
class: CommandLineTool
4+
inputs:
5+
- id: inp
6+
type: string
7+
inputBinding: {}
8+
baseCommand: echo
9+
stdout: out.txt
10+
outputs:

tests/test_examples.py

+5
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ def test_factory(self):
138138
echo = f.make(get_data("tests/echo.cwl"))
139139
self.assertEqual(echo(inp="foo"), {"out": "foo\n"})
140140

141+
def test_factory_bad_outputs(self):
142+
f = cwltool.factory.Factory()
143+
with self.assertRaises(schema_salad.validate.ValidationException):
144+
echo = f.make(get_data("tests/echo_broken_outputs.cwl"))
145+
141146
def test_default_args(self):
142147
f = cwltool.factory.Factory()
143148
assert f.execkwargs["use_container"] is True

0 commit comments

Comments
 (0)