30
30
from .errors import WorkflowException
31
31
from .loghandler import _logger
32
32
from .mutation import MutationManager
33
+ from .software_requirements import DependenciesConfiguration
33
34
from .stdfsaccess import StdFsAccess
34
35
from .utils import (
35
36
CONTENT_LIMIT ,
44
45
)
45
46
46
47
if TYPE_CHECKING :
47
- from .provenance import ProvenanceProfile # pylint: disable=unused-import
48
+ from .provenance_profile import ProvenanceProfile # pylint: disable=unused-import
48
49
from .pathmapper import PathMapper
49
50
50
51
@@ -108,10 +109,10 @@ def formatSubclassOf(
108
109
109
110
110
111
def check_format (
111
- actual_file , # type : Union[Dict[str, Any], List[Dict[str, Any ]], str]
112
- input_formats , # type : Union[List[str], str]
113
- ontology , # type : Optional[Graph]
114
- ): # type: (...) -> None
112
+ actual_file : Union [CWLObjectType , List [CWLObjectType ]],
113
+ input_formats : Union [List [str ], str ],
114
+ ontology : Optional [Graph ],
115
+ ) -> None :
115
116
"""Confirm that the format present is valid for the allowed formats."""
116
117
for afile in aslist (actual_file ):
117
118
if not afile :
@@ -154,16 +155,16 @@ def __init__(
154
155
job : CWLObjectType ,
155
156
files : List [CWLObjectType ],
156
157
bindings : List [CWLObjectType ],
157
- schemaDefs : Dict [str , CWLObjectType ],
158
+ schemaDefs : MutableMapping [str , CWLObjectType ],
158
159
names : Names ,
159
160
requirements : List [CWLObjectType ],
160
161
hints : List [CWLObjectType ],
161
- resources : Dict [str , int ],
162
+ resources : Dict [str , Union [ int , float ] ],
162
163
mutation_manager : Optional [MutationManager ],
163
164
formatgraph : Optional [Graph ],
164
165
make_fs_access : Type [StdFsAccess ],
165
166
fs_access : StdFsAccess ,
166
- job_script_provider : Optional [Any ],
167
+ job_script_provider : Optional [DependenciesConfiguration ],
167
168
timeout : float ,
168
169
debug : bool ,
169
170
js_console : bool ,
@@ -208,21 +209,18 @@ def __init__(
208
209
self .find_default_container = None # type: Optional[Callable[[], str]]
209
210
210
211
def build_job_script (self , commands : List [str ]) -> Optional [str ]:
211
- build_job_script_method = getattr (
212
- self .job_script_provider , "build_job_script" , None
213
- ) # type: Optional[Callable[[Builder, Union[List[str],List[str]]], str]]
214
- if build_job_script_method is not None :
215
- return build_job_script_method (self , commands )
212
+ if self .job_script_provider is not None :
213
+ return self .job_script_provider .build_job_script (self , commands )
216
214
return None
217
215
218
216
def bind_input (
219
217
self ,
220
- schema : MutableMapping [ str , Any ] ,
221
- datum : Any ,
218
+ schema : CWLObjectType ,
219
+ datum : Union [ CWLObjectType , List [ CWLObjectType ]] ,
222
220
discover_secondaryFiles : bool ,
223
221
lead_pos : Optional [Union [int , List [int ]]] = None ,
224
222
tail_pos : Optional [Union [str , List [int ]]] = None ,
225
- ) -> List [MutableMapping [str , Any ]]:
223
+ ) -> List [MutableMapping [str , Union [ str , List [ int ]] ]]:
226
224
227
225
if tail_pos is None :
228
226
tail_pos = []
@@ -267,9 +265,9 @@ def bind_input(
267
265
elif (
268
266
isinstance (t , MutableMapping )
269
267
and "name" in t
270
- and self .names .has_name (t ["name" ], None )
268
+ and self .names .has_name (cast ( str , t ["name" ]) , None )
271
269
):
272
- avsc = self .names .get_name (t ["name" ], None )
270
+ avsc = self .names .get_name (cast ( str , t ["name" ]) , None )
273
271
if not avsc :
274
272
avsc = make_avsc_object (convert_to_dict (t ), self .names )
275
273
if validate (avsc , datum ):
@@ -329,30 +327,35 @@ def bind_input(
329
327
)
330
328
else :
331
329
if schema ["type" ] in self .schemaDefs :
332
- schema = self .schemaDefs [schema ["type" ]]
330
+ schema = self .schemaDefs [cast ( str , schema ["type" ]) ]
333
331
334
332
if schema ["type" ] == "record" :
335
- for f in schema ["fields" ]:
336
- if f ["name" ] in datum and datum [f ["name" ]] is not None :
333
+ datum = cast (CWLObjectType , datum )
334
+ for f in cast (List [CWLObjectType ], schema ["fields" ]):
335
+ name = cast (str , f ["name" ])
336
+ if name in datum and datum [name ] is not None :
337
337
bindings .extend (
338
338
self .bind_input (
339
339
f ,
340
- datum [f [ " name" ]] ,
340
+ cast ( CWLObjectType , datum [name ]) ,
341
341
lead_pos = lead_pos ,
342
- tail_pos = f [ " name" ] ,
342
+ tail_pos = name ,
343
343
discover_secondaryFiles = discover_secondaryFiles ,
344
344
)
345
345
)
346
346
else :
347
- datum [f [ " name" ] ] = f .get ("default" )
347
+ datum [name ] = f .get ("default" )
348
348
349
349
if schema ["type" ] == "array" :
350
- for n , item in enumerate (datum ):
350
+ for n , item in enumerate (cast ( MutableSequence [ CWLObjectType ], datum ) ):
351
351
b2 = None
352
352
if binding :
353
- b2 = copy .deepcopy (binding )
353
+ b2 = cast ( CWLObjectType , copy .deepcopy (binding ) )
354
354
b2 ["datum" ] = item
355
- itemschema = {"type" : schema ["items" ], "inputBinding" : b2 }
355
+ itemschema = {
356
+ "type" : schema ["items" ],
357
+ "inputBinding" : b2 ,
358
+ } # type: CWLObjectType
356
359
for k in ("secondaryFiles" , "format" , "streamable" ):
357
360
if k in schema :
358
361
itemschema [k ] = schema [k ]
@@ -367,17 +370,18 @@ def bind_input(
367
370
)
368
371
binding = {}
369
372
370
- def _capture_files (f ): # type: ( CWLObjectType) -> CWLObjectType
373
+ def _capture_files (f : CWLObjectType ) -> CWLObjectType :
371
374
self .files .append (f )
372
375
return f
373
376
374
377
if schema ["type" ] == "File" :
378
+ datum = cast (CWLObjectType , datum )
375
379
self .files .append (datum )
376
380
if (binding and binding .get ("loadContents" )) or schema .get (
377
381
"loadContents"
378
382
):
379
- with self .fs_access .open (datum ["location" ], "rb" ) as f :
380
- datum ["contents" ] = content_limit_respected_read (f )
383
+ with self .fs_access .open (cast ( str , datum ["location" ]) , "rb" ) as f2 :
384
+ datum ["contents" ] = content_limit_respected_read (f2 )
381
385
382
386
if "secondaryFiles" in schema :
383
387
if "secondaryFiles" not in datum :
@@ -391,7 +395,9 @@ def _capture_files(f): # type: (CWLObjectType) -> CWLObjectType
391
395
if "$(" in sf ["pattern" ] or "${" in sf ["pattern" ]:
392
396
sfpath = self .do_eval (sf ["pattern" ], context = datum )
393
397
else :
394
- sfpath = substitute (datum ["basename" ], sf ["pattern" ])
398
+ sfpath = substitute (
399
+ cast (str , datum ["basename" ]), sf ["pattern" ]
400
+ )
395
401
396
402
for sfname in aslist (sfpath ):
397
403
if not sfname :
@@ -400,8 +406,8 @@ def _capture_files(f): # type: (CWLObjectType) -> CWLObjectType
400
406
401
407
if isinstance (sfname , str ):
402
408
sf_location = (
403
- datum ["location" ][
404
- 0 : datum ["location" ].rindex ("/" ) + 1
409
+ cast ( str , datum ["location" ]) [
410
+ 0 : cast ( str , datum ["location" ]) .rindex ("/" ) + 1
405
411
]
406
412
+ sfname
407
413
)
@@ -415,7 +421,10 @@ def _capture_files(f): # type: (CWLObjectType) -> CWLObjectType
415
421
% (type (sfname ))
416
422
)
417
423
418
- for d in datum ["secondaryFiles" ]:
424
+ for d in cast (
425
+ MutableSequence [MutableMapping [str , str ]],
426
+ datum ["secondaryFiles" ],
427
+ ):
419
428
if not d .get ("basename" ):
420
429
d ["basename" ] = d ["location" ][
421
430
d ["location" ].rindex ("/" ) + 1 :
@@ -426,8 +435,8 @@ def _capture_files(f): # type: (CWLObjectType) -> CWLObjectType
426
435
if not found :
427
436
428
437
def addsf (
429
- files : MutableSequence [MutableMapping [ str , Any ] ],
430
- newsf : MutableMapping [ str , Any ] ,
438
+ files : MutableSequence [CWLObjectType ],
439
+ newsf : CWLObjectType ,
431
440
) -> None :
432
441
for f in files :
433
442
if f ["location" ] == newsf ["location" ]:
@@ -436,12 +445,21 @@ def addsf(
436
445
files .append (newsf )
437
446
438
447
if isinstance (sfname , MutableMapping ):
439
- addsf (datum ["secondaryFiles" ], sfname )
448
+ addsf (
449
+ cast (
450
+ MutableSequence [CWLObjectType ],
451
+ datum ["secondaryFiles" ],
452
+ ),
453
+ sfname ,
454
+ )
440
455
elif discover_secondaryFiles and self .fs_access .exists (
441
456
sf_location
442
457
):
443
458
addsf (
444
- datum ["secondaryFiles" ],
459
+ cast (
460
+ MutableSequence [CWLObjectType ],
461
+ datum ["secondaryFiles" ],
462
+ ),
445
463
{
446
464
"location" : sf_location ,
447
465
"basename" : sfname ,
@@ -454,12 +472,16 @@ def addsf(
454
472
% (sfname , json_dumps (datum , indent = 4 ))
455
473
)
456
474
457
- normalizeFilesDirs (datum ["secondaryFiles" ])
475
+ normalizeFilesDirs (
476
+ cast (MutableSequence [CWLObjectType ], datum ["secondaryFiles" ])
477
+ )
458
478
459
479
if "format" in schema :
460
480
try :
461
481
check_format (
462
- datum , self .do_eval (schema ["format" ]), self .formatgraph
482
+ datum ,
483
+ cast (Union [List [str ], str ], self .do_eval (schema ["format" ])),
484
+ self .formatgraph ,
463
485
)
464
486
except ValidationException as ve :
465
487
raise WorkflowException (
@@ -474,9 +496,12 @@ def addsf(
474
496
)
475
497
476
498
if schema ["type" ] == "Directory" :
499
+ datum = cast (CWLObjectType , datum )
477
500
ll = schema .get ("loadListing" ) or self .loadListing
478
501
if ll and ll != "no_listing" :
479
- get_listing (self .fs_access , datum , (ll == "deep_listing" ))
502
+ get_listing (
503
+ self .fs_access , datum , (ll == "deep_listing" ),
504
+ )
480
505
self .files .append (datum )
481
506
482
507
if schema ["type" ] == "Any" :
@@ -576,13 +601,11 @@ def generate_arg(self, binding: CWLObjectType) -> List[str]:
576
601
577
602
def do_eval (
578
603
self ,
579
- ex : Union [
580
- str , float , bool , None , MutableMapping [str , str ], MutableSequence [str ]
581
- ],
604
+ ex : Optional [CWLOutputType ],
582
605
context : Optional [Any ] = None ,
583
606
recursive : bool = False ,
584
607
strip_whitespace : bool = True ,
585
- ) -> Any :
608
+ ) -> Optional [ CWLOutputType ] :
586
609
if recursive :
587
610
if isinstance (ex , MutableMapping ):
588
611
return {k : self .do_eval (v , context , recursive ) for k , v in ex .items ()}
0 commit comments