From 035627c1907e0455800c8cbf5c5f0d419c313ff8 Mon Sep 17 00:00:00 2001 From: Nathaniel Hartley Date: Thu, 22 Sep 2022 19:40:55 +0100 Subject: [PATCH 1/4] Get plugin activation order from plugins excluding unwanted core plugins --- errbot/plugin_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/errbot/plugin_manager.py b/errbot/plugin_manager.py index 6d5490a0a..24ee6c146 100644 --- a/errbot/plugin_manager.py +++ b/errbot/plugin_manager.py @@ -468,7 +468,7 @@ def get_plugins_activation_order(self) -> List[str]: :return: list of plugin names, in the best order to start them. """ plugins_graph = { - name: set(info.dependencies) for name, info in self.plugin_infos.items() + name: set(info.dependencies) for name, info in self.plugins.items() } plugins_in_cycle = set() while True: From 33e393d33e36b3452a25ac2b111639f68e5aa19c Mon Sep 17 00:00:00 2001 From: Nathaniel Hartley Date: Fri, 23 Sep 2022 11:21:22 +0100 Subject: [PATCH 2/4] 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 --- errbot/plugin_manager.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/errbot/plugin_manager.py b/errbot/plugin_manager.py index 24ee6c146..35b4a8c60 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) @@ -468,7 +486,7 @@ def get_plugins_activation_order(self) -> List[str]: :return: list of plugin names, in the best order to start them. """ plugins_graph = { - name: set(info.dependencies) for name, info in self.plugins.items() + name: set(info.dependencies) for name, info in self.plugin_infos.items() } plugins_in_cycle = set() while True: From 4d9d04ea74dc565c98282785858aba30ca2d91b3 Mon Sep 17 00:00:00 2001 From: Sijis Aviles Date: Sat, 27 Jan 2024 02:13:39 -0600 Subject: [PATCH 3/4] style: run black --- errbot/plugin_manager.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/errbot/plugin_manager.py b/errbot/plugin_manager.py index 35b4a8c60..e49ede6d4 100644 --- a/errbot/plugin_manager.py +++ b/errbot/plugin_manager.py @@ -255,10 +255,10 @@ def _install_potential_package_dependencies( 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) + plugin_info + and self.core_plugins + and plugin_info.core + and (plugin_info.name not in self.core_plugins) ): return True else: From 5cc6bccd98e4617bc139f6fd52a16cfff58156db Mon Sep 17 00:00:00 2001 From: Sijis Aviles Date: Sat, 27 Jan 2024 02:17:12 -0600 Subject: [PATCH 4/4] docs: add info to CHANGES --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) 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) -------------------