3
3
import copy
4
4
import logging
5
5
import math
6
+ from collections .abc import MutableMapping , MutableSequence
6
7
from decimal import Decimal
7
- from typing import (
8
- IO ,
9
- TYPE_CHECKING ,
10
- Any ,
11
- Callable ,
12
- Dict ,
13
- List ,
14
- MutableMapping ,
15
- MutableSequence ,
16
- Optional ,
17
- Type ,
18
- Union ,
19
- cast ,
20
- )
8
+ from typing import IO , TYPE_CHECKING , Any , Callable , Optional , Union , cast
21
9
22
10
from cwl_utils import expression
23
11
from cwl_utils .file_formats import check_format
55
43
)
56
44
from .pathmapper import PathMapper
57
45
58
- INPUT_OBJ_VOCAB : Dict [str , str ] = {
46
+ INPUT_OBJ_VOCAB : dict [str , str ] = {
59
47
"Any" : "https://w3id.org/cwl/salad#Any" ,
60
48
"File" : "https://w3id.org/cwl/cwl#File" ,
61
49
"Directory" : "https://w3id.org/cwl/cwl#Directory" ,
@@ -107,16 +95,16 @@ class Builder(HasReqsHints):
107
95
def __init__ (
108
96
self ,
109
97
job : CWLObjectType ,
110
- files : List [CWLObjectType ],
111
- bindings : List [CWLObjectType ],
98
+ files : list [CWLObjectType ],
99
+ bindings : list [CWLObjectType ],
112
100
schemaDefs : MutableMapping [str , CWLObjectType ],
113
101
names : Names ,
114
- requirements : List [CWLObjectType ],
115
- hints : List [CWLObjectType ],
116
- resources : Dict [str , Union [int , float ]],
102
+ requirements : list [CWLObjectType ],
103
+ hints : list [CWLObjectType ],
104
+ resources : dict [str , Union [int , float ]],
117
105
mutation_manager : Optional [MutationManager ],
118
106
formatgraph : Optional [Graph ],
119
- make_fs_access : Type [StdFsAccess ],
107
+ make_fs_access : type [StdFsAccess ],
120
108
fs_access : StdFsAccess ,
121
109
job_script_provider : Optional [DependenciesConfiguration ],
122
110
timeout : float ,
@@ -172,19 +160,19 @@ def __init__(
172
160
self .find_default_container : Optional [Callable [[], str ]] = None
173
161
self .container_engine = container_engine
174
162
175
- def build_job_script (self , commands : List [str ]) -> Optional [str ]:
163
+ def build_job_script (self , commands : list [str ]) -> Optional [str ]:
176
164
if self .job_script_provider is not None :
177
165
return self .job_script_provider .build_job_script (self , commands )
178
166
return None
179
167
180
168
def bind_input (
181
169
self ,
182
170
schema : CWLObjectType ,
183
- datum : Union [CWLObjectType , List [CWLObjectType ]],
171
+ datum : Union [CWLObjectType , list [CWLObjectType ]],
184
172
discover_secondaryFiles : bool ,
185
- lead_pos : Optional [Union [int , List [int ]]] = None ,
186
- tail_pos : Optional [Union [str , List [int ]]] = None ,
187
- ) -> List [MutableMapping [str , Union [str , List [int ]]]]:
173
+ lead_pos : Optional [Union [int , list [int ]]] = None ,
174
+ tail_pos : Optional [Union [str , list [int ]]] = None ,
175
+ ) -> list [MutableMapping [str , Union [str , list [int ]]]]:
188
176
"""
189
177
Bind an input object to the command line.
190
178
@@ -200,8 +188,8 @@ def bind_input(
200
188
if lead_pos is None :
201
189
lead_pos = []
202
190
203
- bindings : List [MutableMapping [str , Union [str , List [int ]]]] = []
204
- binding : Union [MutableMapping [str , Union [str , List [int ]]], CommentedMap ] = {}
191
+ bindings : list [MutableMapping [str , Union [str , list [int ]]]] = []
192
+ binding : Union [MutableMapping [str , Union [str , list [int ]]], CommentedMap ] = {}
205
193
value_from_expression = False
206
194
if "inputBinding" in schema and isinstance (schema ["inputBinding" ], MutableMapping ):
207
195
binding = CommentedMap (schema ["inputBinding" ].items ())
@@ -324,7 +312,7 @@ def bind_input(
324
312
325
313
if schema ["type" ] == "record" :
326
314
datum = cast (CWLObjectType , datum )
327
- for f in cast (List [CWLObjectType ], schema ["fields" ]):
315
+ for f in cast (list [CWLObjectType ], schema ["fields" ]):
328
316
name = cast (str , f ["name" ])
329
317
if name in datum and datum [name ] is not None :
330
318
bindings .extend (
@@ -372,7 +360,7 @@ def _capture_files(f: CWLObjectType) -> CWLObjectType:
372
360
self .files .append (datum )
373
361
374
362
loadContents_sourceline : Union [
375
- None , MutableMapping [str , Union [str , List [int ]]], CWLObjectType
363
+ None , MutableMapping [str , Union [str , list [int ]]], CWLObjectType
376
364
] = None
377
365
if binding and binding .get ("loadContents" ):
378
366
loadContents_sourceline = binding
@@ -513,7 +501,7 @@ def addsf(
513
501
if "format" in schema :
514
502
eval_format : Any = self .do_eval (schema ["format" ])
515
503
if isinstance (eval_format , str ):
516
- evaluated_format : Union [str , List [str ]] = eval_format
504
+ evaluated_format : Union [str , list [str ]] = eval_format
517
505
elif isinstance (eval_format , MutableSequence ):
518
506
for index , entry in enumerate (eval_format ):
519
507
message = None
@@ -541,7 +529,7 @@ def addsf(
541
529
raise SourceLine (
542
530
schema ["format" ], index , WorkflowException , debug
543
531
).makeError (message )
544
- evaluated_format = cast (List [str ], eval_format )
532
+ evaluated_format = cast (list [str ], eval_format )
545
533
else :
546
534
raise SourceLine (schema , "format" , WorkflowException , debug ).makeError (
547
535
"An expression in the 'format' field must "
@@ -586,8 +574,8 @@ def addsf(
586
574
# Position to front of the sort key
587
575
if binding :
588
576
for bi in bindings :
589
- bi ["position" ] = cast (List [int ], binding ["position" ]) + cast (
590
- List [int ], bi ["position" ]
577
+ bi ["position" ] = cast (list [int ], binding ["position" ]) + cast (
578
+ list [int ], bi ["position" ]
591
579
)
592
580
bindings .append (binding )
593
581
@@ -618,7 +606,7 @@ def tostr(self, value: Union[MutableMapping[str, str], Any]) -> str:
618
606
else :
619
607
return str (value )
620
608
621
- def generate_arg (self , binding : CWLObjectType ) -> List [str ]:
609
+ def generate_arg (self , binding : CWLObjectType ) -> list [str ]:
622
610
value = binding .get ("datum" )
623
611
debug = _logger .isEnabledFor (logging .DEBUG )
624
612
if "valueFrom" in binding :
@@ -648,7 +636,7 @@ def generate_arg(self, binding: CWLObjectType) -> List[str]:
648
636
argl = [itemSeparator .join ([self .tostr (v ) for v in value ])]
649
637
elif binding .get ("valueFrom" ):
650
638
value = [self .tostr (v ) for v in value ]
651
- return cast (List [str ], ([prefix ] if prefix else [])) + cast (List [str ], value )
639
+ return cast (list [str ], ([prefix ] if prefix else [])) + cast (list [str ], value )
652
640
elif prefix and value :
653
641
return [prefix ]
654
642
else :
0 commit comments