Skip to content

Commit

Permalink
Get plugin activation order from plugins excluding unwanted core plug…
Browse files Browse the repository at this point in the history
…ins (#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 <[email protected]>
Co-authored-by: Sijis Aviles <[email protected]>
  • Loading branch information
3 people authored Jan 27, 2024
1 parent d5e3ba7 commit f37541d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
-------------------
Expand Down
30 changes: 24 additions & 6 deletions errbot/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -435,14 +443,24 @@ 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 += (
f"Notice: {plugin.name} is blacklisted, "
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)
Expand Down

0 comments on commit f37541d

Please sign in to comment.