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,20 @@ 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 ]:
164
+ """Use the job_script_provider to turn the commands into a job script."""
176
165
if self .job_script_provider is not None :
177
166
return self .job_script_provider .build_job_script (self , commands )
178
167
return None
179
168
180
169
def bind_input (
181
170
self ,
182
171
schema : CWLObjectType ,
183
- datum : Union [CWLObjectType , List [CWLObjectType ]],
172
+ datum : Union [CWLObjectType , list [CWLObjectType ]],
184
173
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 ]]]]:
174
+ lead_pos : Optional [Union [int , list [int ]]] = None ,
175
+ tail_pos : Optional [Union [str , list [int ]]] = None ,
176
+ ) -> list [MutableMapping [str , Union [str , list [int ]]]]:
188
177
"""
189
178
Bind an input object to the command line.
190
179
@@ -200,8 +189,8 @@ def bind_input(
200
189
if lead_pos is None :
201
190
lead_pos = []
202
191
203
- bindings : List [MutableMapping [str , Union [str , List [int ]]]] = []
204
- binding : Union [MutableMapping [str , Union [str , List [int ]]], CommentedMap ] = {}
192
+ bindings : list [MutableMapping [str , Union [str , list [int ]]]] = []
193
+ binding : Union [MutableMapping [str , Union [str , list [int ]]], CommentedMap ] = {}
205
194
value_from_expression = False
206
195
if "inputBinding" in schema and isinstance (schema ["inputBinding" ], MutableMapping ):
207
196
binding = CommentedMap (schema ["inputBinding" ].items ())
@@ -282,7 +271,7 @@ def bind_input(
282
271
and "itemSeparator" not in binding
283
272
):
284
273
st ["inputBinding" ] = {}
285
- for k in ("secondaryFiles" , "format" , "streamable" ):
274
+ for k in ("secondaryFiles" , "format" , "streamable" , "loadContents" ):
286
275
if k in schema :
287
276
st [k ] = schema [k ]
288
277
if value_from_expression :
@@ -324,7 +313,7 @@ def bind_input(
324
313
325
314
if schema ["type" ] == "record" :
326
315
datum = cast (CWLObjectType , datum )
327
- for f in cast (List [CWLObjectType ], schema ["fields" ]):
316
+ for f in cast (list [CWLObjectType ], schema ["fields" ]):
328
317
name = cast (str , f ["name" ])
329
318
if name in datum and datum [name ] is not None :
330
319
bindings .extend (
@@ -349,7 +338,7 @@ def bind_input(
349
338
"type" : schema ["items" ],
350
339
"inputBinding" : b2 ,
351
340
}
352
- for k in ("secondaryFiles" , "format" , "streamable" ):
341
+ for k in ("secondaryFiles" , "format" , "streamable" , "loadContents" ):
353
342
if k in schema :
354
343
itemschema [k ] = schema [k ]
355
344
bindings .extend (
@@ -372,7 +361,7 @@ def _capture_files(f: CWLObjectType) -> CWLObjectType:
372
361
self .files .append (datum )
373
362
374
363
loadContents_sourceline : Union [
375
- None , MutableMapping [str , Union [str , List [int ]]], CWLObjectType
364
+ None , MutableMapping [str , Union [str , list [int ]]], CWLObjectType
376
365
] = None
377
366
if binding and binding .get ("loadContents" ):
378
367
loadContents_sourceline = binding
@@ -513,7 +502,7 @@ def addsf(
513
502
if "format" in schema :
514
503
eval_format : Any = self .do_eval (schema ["format" ])
515
504
if isinstance (eval_format , str ):
516
- evaluated_format : Union [str , List [str ]] = eval_format
505
+ evaluated_format : Union [str , list [str ]] = eval_format
517
506
elif isinstance (eval_format , MutableSequence ):
518
507
for index , entry in enumerate (eval_format ):
519
508
message = None
@@ -541,7 +530,7 @@ def addsf(
541
530
raise SourceLine (
542
531
schema ["format" ], index , WorkflowException , debug
543
532
).makeError (message )
544
- evaluated_format = cast (List [str ], eval_format )
533
+ evaluated_format = cast (list [str ], eval_format )
545
534
else :
546
535
raise SourceLine (schema , "format" , WorkflowException , debug ).makeError (
547
536
"An expression in the 'format' field must "
@@ -586,8 +575,8 @@ def addsf(
586
575
# Position to front of the sort key
587
576
if binding :
588
577
for bi in bindings :
589
- bi ["position" ] = cast (List [int ], binding ["position" ]) + cast (
590
- List [int ], bi ["position" ]
578
+ bi ["position" ] = cast (list [int ], binding ["position" ]) + cast (
579
+ list [int ], bi ["position" ]
591
580
)
592
581
bindings .append (binding )
593
582
@@ -618,7 +607,8 @@ def tostr(self, value: Union[MutableMapping[str, str], Any]) -> str:
618
607
else :
619
608
return str (value )
620
609
621
- def generate_arg (self , binding : CWLObjectType ) -> List [str ]:
610
+ def generate_arg (self , binding : CWLObjectType ) -> list [str ]:
611
+ """Convert an input binding to a list of command line arguments."""
622
612
value = binding .get ("datum" )
623
613
debug = _logger .isEnabledFor (logging .DEBUG )
624
614
if "valueFrom" in binding :
@@ -648,7 +638,7 @@ def generate_arg(self, binding: CWLObjectType) -> List[str]:
648
638
argl = [itemSeparator .join ([self .tostr (v ) for v in value ])]
649
639
elif binding .get ("valueFrom" ):
650
640
value = [self .tostr (v ) for v in value ]
651
- return cast (List [str ], ([prefix ] if prefix else [])) + cast (List [str ], value )
641
+ return cast (list [str ], ([prefix ] if prefix else [])) + cast (list [str ], value )
652
642
elif prefix and value :
653
643
return [prefix ]
654
644
else :
0 commit comments