Commit e987ab41 authored by Guillaume Binet's avatar Guillaume Binet

Removed another dependency between pm and rm

parent 21c28235
......@@ -141,7 +141,6 @@ def setup_bot(backend_name: str, logger, config, restore=None) -> ErrBot:
try:
bot = backendpm.load_plugin()
botpm = BotPluginManager(storage_plugin,
repo_manager,
config.BOT_EXTRA_PLUGIN_DIR,
config.AUTOINSTALL_DEPS,
getattr(config, 'CORE_PLUGINS', None),
......@@ -163,7 +162,7 @@ def setup_bot(backend_name: str, logger, config, restore=None) -> ErrBot:
print('Restore complete. You can restart the bot normally')
sys.exit(0)
errors = bot.plugin_manager.update_dynamic_plugins()
errors = bot.plugin_manager.update_plugin_places(repo_manager.get_all_repos_paths())
if errors:
log.error('Some plugins failed to load:\n' + '\n'.join(errors.values()))
bot._plugin_errors_during_startup = "\n".join(errors.values())
......
......@@ -27,7 +27,7 @@ class Backup(BotPlugin):
f.write(' log.error(bot.repo_manager.install_repo(repo))\n')
f.write('log.info("Restoring plugins data.")\n')
f.write('bot.plugin_manager.update_dynamic_plugins()\n')
f.write('bot.plugin_manager.update_plugin_places(bot.repo_manager.get_all_repos_paths())\n')
for plugin in self._bot.plugin_manager.plugins.values():
if plugin._store:
f.write('pobj = bot.plugin_manager.plugins["' + plugin.name + '"]\n')
......
......@@ -25,7 +25,7 @@ class Plugins(BotPlugin):
try:
yield f'Installing {args}...'
local_path = self._bot.repo_manager.install_repo(args)
errors = self._bot.plugin_manager.update_dynamic_plugins()
errors = self._bot.plugin_manager.update_plugin_places(self._bot.repo_manager.get_all_repos_paths())
if errors:
v = '\n'.join(errors.values())
yield f'Some plugins are generating errors:\n{v}.'
......
......@@ -11,7 +11,7 @@ from pathlib import Path
from typing import Tuple, Dict, Any, Type, Set, List, Optional, Callable
from errbot.flow import BotFlow, Flow
from errbot.repo_manager import BotRepoManager, check_dependencies
from errbot.repo_manager import check_dependencies
from errbot.storage.base import StoragePluginBase
from .botplugin import BotPlugin
from .plugin_info import PluginInfo
......@@ -21,6 +21,8 @@ from .version import VERSION
from .core_plugins.wsview import route
from .storage import StoreMixin
PluginInstanceCallback = Callable[[str, Type[BotPlugin]], BotPlugin]
log = logging.getLogger(__name__)
CORE_PLUGINS = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'core_plugins')
......@@ -131,11 +133,10 @@ class BotPluginManager(StoreMixin):
def __init__(self,
storage_plugin: StoragePluginBase,
repo_manager: BotRepoManager,
extra_plugin_dir: Optional[str],
autoinstall_deps: bool,
core_plugins: Tuple[str, ...],
plugin_instance_callback: Callable[[str, Type[BotPlugin]], BotPlugin],
plugin_instance_callback: PluginInstanceCallback,
plugins_callback_order: Tuple[Optional[str], ...]):
"""
Creates a Plugin manager
......@@ -148,16 +149,15 @@ class BotPluginManager(StoreMixin):
:param plugins_callback_order: the order on which the plugins will be callbacked
"""
super().__init__()
self.autoinstall_deps = autoinstall_deps
self._extra_plugin_dir = extra_plugin_dir
self._plugin_instance_callback = plugin_instance_callback
self.core_plugins = core_plugins
self.autoinstall_deps: bool = autoinstall_deps
self._extra_plugin_dir: str = extra_plugin_dir
self._plugin_instance_callback: PluginInstanceCallback = plugin_instance_callback
self.core_plugins: Tuple[str, ...] = core_plugins
# Make sure there is a 'None' entry in the callback order, to include
# any plugin not explicitly ordered.
self.plugins_callback_order = plugins_callback_order
if None not in self.plugins_callback_order:
self.plugins_callback_order += (None,)
self.repo_manager = repo_manager
self.plugin_infos: Dict[str, PluginInfo] = {}
self.plugins: Dict[str, BotPlugin] = {}
self.flow_infos: Dict[str, PluginInfo] = {}
......@@ -255,7 +255,12 @@ class BotPluginManager(StoreMixin):
self.flows, self.flow_infos, feedback)
return feedback
def _update_plugin_places(self, path_list) -> Dict[Path, str]:
def update_plugin_places(self, path_list) -> Dict[Path, str]:
"""
This updates where this manager is trying to find plugins and try to load newly found ones.
:param path_list: the path list where to search for plugins.
:return: the feedback for any specific path in case of error.
"""
repo_roots = (CORE_PLUGINS, self._extra_plugin_dir, path_list)
all_roots = collect_roots(repo_roots)
......@@ -335,11 +340,6 @@ class BotPluginManager(StoreMixin):
configs[name] = obj
self[CONFIGS] = configs
# this will load the plugins the admin has setup at runtime
def update_dynamic_plugins(self):
""" It returns a dictionary of path -> error strings."""
return self._update_plugin_places(self.repo_manager.get_all_repos_paths())
def activate_non_started_plugins(self):
"""
Activates all plugins that are not activated, respecting its dependencies.
......
......@@ -106,7 +106,6 @@ class DummyBackend(ErrBot):
self.attach_storage_plugin(storage_plugin)
self.attach_repo_manager(repo_manager)
self.attach_plugin_manager(BotPluginManager(storage_plugin,
repo_manager,
config.BOT_EXTRA_PLUGIN_DIR,
config.AUTOINSTALL_DEPS,
getattr(config, 'CORE_PLUGINS', None),
......
......@@ -331,7 +331,7 @@ def test_callback_no_command(testbot):
testbot.exec_command('!plugin deactivate CommandNotFoundFilter')
testbot.bot.plugin_manager._extra_plugin_dir = extra_plugin_dir
testbot.bot.plugin_manager._update_plugin_places([])
testbot.bot.plugin_manager.update_plugin_places([])
testbot.exec_command('!plugin activate TestCommandNotFoundFilter')
assert expected_str == testbot.exec_command(cmd)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment