19
19
cast ,
20
20
)
21
21
22
+ from cwl_utils .parser import cwl_v1_2 , cwl_v1_2_utils
22
23
from ruamel .yaml .comments import CommentedMap , CommentedSeq
23
24
from schema_salad .exceptions import ValidationException
24
25
from schema_salad .ref_resolver import Loader , file_uri
40
41
from .update import ALLUPDATES
41
42
from .utils import CWLObjectType , ResolverType , visit_class
42
43
43
- import cwl_utils .parser .cwl_v1_2
44
- import cwl_utils .parser .cwl_v1_2_utils
45
-
46
44
jobloaderctx = {
47
45
"cwl" : "https://w3id.org/cwl/cwl#" ,
48
46
"cwltool" : "http://commonwl.org/cwltool#" ,
@@ -266,30 +264,43 @@ def _add_blank_ids(
266
264
)
267
265
)
268
266
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 ):
267
+
268
+ def _fast_validator_convert_stdstreams_to_files (
269
+ processobj : Union [cwl_v1_2 .Process , MutableSequence [cwl_v1_2 .Process ]]
270
+ ) -> None :
271
+ if isinstance (processobj , cwl_v1_2 .CommandLineTool ):
272
+ cwl_v1_2_utils .convert_stdstreams_to_files (processobj )
273
+ elif isinstance (processobj , cwl_v1_2 .Workflow ):
273
274
for st in processobj .steps :
274
275
_fast_validator_convert_stdstreams_to_files (st .run )
275
276
elif isinstance (processobj , MutableSequence ):
276
277
for p in processobj :
277
278
_fast_validator_convert_stdstreams_to_files (p )
278
279
279
280
280
- def fast_validator (workflowobj , fileuri , uri , loadingContext : LoadingContext ):
281
- lopt = cwl_utils .parser .cwl_v1_2 .LoadingOptions (idx = loadingContext .codegen_idx , fileuri = fileuri )
281
+ def fast_validator (
282
+ workflowobj : Union [CommentedMap , CommentedSeq , None ],
283
+ fileuri : Optional [str ],
284
+ uri : str ,
285
+ loadingContext : LoadingContext ,
286
+ ) -> Tuple [Union [CommentedMap , CommentedSeq ], CommentedMap ]:
287
+ lopt = cwl_v1_2 .LoadingOptions (idx = loadingContext .codegen_idx , fileuri = fileuri )
282
288
283
289
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" ))
290
+ cwl_v1_2 .load_document_with_metadata (
291
+ workflowobj ,
292
+ fileuri ,
293
+ loadingOptions = lopt ,
294
+ addl_metadata_fields = ["id" , "cwlVersion" ],
295
+ )
285
296
286
297
objects , loadopt = loadingContext .codegen_idx [uri ]
287
298
288
299
_fast_validator_convert_stdstreams_to_files (objects )
289
300
290
- processobj = cwl_utils . parser . cwl_v1_2 .save (objects , relative_uris = False )
301
+ processobj = cwl_v1_2 .save (objects , relative_uris = False )
291
302
292
- metadata = {}
303
+ metadata : Dict [ str , Any ] = {}
293
304
metadata ["id" ] = loadopt .fileuri
294
305
295
306
if loadopt .namespaces :
@@ -298,15 +309,19 @@ def fast_validator(workflowobj, fileuri, uri, loadingContext: LoadingContext):
298
309
metadata ["$schemas" ] = loadopt .schemas
299
310
if loadopt .baseuri :
300
311
metadata ["$base" ] = loadopt .baseuri
301
- for k ,v in loadopt .addl_metadata .items ():
312
+ for k , v in loadopt .addl_metadata .items ():
302
313
if isinstance (processobj , MutableMapping ) and k in processobj :
303
314
metadata [k ] = processobj [k ]
304
315
else :
305
316
metadata [k ] = v
306
317
307
- loadingContext .loader .graph += loadopt .graph
318
+ if loadingContext .loader :
319
+ loadingContext .loader .graph += loadopt .graph
320
+
321
+ return cast (Union [CommentedMap , CommentedSeq ], cmap (processobj )), cast (
322
+ CommentedMap , cmap (metadata )
323
+ )
308
324
309
- return cmap (processobj ), cmap (metadata )
310
325
311
326
def resolve_and_validate_document (
312
327
loadingContext : LoadingContext ,
@@ -500,7 +515,7 @@ def make_tool(
500
515
if loadingContext .loader is None :
501
516
raise ValueError ("loadingContext must have a loader" )
502
517
503
- if loadingContext .fast_validator :
518
+ if loadingContext .fast_validator and isinstance ( uri , str ) :
504
519
resolveduri , metadata = fast_validator (None , None , uri , loadingContext )
505
520
else :
506
521
resolveduri , metadata = loadingContext .loader .resolve_ref (uri )
0 commit comments