Skip to content

Commit

Permalink
Removed another dependency between pm and rm
Browse files Browse the repository at this point in the history
  • Loading branch information
gbin committed May 28, 2018
1 parent 21c2823 commit e987ab4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 20 deletions.
3 changes: 1 addition & 2 deletions errbot/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion errbot/core_plugins/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def backup(self, msg, args):
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')
Expand Down
2 changes: 1 addition & 1 deletion errbot/core_plugins/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def repos_install(self, _, args):
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}.'
Expand Down
28 changes: 14 additions & 14 deletions errbot/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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
Expand All @@ -21,6 +21,8 @@
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')
Expand Down Expand Up @@ -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
Expand All @@ -148,16 +149,15 @@ def __init__(self,
: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] = {}
Expand Down Expand Up @@ -255,7 +255,12 @@ def _load_plugins(self) -> Dict[Path, str]:
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)
Expand Down Expand Up @@ -335,11 +340,6 @@ def set_plugin_configuration(self, name, obj):
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.
Expand Down
1 change: 0 additions & 1 deletion tests/base_backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ def __init__(self, extra_config=None):
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),
Expand Down
2 changes: 1 addition & 1 deletion tests/commands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit e987ab4

Please sign in to comment.