4
4
import inspect
5
5
import importlib
6
6
import typing
7
+ import types
7
8
import warnings
8
9
9
10
import yaml
16
17
SPECIAL_ARGS = ["self" , "app" , "container_settings" , "_call_signature" , "_imports" ]
17
18
18
19
19
- def _get_webviz_plugins (module ) :
20
+ def _get_webviz_plugins (module : types . ModuleType ) -> list :
20
21
"""Returns a list of all Webviz plugins
21
22
in the module given as input.
22
23
"""
23
24
24
- def _is_webviz_plugin (obj ) :
25
+ def _is_webviz_plugin (obj : typing . Any ) -> bool :
25
26
return inspect .isclass (obj ) and issubclass (obj , WebvizPluginABC )
26
27
27
28
return [member [0 ] for member in inspect .getmembers (module , _is_webviz_plugin )]
28
29
29
30
30
31
def _call_signature (
31
- module ,
32
- module_name ,
33
- plugin_name ,
34
- shared_settings ,
35
- kwargs ,
36
- config_folder ,
37
- contact_person = None ,
38
- ):
32
+ module : types . ModuleType ,
33
+ module_name : str ,
34
+ plugin_name : str ,
35
+ shared_settings : dict ,
36
+ kwargs : dict ,
37
+ config_folder : pathlib . Path ,
38
+ contact_person : typing . Optional [ dict ] = None ,
39
+ ) -> tuple :
39
40
# pylint: disable=too-many-branches,too-many-statements
40
41
"""Takes as input the name of a plugin, the module it is located in,
41
42
together with user given arguments (originating from the configuration
@@ -158,7 +159,7 @@ class ConfigParser:
158
159
159
160
STANDARD_PLUGINS = _get_webviz_plugins (standard_plugins )
160
161
161
- def __init__ (self , yaml_file ):
162
+ def __init__ (self , yaml_file : str ):
162
163
163
164
ConfigParser .check_for_tabs_in_file (yaml_file )
164
165
@@ -181,12 +182,12 @@ def __init__(self, yaml_file):
181
182
).with_traceback (sys .exc_info ()[2 ])
182
183
183
184
self ._config_folder = pathlib .Path (yaml_file ).parent
184
- self ._page_ids = []
185
- self ._assets = set ()
185
+ self ._page_ids : typing . List [ str ] = []
186
+ self ._assets : set = set ()
186
187
self .clean_configuration ()
187
188
188
189
@staticmethod
189
- def check_for_tabs_in_file (path ) :
190
+ def check_for_tabs_in_file (path : str ) -> None :
190
191
191
192
with open (path , "r" ) as filehandle :
192
193
# Create a list with unique entries of line numbers containing tabs
@@ -209,7 +210,7 @@ def check_for_tabs_in_file(path):
209
210
f"{ terminal_colors .END } "
210
211
)
211
212
212
- def _generate_page_id (self , title ) :
213
+ def _generate_page_id (self , title : str ) -> str :
213
214
"""From the user given title, this function provides a unique
214
215
human readable page id, not already present in self._page_ids
215
216
"""
@@ -225,7 +226,7 @@ def _generate_page_id(self, title):
225
226
226
227
return page_id
227
228
228
- def clean_configuration (self ):
229
+ def clean_configuration (self ) -> None :
229
230
# pylint: disable=too-many-branches,too-many-statements
230
231
"""Various cleaning and checks of the raw configuration read
231
232
from the user provided yaml configuration file.
@@ -372,13 +373,13 @@ def clean_configuration(self):
372
373
self .assets .update (getattr (module , plugin_name ).ASSETS )
373
374
374
375
@property
375
- def configuration (self ):
376
+ def configuration (self ) -> dict :
376
377
return self ._configuration
377
378
378
379
@property
379
- def shared_settings (self ):
380
+ def shared_settings (self ) -> dict :
380
381
return self ._shared_settings
381
382
382
383
@property
383
- def assets (self ):
384
+ def assets (self ) -> set :
384
385
return self ._assets
0 commit comments