14
14
Set ,
15
15
Tuple ,
16
16
Union ,
17
+ cast ,
17
18
)
18
19
19
20
from rdflib import Graph , URIRef
20
21
from rdflib .namespace import OWL , RDFS
21
22
from ruamel .yaml .comments import CommentedMap
22
- from typing_extensions import TYPE_CHECKING , Type # pylint: disable=unused-import
23
-
24
23
from schema_salad .avro .schema import Names , Schema , make_avsc_object
25
24
from schema_salad .exceptions import ValidationException
26
25
from schema_salad .sourceline import SourceLine
27
26
from schema_salad .utils import convert_to_dict , json_dumps
28
27
from schema_salad .validate import validate
28
+ from typing_extensions import TYPE_CHECKING , Type # pylint: disable=unused-import
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
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 , visit_class
37
-
38
- # move to a regular typing import when Python 3.3-3.6 is no longer supported
39
-
36
+ from .utils import (
37
+ CWLObjectType ,
38
+ CWLOutputType ,
39
+ aslist ,
40
+ docker_windows_path_adjust ,
41
+ onWindows ,
42
+ visit_class ,
43
+ )
40
44
41
45
if TYPE_CHECKING :
42
46
from .provenance import ProvenanceProfile # pylint: disable=unused-import
@@ -126,14 +130,14 @@ def check_format(
126
130
127
131
128
132
class HasReqsHints (object ):
129
- def __init__ (self ): # type: () -> None
133
+ def __init__ (self ) -> None :
130
134
"""Initialize this reqs decorator."""
131
- self .requirements = [] # type: List[Dict[str, Any] ]
132
- self .hints = [] # type: List[Dict[str, Any] ]
135
+ self .requirements = [] # type: List[CWLObjectType ]
136
+ self .hints = [] # type: List[CWLObjectType ]
133
137
134
138
def get_requirement (
135
- self , feature # type : str
136
- ): # type: (...) -> Tuple[Optional[Any ], Optional[bool]]
139
+ self , feature : str
140
+ ) -> Tuple [Optional [CWLObjectType ], Optional [bool ]]:
137
141
for item in reversed (self .requirements ):
138
142
if item ["class" ] == feature :
139
143
return (item , True )
@@ -146,28 +150,28 @@ def get_requirement(
146
150
class Builder (HasReqsHints ):
147
151
def __init__ (
148
152
self ,
149
- job , # type: Dict[str, expression.JSON]
150
- files , # type : List[Dict[str, str]]
151
- bindings , # type : List[Dict[str, Any]]
152
- schemaDefs , # type : Dict[str, Dict[str, Any]]
153
- names , # type : Names
154
- requirements , # type : List[Dict[str, Any]]
155
- hints , # type : List[Dict[str, Any]]
156
- resources , # type : Dict[str, int]
153
+ job : CWLObjectType ,
154
+ files : List [CWLObjectType ],
155
+ bindings : List [CWLObjectType ],
156
+ schemaDefs : Dict [str , CWLObjectType ],
157
+ names : Names ,
158
+ requirements : List [CWLObjectType ],
159
+ hints : List [CWLObjectType ],
160
+ resources : Dict [str , int ],
157
161
mutation_manager : Optional [MutationManager ],
158
- formatgraph , # type : Optional[Graph]
162
+ formatgraph : Optional [Graph ],
159
163
make_fs_access : Type [StdFsAccess ],
160
- fs_access , # type : StdFsAccess
161
- job_script_provider , # type : Optional[Any]
162
- timeout , # type : float
163
- debug , # type : bool
164
- js_console , # type : bool
165
- force_docker_pull , # type : bool
166
- loadListing , # type : str
167
- outdir , # type : str
168
- tmpdir , # type : str
169
- stagedir , # type : str
170
- ): # type: (...) -> None
164
+ fs_access : StdFsAccess ,
165
+ job_script_provider : Optional [Any ],
166
+ timeout : float ,
167
+ debug : bool ,
168
+ js_console : bool ,
169
+ force_docker_pull : bool ,
170
+ loadListing : str ,
171
+ outdir : str ,
172
+ tmpdir : str ,
173
+ stagedir : str ,
174
+ ) -> None :
171
175
"""Initialize this Builder."""
172
176
self .job = job
173
177
self .files = files
@@ -360,7 +364,7 @@ def bind_input(
360
364
)
361
365
binding = {}
362
366
363
- def _capture_files (f ): # type: (Dict[str, str] ) -> Dict[str, str]
367
+ def _capture_files (f ): # type: (CWLObjectType ) -> CWLObjectType
364
368
self .files .append (f )
365
369
return f
366
370
@@ -504,7 +508,7 @@ def tostr(self, value: Union[MutableMapping[str, str], Any]) -> str:
504
508
else :
505
509
return str (value )
506
510
507
- def generate_arg (self , binding ): # type: (Dict[str, Any] ) -> List[str]
511
+ def generate_arg (self , binding : CWLObjectType ) -> List [str ]:
508
512
value = binding .get ("datum" )
509
513
if "valueFrom" in binding :
510
514
with SourceLine (
@@ -513,9 +517,9 @@ def generate_arg(self, binding): # type: (Dict[str, Any]) -> List[str]
513
517
WorkflowException ,
514
518
_logger .isEnabledFor (logging .DEBUG ),
515
519
):
516
- value = self .do_eval (binding ["valueFrom" ], context = value )
520
+ value = self .do_eval (cast ( str , binding ["valueFrom" ]) , context = value )
517
521
518
- prefix = binding .get ("prefix" ) # type: Optional[str]
522
+ prefix = cast ( Optional [ str ], binding .get ("prefix" ))
519
523
sep = binding .get ("separate" , True )
520
524
if prefix is None and not sep :
521
525
with SourceLine (
@@ -528,13 +532,16 @@ def generate_arg(self, binding): # type: (Dict[str, Any]) -> List[str]
528
532
"'separate' option can not be specified without prefix"
529
533
)
530
534
531
- argl = [] # type: MutableSequence[MutableMapping[str, str] ]
535
+ argl = [] # type: MutableSequence[CWLOutputType ]
532
536
if isinstance (value , MutableSequence ):
533
537
if binding .get ("itemSeparator" ) and value :
534
- argl = [binding ["itemSeparator" ].join ([self .tostr (v ) for v in value ])]
538
+ itemSeparator = cast (str , binding ["itemSeparator" ])
539
+ argl = [itemSeparator .join ([self .tostr (v ) for v in value ])]
535
540
elif binding .get ("valueFrom" ):
536
541
value = [self .tostr (v ) for v in value ]
537
- return ([prefix ] if prefix else []) + value
542
+ return cast (List [str ], ([prefix ] if prefix else [])) + cast (
543
+ List [str ], value
544
+ )
538
545
elif prefix and value :
539
546
return [prefix ]
540
547
else :
@@ -543,7 +550,7 @@ def generate_arg(self, binding): # type: (Dict[str, Any]) -> List[str]
543
550
"File" ,
544
551
"Directory" ,
545
552
):
546
- argl = [ value ]
553
+ argl = cast ( MutableSequence [ CWLOutputType ], [ value ])
547
554
elif isinstance (value , MutableMapping ):
548
555
return [prefix ] if prefix else []
549
556
elif value is True and prefix :
@@ -564,7 +571,9 @@ def generate_arg(self, binding): # type: (Dict[str, Any]) -> List[str]
564
571
565
572
def do_eval (
566
573
self ,
567
- ex : Union [MutableMapping [str , Any ], MutableSequence [str ], str ],
574
+ ex : Union [
575
+ str , float , bool , None , MutableMapping [str , str ], MutableSequence [str ]
576
+ ],
568
577
context : Optional [Any ] = None ,
569
578
recursive : bool = False ,
570
579
strip_whitespace : bool = True ,
0 commit comments