40
40
from .update import ALLUPDATES
41
41
from .utils import CWLObjectType , ResolverType , visit_class
42
42
43
+ import cwl_utils .parser .cwl_v1_2
44
+ import cwl_utils .parser .cwl_v1_2_utils
45
+
43
46
jobloaderctx = {
44
47
"cwl" : "https://w3id.org/cwl/cwl#" ,
45
48
"cwltool" : "http://commonwl.org/cwltool#" ,
@@ -263,6 +266,45 @@ def _add_blank_ids(
263
266
)
264
267
)
265
268
269
+ def _fast_validator_convert_stdstreams_to_files (processobj ) -> None :
270
+ if isinstance (processobj , cwl_utils .parser .cwl_v1_2 .CommandLineTool ):
271
+ cwl_utils .parser .cwl_v1_2_utils .convert_stdstreams_to_files (processobj )
272
+ elif isinstance (processobj , cwl_utils .parser .cwl_v1_2 .Workflow ):
273
+ for st in processobj .steps :
274
+ _fast_validator_convert_stdstreams_to_files (st .run )
275
+ elif isinstance (processobj , MutableSequence ):
276
+ for p in processobj :
277
+ _fast_validator_convert_stdstreams_to_files (p )
278
+
279
+
280
+ def fast_validator (workflowobj , fileuri , uri , loadingContext : LoadingContext ):
281
+ lopt = cwl_utils .parser .cwl_v1_2 .LoadingOptions (idx = loadingContext .codegen_idx , fileuri = fileuri )
282
+
283
+ if uri not in loadingContext .codegen_idx :
284
+ cwl_utils .parser .cwl_v1_2 .load_document_with_metadata (workflowobj , fileuri , loadingOptions = lopt , addl_metadata_fields = ("id" , "cwlVersion" ))
285
+
286
+ objects , loadopt = loadingContext .codegen_idx [uri ]
287
+
288
+ _fast_validator_convert_stdstreams_to_files (objects )
289
+
290
+ processobj = cwl_utils .parser .cwl_v1_2 .save (objects , relative_uris = False )
291
+
292
+ metadata = {}
293
+ metadata ["id" ] = loadopt .fileuri
294
+
295
+ if loadopt .namespaces :
296
+ metadata ["$namespaces" ] = loadopt .namespaces
297
+ if loadopt .schemas :
298
+ metadata ["$schemas" ] = loadopt .schemas
299
+ if loadopt .baseuri :
300
+ metadata ["$base" ] = loadopt .baseuri
301
+ for k ,v in loadopt .addl_metadata .items ():
302
+ if isinstance (processobj , MutableMapping ) and k in processobj :
303
+ metadata [k ] = processobj [k ]
304
+ else :
305
+ metadata [k ] = v
306
+
307
+ return cmap (processobj ), cmap (metadata )
266
308
267
309
def resolve_and_validate_document (
268
310
loadingContext : LoadingContext ,
@@ -381,8 +423,15 @@ def resolve_and_validate_document(
381
423
if cwlVersion == "v1.0" :
382
424
_add_blank_ids (workflowobj )
383
425
384
- document_loader .resolve_all (workflowobj , fileuri )
385
- processobj , metadata = document_loader .resolve_ref (uri )
426
+ if cwlVersion != "v1.2" :
427
+ loadingContext .fast_validator = False
428
+
429
+ if loadingContext .fast_validator :
430
+ processobj , metadata = fast_validator (workflowobj , fileuri , uri , loadingContext )
431
+ else :
432
+ document_loader .resolve_all (workflowobj , fileuri )
433
+ processobj , metadata = document_loader .resolve_ref (uri )
434
+
386
435
if not isinstance (processobj , (CommentedMap , CommentedSeq )):
387
436
raise ValidationException ("Workflow must be a CommentedMap or CommentedSeq." )
388
437
@@ -405,7 +454,8 @@ def resolve_and_validate_document(
405
454
if isinstance (processobj , CommentedMap ):
406
455
uri = processobj ["id" ]
407
456
408
- _convert_stdstreams_to_files (workflowobj )
457
+ if not loadingContext .fast_validator :
458
+ _convert_stdstreams_to_files (workflowobj )
409
459
410
460
if isinstance (jobobj , CommentedMap ):
411
461
loadingContext .jobdefaults = jobobj
0 commit comments