44
44
from schema_salad .ref_resolver import Loader , file_uri , uri_file_path
45
45
from schema_salad .schema import load_schema , make_avro_schema , make_valid_avro
46
46
from schema_salad .sourceline import SourceLine , strip_dup_lineno
47
- from schema_salad .utils import convert_to_dict
48
- from schema_salad .validate import validate_ex
47
+ from schema_salad .utils import ContextType , convert_to_dict
48
+ from schema_salad .validate import validate_ex , avro_type_name
49
49
from typing_extensions import TYPE_CHECKING
50
50
51
51
from . import expression
52
- from .builder import Builder , HasReqsHints
52
+ from .builder import Builder , HasReqsHints , INPUT_OBJ_VOCAB
53
53
from .context import LoadingContext , RuntimeContext , getdefault
54
54
from .errors import UnsupportedRequirement , WorkflowException
55
55
from .loghandler import _logger
@@ -457,30 +457,34 @@ def fill_in_defaults(
457
457
458
458
459
459
def avroize_type (
460
- field_type : Union [
461
- CWLObjectType , MutableSequence [CWLOutputType ], CWLOutputType , None
462
- ],
460
+ field_type : Union [CWLObjectType , MutableSequence [Any ], CWLOutputType , None ],
463
461
name_prefix : str = "" ,
464
- ) -> None :
462
+ ) -> Union [ CWLObjectType , MutableSequence [ Any ], CWLOutputType , None ] :
465
463
"""Add missing information to a type so that CWL types are valid."""
466
464
if isinstance (field_type , MutableSequence ):
467
- for field in field_type :
468
- avroize_type (field , name_prefix )
465
+ for i , field in enumerate ( field_type ) :
466
+ field_type [ i ] = avroize_type (field , name_prefix )
469
467
elif isinstance (field_type , MutableMapping ):
470
468
if field_type ["type" ] in ("enum" , "record" ):
471
469
if "name" not in field_type :
472
470
field_type ["name" ] = name_prefix + str (uuid .uuid4 ())
473
471
if field_type ["type" ] == "record" :
474
- avroize_type (
472
+ field_type [ "fields" ] = avroize_type (
475
473
cast (MutableSequence [CWLOutputType ], field_type ["fields" ]), name_prefix
476
474
)
477
- if field_type ["type" ] == "array" :
478
- avroize_type (
475
+ elif field_type ["type" ] == "array" :
476
+ field_type [ "items" ] = avroize_type (
479
477
cast (MutableSequence [CWLOutputType ], field_type ["items" ]), name_prefix
480
478
)
481
- if isinstance (field_type ["type" ], MutableSequence ):
482
- for ctype in field_type ["type" ]:
483
- avroize_type (cast (CWLOutputType , ctype ), name_prefix )
479
+ else :
480
+ field_type ["type" ] = avroize_type (
481
+ cast (CWLOutputType , field_type ["type" ]), name_prefix
482
+ )
483
+ elif field_type == "File" :
484
+ return "org.w3id.cwl.cwl.File"
485
+ elif field_type == "Directory" :
486
+ return "org.w3id.cwl.cwl.Directory"
487
+ return field_type
484
488
485
489
486
490
def get_overrides (
@@ -635,6 +639,7 @@ def __init__(
635
639
sdtypes ,
636
640
{cast (str , t ["name" ]): cast (Dict [str , Any ], t ) for t in sdtypes },
637
641
set (),
642
+ vocab = INPUT_OBJ_VOCAB ,
638
643
)
639
644
for i in av :
640
645
self .schemaDefs [i ["name" ]] = i # type: ignore
@@ -669,7 +674,8 @@ def __init__(
669
674
c ["type" ] = nullable
670
675
else :
671
676
c ["type" ] = c ["type" ]
672
- avroize_type (c ["type" ], c ["name" ])
677
+
678
+ c ["type" ] = avroize_type (c ["type" ], c ["name" ])
673
679
if key == "inputs" :
674
680
cast (
675
681
List [CWLObjectType ], self .inputs_record_schema ["fields" ]
@@ -709,9 +715,13 @@ def __init__(
709
715
)
710
716
raise
711
717
if self .doc_schema is not None :
718
+ classname = toolpath_object ["class" ]
719
+ avroname = classname
720
+ if self .doc_loader and classname in self .doc_loader .vocab :
721
+ avroname = avro_type_name (self .doc_loader .vocab [classname ])
712
722
validate_js_expressions (
713
723
toolpath_object ,
714
- self .doc_schema .names [toolpath_object [ "class" ] ],
724
+ self .doc_schema .names [avroname ],
715
725
validate_js_options ,
716
726
)
717
727
@@ -778,7 +788,13 @@ def _init_job(
778
788
raise WorkflowException (
779
789
"Missing input record schema: " "{}" .format (self .names )
780
790
)
781
- validate_ex (schema , job , strict = False , logger = _logger_validation_warnings )
791
+ validate_ex (
792
+ schema ,
793
+ job ,
794
+ strict = False ,
795
+ logger = _logger_validation_warnings ,
796
+ vocab = INPUT_OBJ_VOCAB ,
797
+ )
782
798
783
799
if load_listing and load_listing != "no_listing" :
784
800
get_listing (fs_access , job , recursive = (load_listing == "deep_listing" ))
@@ -1015,13 +1031,16 @@ def evalResources(
1015
1031
def validate_hints (
1016
1032
self , avsc_names : Names , hints : List [CWLObjectType ], strict : bool
1017
1033
) -> None :
1034
+ if self .doc_loader is None :
1035
+ return
1018
1036
for i , r in enumerate (hints ):
1019
1037
sl = SourceLine (hints , i , ValidationException )
1020
1038
with sl :
1021
- if (
1022
- avsc_names .get_name (cast (str , r ["class" ]), None ) is not None
1023
- and self .doc_loader is not None
1024
- ):
1039
+ classname = cast (str , r ["class" ])
1040
+ avroname = classname
1041
+ if classname in self .doc_loader .vocab :
1042
+ avroname = avro_type_name (self .doc_loader .vocab [classname ])
1043
+ if avsc_names .get_name (avroname , None ) is not None :
1025
1044
plain_hint = {
1026
1045
key : r [key ]
1027
1046
for key in r
@@ -1030,10 +1049,11 @@ def validate_hints(
1030
1049
validate_ex (
1031
1050
cast (
1032
1051
Schema ,
1033
- avsc_names .get_name (cast ( str , plain_hint [ "class" ]) , None ),
1052
+ avsc_names .get_name (avroname , None ),
1034
1053
),
1035
1054
plain_hint ,
1036
1055
strict = strict ,
1056
+ vocab = self .doc_loader .vocab ,
1037
1057
)
1038
1058
elif r ["class" ] in ("NetworkAccess" , "LoadListingRequirement" ):
1039
1059
pass
0 commit comments