2
2
import copy
3
3
import logging
4
4
import math
5
- from typing import (
5
+ from typing import ( # pylint: disable=unused-import
6
6
IO ,
7
+ TYPE_CHECKING ,
7
8
Any ,
8
9
Callable ,
9
10
Dict ,
10
11
List ,
11
12
MutableMapping ,
12
13
MutableSequence ,
13
14
Optional ,
15
+ Type ,
14
16
Union ,
15
17
cast ,
16
18
)
17
19
18
20
from cwl_utils import expression
19
21
from cwl_utils .file_formats import check_format
20
22
from rdflib import Graph
21
- from ruamel .yaml .comments import CommentedMap
22
23
from schema_salad .avro .schema import Names , Schema , make_avsc_object
23
24
from schema_salad .exceptions import ValidationException
24
25
from schema_salad .sourceline import SourceLine
25
26
from schema_salad .utils import convert_to_dict , json_dumps
26
27
from schema_salad .validate import validate
27
- from typing_extensions import TYPE_CHECKING , Type # pylint: disable=unused-import
28
+
29
+ from ruamel .yaml .comments import CommentedMap
28
30
29
31
from .errors import WorkflowException
30
32
from .loghandler import _logger
@@ -186,10 +188,8 @@ def bind_input(
186
188
if lead_pos is None :
187
189
lead_pos = []
188
190
189
- bindings = [] # type: List[MutableMapping[str, Union[str, List[int]]]]
190
- binding = (
191
- {}
192
- ) # type: 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 ] = {}
193
193
value_from_expression = False
194
194
if "inputBinding" in schema and isinstance (
195
195
schema ["inputBinding" ], MutableMapping
@@ -208,7 +208,7 @@ def bind_input(
208
208
).makeError (
209
209
"'position' expressions must evaluate to an int, "
210
210
f"not a { type (result )} . Expression { position } "
211
- f"resulted in ' { result } ' ."
211
+ f"resulted in { result !r } ."
212
212
)
213
213
binding ["position" ] = result
214
214
bp .append (result )
@@ -227,7 +227,7 @@ def bind_input(
227
227
if isinstance (schema ["type" ], MutableSequence ):
228
228
bound_input = False
229
229
for t in schema ["type" ]:
230
- avsc = None # type : Optional[Schema]
230
+ avsc : Optional [Schema ] = None
231
231
if isinstance (t , str ) and self .names .has_name (t , None ):
232
232
avsc = self .names .get_name (t , None )
233
233
elif (
@@ -336,10 +336,10 @@ def bind_input(
336
336
if binding :
337
337
b2 = cast (CWLObjectType , copy .deepcopy (binding ))
338
338
b2 ["datum" ] = item
339
- itemschema = {
339
+ itemschema : CWLObjectType = {
340
340
"type" : schema ["items" ],
341
341
"inputBinding" : b2 ,
342
- } # type: CWLObjectType
342
+ }
343
343
for k in ("secondaryFiles" , "format" , "streamable" ):
344
344
if k in schema :
345
345
itemschema [k ] = schema [k ]
@@ -362,9 +362,9 @@ def _capture_files(f: CWLObjectType) -> CWLObjectType:
362
362
datum = cast (CWLObjectType , datum )
363
363
self .files .append (datum )
364
364
365
- loadContents_sourceline = (
366
- None
367
- ) # type: Union[ None, MutableMapping[str, Union[str, List[int]]], CWLObjectType]
365
+ loadContents_sourceline : Union [
366
+ None , MutableMapping [ str , Union [ str , List [ int ]]], CWLObjectType
367
+ ] = None
368
368
if binding and binding .get ("loadContents" ):
369
369
loadContents_sourceline = binding
370
370
elif schema .get ("loadContents" ):
@@ -385,7 +385,7 @@ def _capture_files(f: CWLObjectType) -> CWLObjectType:
385
385
except Exception as e :
386
386
raise Exception (
387
387
"Reading {}\n {}" .format (datum ["location" ], e )
388
- )
388
+ ) from e
389
389
390
390
if "secondaryFiles" in schema :
391
391
if "secondaryFiles" not in datum :
@@ -415,8 +415,8 @@ def _capture_files(f: CWLObjectType) -> CWLObjectType:
415
415
"The result of a expression in the field "
416
416
"'required' must "
417
417
f"be a bool or None, not a { type (required_result )} . "
418
- f"Expression ' { sf_entry ['required' ]} ' resulted "
419
- f"in ' { required_result } ' ."
418
+ f"Expression { sf_entry ['required' ]!r } resulted "
419
+ f"in { required_result !r } ."
420
420
)
421
421
sf_required = required_result
422
422
else :
@@ -454,7 +454,7 @@ def _capture_files(f: CWLObjectType) -> CWLObjectType:
454
454
"Expected secondaryFile expression to "
455
455
"return type 'str', a 'File' or 'Directory' "
456
456
"dictionary, or a list of the same. Received "
457
- f"' { type (sfname )} from ' { sf_entry ['pattern' ]} ' ."
457
+ f"{ type (sfname )!r } from { sf_entry ['pattern' ]!r } ."
458
458
)
459
459
460
460
for d in cast (
@@ -529,9 +529,9 @@ def addsf(
529
529
"An expression in the 'format' field must "
530
530
"evaluate to a string, or list of strings. "
531
531
"However a non-string item was received: "
532
- f"' { entry } ' of type ' { type (entry )} ' . "
533
- f"The expression was ' { schema ['format' ]} ' and "
534
- f"its fully evaluated result is ' { eval_format } ' ."
532
+ f"{ entry !r } of type { type (entry )!r } . "
533
+ f"The expression was { schema ['format' ]!r } and "
534
+ f"its fully evaluated result is { eval_format !r } ."
535
535
)
536
536
if expression .needs_parsing (entry ):
537
537
message = (
@@ -542,7 +542,7 @@ def addsf(
542
542
"Expressions or CWL Parameter References. List "
543
543
f"entry number { index + 1 } contains the following "
544
544
"unallowed CWL Parameter Reference or Expression: "
545
- f"' { entry } ' ."
545
+ f"{ entry !r } ."
546
546
)
547
547
if message :
548
548
raise SourceLine (
@@ -557,8 +557,8 @@ def addsf(
557
557
"evaluate to a string, or list of strings. "
558
558
"However the type of the expression result was "
559
559
f"{ type (eval_format )} . "
560
- f"The expression was ' { schema ['format' ]} ' and "
561
- f"its fully evaluated result is ' eval_format' ."
560
+ f"The expression was { schema ['format' ]!r } and "
561
+ f"its fully evaluated result is { eval_format !r } ."
562
562
)
563
563
try :
564
564
check_format (
@@ -568,8 +568,8 @@ def addsf(
568
568
)
569
569
except ValidationException as ve :
570
570
raise WorkflowException (
571
- "Expected value of '%s' to have format %s but \n "
572
- " %s" % ( schema ["name" ], schema [ " format" ], ve )
571
+ f "Expected value of { schema [ 'name' ]!r } to have "
572
+ f"format { schema [' format' ]!r } but \n { ve } "
573
573
) from ve
574
574
575
575
visit_class (
@@ -646,7 +646,7 @@ def generate_arg(self, binding: CWLObjectType) -> List[str]:
646
646
"'separate' option can not be specified without prefix"
647
647
)
648
648
649
- argl = [] # type: MutableSequence[CWLOutputType ]
649
+ argl : MutableSequence [ CWLOutputType ] = [ ]
650
650
if isinstance (value , MutableSequence ):
651
651
if binding .get ("itemSeparator" ) and value :
652
652
itemSeparator = cast (str , binding ["itemSeparator" ])
0 commit comments