From f37541d8811b814b64f92c73a5f599fb708c57f6 Mon Sep 17 00:00:00 2001 From: ostracon Date: Sat, 27 Jan 2024 08:24:57 +0000 Subject: [PATCH] Get plugin activation order from plugins excluding unwanted core plugins (#1601) * Get plugin activation order from plugins excluding unwanted core plugins * Abstract _is_excluded_core_plugin to check if we should exclude a plugin from loading or activating based on CORE_PLUGINS, and update code to ensure passing tests * style: run black * docs: add info to CHANGES --------- Co-authored-by: Nathaniel Hartley Co-authored-by: Sijis Aviles --- CHANGES.rst | 1 + errbot/plugin_manager.py | 30 ++++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 1c41cf3f1..bc03ff555 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,7 @@ v9.9.9 (unreleased) fixes: - docs: add unreleased section (#1681) +- fix: check only activate plugins listed in CORE_PLUGINS (#1601) v6.2.0 (2024-01-01) ------------------- diff --git a/errbot/plugin_manager.py b/errbot/plugin_manager.py index 6d5490a0a..e49ede6d4 100644 --- a/errbot/plugin_manager.py +++ b/errbot/plugin_manager.py @@ -252,6 +252,18 @@ def _install_potential_package_dependencies( if msg and path not in feedback: # favor the first error. feedback[path] = msg + def _is_excluded_core_plugin(self, plugin_info: PluginInfo) -> bool: + """Check if a plugin should be excluded based on the CORE_PLUGINS config directive""" + if ( + plugin_info + and self.core_plugins + and plugin_info.core + and (plugin_info.name not in self.core_plugins) + ): + return True + else: + return False + def _load_plugins_generic( self, path: Path, @@ -276,11 +288,7 @@ def _load_plugins_generic( dest_info_dict[name] = plugin_info # Skip the core plugins not listed in CORE_PLUGINS if CORE_PLUGINS is defined. - if ( - self.core_plugins - and plugin_info.core - and (plugin_info.name not in self.core_plugins) - ): + if self._is_excluded_core_plugin(plugin_info): log.debug( "%s plugin will not be loaded because it's not listed in CORE_PLUGINS", name, @@ -426,7 +434,7 @@ def set_plugin_configuration(self, name: str, obj: Any): configs[name] = obj self[CONFIGS] = configs - def activate_non_started_plugins(self) -> None: + def activate_non_started_plugins(self) -> str: """ Activates all plugins that are not activated, respecting its dependencies. @@ -435,7 +443,10 @@ def activate_non_started_plugins(self) -> None: log.info("Activate bot plugins...") errors = "" for name in self.get_plugins_activation_order(): + # We need both the plugin and the corresponding PluginInfo to check if we need to skip an excluded core plugin + plugin_info = self.plugin_infos.get(name) plugin = self.plugins.get(name) + try: if self.is_plugin_blacklisted(name): errors += ( @@ -443,6 +454,13 @@ def activate_non_started_plugins(self) -> None: f'use "{self.plugins["Help"]._bot.prefix}plugin unblacklist {name}" to unblacklist it.\n' ) continue + elif self._is_excluded_core_plugin(plugin_info): + log.debug( + "%s plugin will not be activated because it's excluded from CORE_PLUGINS", + name, + ) + continue + if not plugin.is_activated: log.info("Activate plugin: %s.", name) self.activate_plugin(name)