@@ -125,9 +125,11 @@ def init(self, context: Context, config: Config) -> None:
125125
126126 def reload (self , context : Context , config : Config ) -> None :
127127 """Reinitialize all the plugins with updated config."""
128+ plugin_ids : set [str ] = set ()
128129 # Load the plugins
129130 for plugin in config .get ("plugins" ):
130131 plugin_id = plugin ["id" ]
132+ plugin_ids .add (plugin_id )
131133 if plugin_id in self .__plugins :
132134 self .__plugins [plugin_id ].reload_config (plugin )
133135 else :
@@ -144,6 +146,11 @@ def reload(self, context: Context, config: Config) -> None:
144146 traceback .print_exc ()
145147 logging .error ("Error in loading the plugin %s: %s" , plugin ["id" ], e )
146148 continue
149+
150+ removed_plugins = set (self .__plugins .keys ()).difference (plugin_ids )
151+ for plugin_id in removed_plugins :
152+ self .__plugins [plugin_id ].disable ()
153+
147154 # Initialize the plugins
148155 for plugin in self .__plugins .values ():
149156 plugin .init_plugin (context , config )
@@ -318,15 +325,7 @@ def __init__(self, plugin: dict) -> None:
318325
319326 def reload_config (self , plugin : dict ) -> None :
320327 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" ])
328+ self .disable ()
330329 return
331330
332331 if not self .enabled and plugin ["enabled" ]:
@@ -353,6 +352,17 @@ def reload_config(self, plugin: dict) -> None:
353352 # No longer errored, import the module now
354353 self ._import_plugin ()
355354
355+ def disable (self ) -> None :
356+ if self .enabled :
357+ self .enabled = False
358+ if (
359+ not self .errored
360+ and self .module is not None
361+ and utility .has_method (self .module , "disable" )
362+ ):
363+ self .module .disable ()
364+ logging .info ("Successfully unloaded the plugin '%s'" , self .id )
365+
356366 def reload_errored (self ) -> None :
357367 if not self .errored :
358368 return
0 commit comments