Skip to content

Allow output type: ["null", File] #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from Nov 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions cwltool/draft2tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def collect_output_ports(self, ports, builder, outdir):
return outputdoc

ret = {}

for port in ports:
fragment = shortname(port["id"])
ret[fragment] = self.collect_output(port, builder, outdir)
Expand All @@ -195,6 +196,7 @@ def collect_output_ports(self, ports, builder, outdir):

def collect_output(self, schema, builder, outdir):
r = None
_type = None
if "outputBinding" in schema:
binding = schema["outputBinding"]
if "glob" in binding:
Expand All @@ -219,19 +221,26 @@ def collect_output(self, schema, builder, outdir):
files["checksum"] = "sha1$%s" % checksum.hexdigest()
files["size"] = filesize

if isinstance(schema["type"], list):
for t in schema["type"]:
if t == "null" and (not r or len(r) == 0):
return None
if t == "File" and len(r) == 1:
_type = "File"

if "outputEval" in binding:
r = builder.do_eval(binding["outputEval"], context=r)
if schema["type"] == "File" and (not isinstance(r, dict) or "path" not in r):
if (schema["type"] == "File" or _type == "File") and (not isinstance(r, dict) or "path" not in r):
raise WorkflowException("Expression must return a file object.")

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

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


if not r and schema["type"] == "record":
r = {}
for f in schema["fields"]:
Expand Down
2 changes: 1 addition & 1 deletion cwltool/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,5 @@ def run(self, dry_run=False, pull_image=True, rm_container=True, rm_tmpdir=True,
shutil.rmtree(self.tmpdir, True)

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