7
7
8
8
from flask import url_for
9
9
10
- from typing import List , Dict , Callable
10
+ from typing import List , Dict , Callable , Union
11
11
12
12
from .utilities import camel_to_snake , get_docstring , snake_to_spine
13
13
from .views .builder import static_from
@@ -36,11 +36,11 @@ def __init__(
36
36
self ._meta : dict = {} # Extra metadata to add to the extension description
37
37
38
38
self ._on_registers : List [
39
- Dict
39
+ Union [ Dict , Callable ]
40
40
] = [] # List of dictionaries of functions to run on registration
41
41
42
42
self ._on_components : List [
43
- Dict
43
+ Union [ Dict , Callable ]
44
44
] = [] # List of dictionaries of functions to run as components are added
45
45
46
46
self ._cls = str (self ) # String description of extension instance
@@ -64,6 +64,14 @@ def views(self):
64
64
""" """
65
65
return self ._views
66
66
67
+ @property
68
+ def on_components (self ):
69
+ return self ._on_components
70
+
71
+ @property
72
+ def on_registers (self ):
73
+ return self ._on_registers
74
+
67
75
def add_view (self , view_class , * urls , endpoint = None , ** kwargs ):
68
76
"""
69
77
@@ -217,7 +225,7 @@ def find_instances_in_module(module, class_to_find):
217
225
for attribute in dir (module ):
218
226
if not attribute .startswith ("__" ):
219
227
if isinstance (getattr (module , attribute ), class_to_find ):
220
- logging .debug (f "Found extension { getattr (module , attribute ).name } " )
228
+ logging .debug ("Found extension %s" , getattr (module , attribute ).name )
221
229
objs .append (getattr (module , attribute ))
222
230
return objs
223
231
@@ -235,17 +243,19 @@ def find_extensions_in_file(extension_path: str, module_name="extensions") -> li
235
243
:rtype: list
236
244
237
245
"""
238
- logging .debug (f "Loading extensions from { extension_path } " )
246
+ logging .debug ("Loading extensions from %s" , extension_path )
239
247
240
248
spec = util .spec_from_file_location (module_name , extension_path )
241
249
mod = util .module_from_spec (spec )
242
250
sys .modules [spec .name ] = mod
243
251
244
252
try :
245
253
spec .loader .exec_module (mod ) # type: ignore
246
- except Exception : # skipcq: PYL-W0703
254
+ except Exception : # pylint: disable=broad-except
247
255
logging .error (
248
- f"Exception in extension path { extension_path } : \n { traceback .format_exc ()} "
256
+ "Exception in extension path %s: \n %s" ,
257
+ extension_path ,
258
+ traceback .format_exc (),
249
259
)
250
260
return []
251
261
else :
@@ -270,7 +280,7 @@ def find_extensions(extension_dir: str, module_name="extensions") -> list:
270
280
:rtype: list
271
281
272
282
"""
273
- logging .debug (f "Loading extensions from { extension_dir } " )
283
+ logging .debug ("Loading extensions from %s" , extension_dir )
274
284
275
285
extensions = []
276
286
extension_paths = glob .glob (os .path .join (extension_dir , "*.py" ))
0 commit comments