@@ -51,6 +51,20 @@ def job(self, joborder, input_basedir, output_callback, **kwargs):
51
51
52
52
yield j
53
53
54
+ def revmap_file (builder , outdir , f ):
55
+ """Remap a file back to original path. For Docker, this is outside the container.
56
+
57
+ Uses either files in the pathmapper or remaps internal output directories
58
+ to the external directory.
59
+ """
60
+ revmap_f = builder .pathmapper .reversemap (f )
61
+ if revmap_f :
62
+ return revmap_f [1 ]
63
+ elif f .startswith (builder .outdir ):
64
+ return os .path .join (outdir , f [len (builder .outdir )+ 1 :])
65
+ else :
66
+ raise WorkflowException ("Output file path %s must be within designated output directory or an input file pass through." % f )
67
+
54
68
55
69
class CommandLineTool (Process ):
56
70
def __init__ (self , toolpath_object , ** kwargs ):
@@ -183,13 +197,15 @@ def job(self, joborder, input_basedir, output_callback, **kwargs):
183
197
184
198
def collect_output_ports (self , ports , builder , outdir ):
185
199
try :
200
+ ret = {}
186
201
custom_output = os .path .join (outdir , "cwl.output.json" )
187
202
if builder .fs_access .exists (custom_output ):
188
- outputdoc = yaml .load (custom_output )
189
- validate .validate_ex (self .names .get_name ("outputs_record_schema" , "" ), outputdoc )
190
- return outputdoc
191
-
192
- ret = {}
203
+ with builder .fs_access .open (custom_output , "r" ) as f :
204
+ ret = yaml .load (f )
205
+ _logger .debug ("Raw output from %s: %s" , custom_output , json .dumps (ret , indent = 4 ))
206
+ adjustFiles (ret , functools .partial (revmap_file , builder , outdir ))
207
+ validate .validate_ex (self .names .get_name ("outputs_record_schema" , "" ), ret )
208
+ return ret
193
209
194
210
for port in ports :
195
211
fragment = shortname (port ["id" ])
@@ -200,20 +216,6 @@ def collect_output_ports(self, ports, builder, outdir):
200
216
raise WorkflowException ("Error validating output record, " + str (e ) + "\n in " + json .dumps (ret , indent = 4 ))
201
217
202
218
def collect_output (self , schema , builder , outdir ):
203
- def revmap_file (f ):
204
- """Remap a file back to original path. For Docker, this is outside the container.
205
-
206
- Uses either files in the pathmapper or remaps internal output directories
207
- to the external directory.
208
- """
209
- revmap_f = builder .pathmapper .reversemap (f )
210
- if revmap_f :
211
- return revmap_f [- 1 ]
212
- elif f .startswith (builder .outdir ):
213
- return f .replace (builder .outdir , outdir )
214
- else :
215
- return f
216
-
217
219
r = None
218
220
if "outputBinding" in schema :
219
221
binding = schema ["outputBinding" ]
@@ -276,9 +278,10 @@ def revmap_file(f):
276
278
else :
277
279
r = r [0 ]
278
280
281
+ # Ensure files point to local references outside of the run environment
282
+ adjustFiles (r , functools .partial (revmap_file , builder , outdir ))
283
+
279
284
if "secondaryFiles" in schema :
280
- # remap secondaryFiles since we check if they exist
281
- adjustFiles (r , revmap_file )
282
285
for primary in aslist (r ):
283
286
if isinstance (primary , dict ):
284
287
primary ["secondaryFiles" ] = []
@@ -301,6 +304,5 @@ def revmap_file(f):
301
304
r = {}
302
305
for f in schema ["type" ]["fields" ]:
303
306
r [shortname (f ["name" ])] = self .collect_output (f , builder , outdir )
304
- # Ensure files point to local references outside of the run environment
305
- adjustFiles (r , revmap_file )
307
+
306
308
return r
0 commit comments