@@ -123,6 +123,31 @@ def init(self, context: Context, config: Config) -> None:
123123 for plugin in self .__plugins .values ():
124124 plugin .init_plugin (context , config )
125125
126+ def reload (self , context : Context , config : Config ) -> None :
127+ """Reinitialize all the plugins with updated config."""
128+ # Load the plugins
129+ for plugin in config .get ("plugins" ):
130+ plugin_id = plugin ["id" ]
131+ if plugin_id in self .__plugins :
132+ self .__plugins [plugin_id ].reload_config (plugin )
133+ else :
134+ try :
135+ loaded_plugin = LoadedPlugin (plugin )
136+ self .__plugins [loaded_plugin .id ] = loaded_plugin
137+ except BaseException as e :
138+ traceback_wanted = (
139+ logging .getLogger ().getEffectiveLevel () == logging .DEBUG
140+ )
141+ if traceback_wanted :
142+ import traceback
143+
144+ traceback .print_exc ()
145+ logging .error ("Error in loading the plugin %s: %s" , plugin ["id" ], e )
146+ continue
147+ # Initialize the plugins
148+ for plugin in self .__plugins .values ():
149+ plugin .init_plugin (context , config )
150+
126151 def needs_retry (self ) -> bool :
127152 return self .get_retryable_error () is not None
128153
@@ -292,14 +317,17 @@ def __init__(self, plugin: dict) -> None:
292317 self ._import_plugin ()
293318
294319 def reload_config (self , plugin : dict ) -> None :
295- if self .enabled and not plugin ["enabled" ]:
296- self .enabled = False
297- if (
298- not self .errored
299- and self .module is not None
300- and utility .has_method (self .module , "disable" )
301- ):
302- self .module .disable ()
320+ if not plugin ["enabled" ]:
321+ if self .enabled :
322+ self .enabled = False
323+ if (
324+ not self .errored
325+ and self .module is not None
326+ and utility .has_method (self .module , "disable" )
327+ ):
328+ self .module .disable ()
329+ logging .info ("Successfully unloaded the plugin '%s'" , plugin ["id" ])
330+ return
303331
304332 if not self .enabled and plugin ["enabled" ]:
305333 self .enabled = True
0 commit comments