Skip to content

Commit bcb9097

Browse files
author
Peter Amstutz
committed
Refactor collect_output_ports, compute checksum when result is loaded from
cwl.output.json.
1 parent 823bdac commit bcb9097

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

cwltool/draft2tool.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -366,27 +366,26 @@ def collect_output_ports(self, ports, builder, outdir, compute_checksum=True):
366366
with builder.fs_access.open(custom_output, "r") as f:
367367
ret = json.load(f)
368368
_logger.debug(u"Raw output from %s: %s", custom_output, json.dumps(ret, indent=4))
369+
else:
370+
for port in ports:
371+
fragment = shortname(port["id"])
372+
try:
373+
ret[fragment] = self.collect_output(port, builder, outdir, compute_checksum)
374+
except Exception as e:
375+
_logger.debug(u"Error collecting output for parameter '%s'" % shortname(port["id"]), exc_info=e)
376+
raise WorkflowException(u"Error collecting output for parameter '%s': %s" % (shortname(port["id"]), e))
377+
378+
if ret:
369379
adjustFileObjs(ret,
370380
cast(Callable[[Any], Any], # known bug in mypy
371381
# https://github.com/python/mypy/issues/797
372382
partial(revmap_file, builder, outdir)))
373383
adjustFileObjs(ret, remove_path)
374384
adjustDirObjs(ret, remove_path)
375385
normalizeFilesDirs(ret)
376-
validate.validate_ex(self.names.get_name("outputs_record_schema", ""), ret)
377-
return ret
378-
379-
for port in ports:
380-
fragment = shortname(port["id"])
381-
try:
382-
ret[fragment] = self.collect_output(port, builder, outdir, compute_checksum)
383-
except Exception as e:
384-
_logger.debug(u"Error collecting output for parameter '%s'" % shortname(port["id"]), exc_info=e)
385-
raise WorkflowException(u"Error collecting output for parameter '%s': %s" % (shortname(port["id"]), e))
386-
if ret:
387-
adjustFileObjs(ret, remove_path)
388-
adjustDirObjs(ret, remove_path)
389-
normalizeFilesDirs(ret)
386+
if compute_checksum:
387+
adjustFileObjs(ret, partial(compute_checksums, builder.fs_access))
388+
390389
validate.validate_ex(self.names.get_name("outputs_record_schema", ""), ret)
391390
return ret if ret is not None else {}
392391
except validate.ValidationException as e:
@@ -491,9 +490,6 @@ def collect_output(self, schema, builder, outdir, compute_checksum=True):
491490
if not r and optional:
492491
r = None
493492

494-
if r and compute_checksum:
495-
adjustFileObjs(r, partial(compute_checksums, builder.fs_access))
496-
497493
if (not r and isinstance(schema["type"], dict) and
498494
schema["type"]["type"] == "record"):
499495
out = {}

0 commit comments

Comments
 (0)