21
21
from ruamel .yaml .comments import CommentedMap
22
22
from typing_extensions import TYPE_CHECKING , Type # pylint: disable=unused-import
23
23
24
- from schema_salad import validate
25
- from schema_salad .avro .schema import Schema , make_avsc_object
26
- from schema_salad .schema import Names , convert_to_dict
24
+ from schema_salad .avro .schema import Names , Schema , make_avsc_object
25
+ from schema_salad .exceptions import ValidationException
27
26
from schema_salad .sourceline import SourceLine
28
- from schema_salad .utils import json_dumps
27
+ from schema_salad .utils import convert_to_dict , json_dumps
28
+ from schema_salad .validate import validate
29
29
30
30
from . import expression
31
31
from .errors import WorkflowException
32
32
from .loghandler import _logger
33
33
from .mutation import MutationManager
34
- from .pathmapper import CONTENT_LIMIT , get_listing , normalizeFilesDirs , visit_class
34
+ from .pathmapper import CONTENT_LIMIT , get_listing , normalizeFilesDirs
35
35
from .stdfsaccess import StdFsAccess
36
- from .utils import aslist , docker_windows_path_adjust , onWindows
36
+ from .utils import aslist , docker_windows_path_adjust , onWindows , visit_class
37
37
38
38
# move to a regular typing import when Python 3.3-3.6 is no longer supported
39
39
@@ -112,15 +112,15 @@ def check_format(
112
112
if not afile :
113
113
continue
114
114
if "format" not in afile :
115
- raise validate . ValidationException (
115
+ raise ValidationException (
116
116
"File has no 'format' defined: {}" .format (json_dumps (afile , indent = 4 ))
117
117
)
118
118
for inpf in aslist (input_formats ):
119
119
if afile ["format" ] == inpf or formatSubclassOf (
120
120
afile ["format" ], inpf , ontology , set ()
121
121
):
122
122
return
123
- raise validate . ValidationException (
123
+ raise ValidationException (
124
124
"File has an incompatible format: {}" .format (json_dumps (afile , indent = 4 ))
125
125
)
126
126
@@ -202,10 +202,10 @@ def __init__(
202
202
self .prov_obj = None # type: Optional[ProvenanceProfile]
203
203
self .find_default_container = None # type: Optional[Callable[[], str]]
204
204
205
- def build_job_script (self , commands : List [str ]) -> str :
205
+ def build_job_script (self , commands : List [str ]) -> Optional [ str ] :
206
206
build_job_script_method = getattr (
207
207
self .job_script_provider , "build_job_script" , None
208
- ) # type: Callable[[Builder, Union[List[str],List[str]]], str]
208
+ ) # type: Optional[ Callable[[Builder, Union[List[str],List[str]]], str] ]
209
209
if build_job_script_method is not None :
210
210
return build_job_script_method (self , commands )
211
211
return None
@@ -216,7 +216,7 @@ def bind_input(
216
216
datum : Any ,
217
217
discover_secondaryFiles : bool ,
218
218
lead_pos : Optional [Union [int , List [int ]]] = None ,
219
- tail_pos : Optional [List [int ]] = None ,
219
+ tail_pos : Optional [Union [ str , List [int ] ]] = None ,
220
220
) -> List [MutableMapping [str , Any ]]:
221
221
222
222
if tail_pos is None :
@@ -265,7 +265,7 @@ def bind_input(
265
265
avsc = self .names .get_name (t ["name" ], None )
266
266
if not avsc :
267
267
avsc = make_avsc_object (convert_to_dict (t ), self .names )
268
- if validate . validate (avsc , datum ):
268
+ if validate (avsc , datum ):
269
269
schema = copy .deepcopy (schema )
270
270
schema ["type" ] = t
271
271
if not value_from_expression :
@@ -286,7 +286,7 @@ def bind_input(
286
286
)
287
287
bound_input = True
288
288
if not bound_input :
289
- raise validate . ValidationException (
289
+ raise ValidationException (
290
290
"'%s' is not a valid union %s" % (datum , schema ["type" ])
291
291
)
292
292
elif isinstance (schema ["type" ], MutableMapping ):
@@ -454,7 +454,7 @@ def addsf(
454
454
check_format (
455
455
datum , self .do_eval (schema ["format" ]), self .formatgraph
456
456
)
457
- except validate . ValidationException as ve :
457
+ except ValidationException as ve :
458
458
raise WorkflowException (
459
459
"Expected value of '%s' to have format %s but\n "
460
460
" %s" % (schema ["name" ], schema ["format" ], ve )
@@ -562,8 +562,13 @@ def generate_arg(self, binding): # type: (Dict[str, Any]) -> List[str]
562
562
563
563
return [a for a in args if a is not None ]
564
564
565
- def do_eval (self , ex , context = None , recursive = False , strip_whitespace = True ):
566
- # type: (Union[Dict[str, str], str], Any, bool, bool) -> Any
565
+ def do_eval (
566
+ self ,
567
+ ex : Union [MutableMapping [str , Any ], MutableSequence [str ], str ],
568
+ context : Optional [Any ] = None ,
569
+ recursive : bool = False ,
570
+ strip_whitespace : bool = True ,
571
+ ) -> Any :
567
572
if recursive :
568
573
if isinstance (ex , MutableMapping ):
569
574
return {k : self .do_eval (v , context , recursive ) for k , v in ex .items ()}
0 commit comments