8
8
from abc import ABCMeta , abstractmethod
9
9
from threading import Lock
10
10
from typing import (
11
- Any ,
12
11
Dict ,
13
12
Iterable ,
14
13
List ,
15
- MutableMapping ,
16
14
MutableSequence ,
17
15
Optional ,
18
16
Set ,
@@ -45,14 +43,19 @@ class JobExecutor(object, metaclass=ABCMeta):
45
43
46
44
def __init__ (self ) -> None :
47
45
"""Initialize."""
48
- self .final_output = (
49
- []
50
- ) # type: MutableSequence[Union[Optional[CWLObjectType], MutableSequence[CWLObjectType]]]
46
+ self .final_output = [] # type: MutableSequence[Optional[CWLObjectType]]
51
47
self .final_status = [] # type: List[str]
52
48
self .output_dirs = set () # type: Set[str]
53
49
54
- def __call__ (self , * args : Any , ** kwargs : Any ) -> Any :
55
- return self .execute (* args , ** kwargs )
50
+ def __call__ (
51
+ self ,
52
+ process : Process ,
53
+ job_order_object : CWLObjectType ,
54
+ runtime_context : RuntimeContext ,
55
+ logger : logging .Logger = _logger ,
56
+ ) -> Tuple [Optional [CWLObjectType ], str ]:
57
+
58
+ return self .execute (process , job_order_object , runtime_context , logger )
56
59
57
60
def output_callback (
58
61
self , out : Optional [CWLObjectType ], process_status : str
@@ -77,12 +80,12 @@ def execute(
77
80
job_order_object : CWLObjectType ,
78
81
runtime_context : RuntimeContext ,
79
82
logger : logging .Logger = _logger ,
80
- ) -> Tuple [Union [Optional [CWLObjectType ], MutableSequence [ CWLObjectType ] ], str ]:
83
+ ) -> Tuple [Union [Optional [CWLObjectType ]], str ]:
81
84
"""Execute the process."""
82
85
if not runtime_context .basedir :
83
86
raise WorkflowException ("Must provide 'basedir' in runtimeContext" )
84
87
85
- def check_for_abstract_op (tool : MutableMapping [ str , Any ] ) -> None :
88
+ def check_for_abstract_op (tool : CWLObjectType ) -> None :
86
89
if tool ["class" ] == "Operation" :
87
90
raise SourceLine (tool , "class" , WorkflowException ).makeError (
88
91
"Workflow has unrunnable abstract Operation"
@@ -122,7 +125,7 @@ def check_for_abstract_op(tool: MutableMapping[str, Any]) -> None:
122
125
elif (
123
126
"cwl:defaults" in process .metadata
124
127
and "https://w3id.org/cwl/cwl#requirements"
125
- in process .metadata ["cwl:defaults" ]
128
+ in cast ( CWLObjectType , process .metadata ["cwl:defaults" ])
126
129
):
127
130
if (
128
131
process .metadata .get ("http://commonwl.org/cwltool#original_cwlVersion" )
@@ -133,9 +136,12 @@ def check_for_abstract_op(tool: MutableMapping[str, Any]) -> None:
133
136
"v1.0. You can adjust to use `cwltool:overrides` instead; or you "
134
137
"can set the cwlVersion to v1.1"
135
138
)
136
- job_reqs = process .metadata ["cwl:defaults" ][
137
- "https://w3id.org/cwl/cwl#requirements"
138
- ]
139
+ job_reqs = cast (
140
+ Optional [List [CWLObjectType ]],
141
+ cast (CWLObjectType , process .metadata ["cwl:defaults" ])[
142
+ "https://w3id.org/cwl/cwl#requirements"
143
+ ],
144
+ )
139
145
if job_reqs is not None :
140
146
for req in job_reqs :
141
147
process .requirements .append (req )
@@ -159,10 +165,10 @@ def check_for_abstract_op(tool: MutableMapping[str, Any]) -> None:
159
165
160
166
if runtime_context .rm_tmpdir :
161
167
if runtime_context .cachedir is None :
162
- output_dirs = self .output_dirs # type: Iterable[Any ]
168
+ output_dirs = self .output_dirs # type: Iterable[str ]
163
169
else :
164
170
output_dirs = filter (
165
- lambda x : not x .startswith (runtime_context .cachedir ),
171
+ lambda x : not x .startswith (runtime_context .cachedir ), # type: ignore
166
172
self .output_dirs ,
167
173
)
168
174
cleanIntermediate (output_dirs )
@@ -279,16 +285,16 @@ def __init__(self) -> None:
279
285
self .pending_jobs_lock = threading .Lock ()
280
286
281
287
self .max_ram = int (psutil .virtual_memory ().available / 2 ** 20 )
282
- self .max_cores = psutil .cpu_count ()
283
- self .allocated_ram = 0
284
- self .allocated_cores = 0
288
+ self .max_cores = float ( psutil .cpu_count () )
289
+ self .allocated_ram = float ( 0 )
290
+ self .allocated_cores = float ( 0 )
285
291
286
292
def select_resources (
287
293
self , request , runtime_context
288
294
): # pylint: disable=unused-argument
289
- # type: (Dict[str, int] , RuntimeContext) -> Dict[str, int]
295
+ # type: (Dict[str, Union[ int, float]] , RuntimeContext) -> Dict[str, Union[ int, float] ]
290
296
"""Naïve check for available cpu cores and memory."""
291
- result = {} # type: Dict[str, int]
297
+ result = {} # type: Dict[str, Union[ int, float] ]
292
298
maxrsc = {"cores" : self .max_cores , "ram" : self .max_ram }
293
299
for rsc in ("cores" , "ram" ):
294
300
if request [rsc + "Min" ] > maxrsc [rsc ]:
@@ -328,7 +334,9 @@ def _runner(self, job, runtime_context, TMPDIR_LOCK):
328
334
self .allocated_cores -= job .builder .resources ["cores" ]
329
335
runtime_context .workflow_eval_lock .notifyAll ()
330
336
331
- def run_job (self , job : JobsType , runtime_context : RuntimeContext ,) -> None :
337
+ def run_job (
338
+ self , job : Optional [JobsType ], runtime_context : RuntimeContext ,
339
+ ) -> None :
332
340
"""Execute a single Job in a seperate thread."""
333
341
if job is not None :
334
342
with self .pending_jobs_lock :
@@ -452,5 +460,5 @@ def execute(
452
460
job_order_object : CWLObjectType ,
453
461
runtime_context : RuntimeContext ,
454
462
logger : Optional [logging .Logger ] = None ,
455
- ) -> Tuple [Union [ Optional [CWLObjectType ], MutableSequence [ CWLObjectType ] ], str ]:
463
+ ) -> Tuple [Optional [CWLObjectType ], str ]:
456
464
return {}, "success"
0 commit comments