@@ -185,6 +185,7 @@ def collect_output_ports(self, ports, builder, outdir):
185
185
return outputdoc
186
186
187
187
ret = {}
188
+
188
189
for port in ports :
189
190
fragment = shortname (port ["id" ])
190
191
ret [fragment ] = self .collect_output (port , builder , outdir )
@@ -195,6 +196,7 @@ def collect_output_ports(self, ports, builder, outdir):
195
196
196
197
def collect_output (self , schema , builder , outdir ):
197
198
r = None
199
+ _type = None
198
200
if "outputBinding" in schema :
199
201
binding = schema ["outputBinding" ]
200
202
if "glob" in binding :
@@ -219,19 +221,26 @@ def collect_output(self, schema, builder, outdir):
219
221
files ["checksum" ] = "sha1$%s" % checksum .hexdigest ()
220
222
files ["size" ] = filesize
221
223
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
+
222
231
if "outputEval" in binding :
223
232
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 ):
225
234
raise WorkflowException ("Expression must return a file object." )
226
235
227
- if schema ["type" ] == "File" :
236
+ if schema ["type" ] == "File" or _type == "File" :
228
237
if not r :
229
238
raise WorkflowException ("No matches for output file with glob: '{}'" .format (bg ))
230
239
if len (r ) > 1 :
231
240
raise WorkflowException ("Multiple matches for output item that is a single file." )
232
241
r = r [0 ]
233
242
234
- if schema ["type" ] == "File" and "secondaryFiles" in binding :
243
+ if ( schema ["type" ] == "File" or _type == "File" ) and "secondaryFiles" in binding :
235
244
r ["secondaryFiles" ] = []
236
245
for sf in aslist (binding ["secondaryFiles" ]):
237
246
if isinstance (sf , dict ) or "$(" in sf or "${" in sf :
@@ -247,7 +256,6 @@ def collect_output(self, schema, builder, outdir):
247
256
if not builder .fs_access .exists (sf ["path" ]):
248
257
raise WorkflowException ("Missing secondary file of '%s' of primary file '%s'" % (sf ["path" ], r ["path" ]))
249
258
250
-
251
259
if not r and schema ["type" ] == "record" :
252
260
r = {}
253
261
for f in schema ["fields" ]:
0 commit comments