Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get plugin activation order from plugins excluding unwanted core plugins #1601

Merged
merged 4 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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