Skip to content

Commit 187e032

Browse files
committed
Allow output type: ["null", File]
1 parent 0f55791 commit 187e032

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

cwltool/draft2tool.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ def collect_output_ports(self, ports, builder, outdir):
185185
return outputdoc
186186

187187
ret = {}
188+
188189
for port in ports:
189190
fragment = shortname(port["id"])
190191
ret[fragment] = self.collect_output(port, builder, outdir)
@@ -195,6 +196,7 @@ def collect_output_ports(self, ports, builder, outdir):
195196

196197
def collect_output(self, schema, builder, outdir):
197198
r = None
199+
_type = None
198200
if "outputBinding" in schema:
199201
binding = schema["outputBinding"]
200202
if "glob" in binding:
@@ -219,19 +221,26 @@ def collect_output(self, schema, builder, outdir):
219221
files["checksum"] = "sha1$%s" % checksum.hexdigest()
220222
files["size"] = filesize
221223

224+
if isinstance(schema["type"], list):
225+
for t in schema["type"]:
226+
if t == "null" and (not r or len(r) == 0):
227+
return None
228+
if t == "File" and len(r) == 1:
229+
_type = "File"
230+
222231
if "outputEval" in binding:
223232
r = builder.do_eval(binding["outputEval"], context=r)
224-
if schema["type"] == "File" and (not isinstance(r, dict) or "path" not in r):
233+
if (schema["type"] == "File" or _type == "File") and (not isinstance(r, dict) or "path" not in r):
225234
raise WorkflowException("Expression must return a file object.")
226235

227-
if schema["type"] == "File":
236+
if schema["type"] == "File" or _type == "File":
228237
if not r:
229238
raise WorkflowException("No matches for output file with glob: '{}'".format(bg))
230239
if len(r) > 1:
231240
raise WorkflowException("Multiple matches for output item that is a single file.")
232241
r = r[0]
233242

234-
if schema["type"] == "File" and "secondaryFiles" in binding:
243+
if (schema["type"] == "File" or _type == "File") and "secondaryFiles" in binding:
235244
r["secondaryFiles"] = []
236245
for sf in aslist(binding["secondaryFiles"]):
237246
if isinstance(sf, dict) or "$(" in sf or "${" in sf:
@@ -247,7 +256,6 @@ def collect_output(self, schema, builder, outdir):
247256
if not builder.fs_access.exists(sf["path"]):
248257
raise WorkflowException("Missing secondary file of '%s' of primary file '%s'" % (sf["path"], r["path"]))
249258

250-
251259
if not r and schema["type"] == "record":
252260
r = {}
253261
for f in schema["fields"]:

cwltool/job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,5 @@ def run(self, dry_run=False, pull_image=True, rm_container=True, rm_tmpdir=True,
193193
shutil.rmtree(self.tmpdir, True)
194194

195195
if move_outputs and empty_subtree(self.outdir):
196-
_logger.debug("[job %s] Removing empty output directory %s", id(self), self.tmpdir)
196+
_logger.debug("[job %s] Removing empty output directory %s", id(self), self.outdir)
197197
shutil.rmtree(self.outdir, True)

0 commit comments

Comments
 (0)