Skip to content

Commit e987ab4

Browse files
committed
Removed another dependency between pm and rm
1 parent 21c2823 commit e987ab4

File tree

6 files changed

+18
-20
lines changed

6 files changed

+18
-20
lines changed

errbot/bootstrap.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ def setup_bot(backend_name: str, logger, config, restore=None) -> ErrBot:
141141
try:
142142
bot = backendpm.load_plugin()
143143
botpm = BotPluginManager(storage_plugin,
144-
repo_manager,
145144
config.BOT_EXTRA_PLUGIN_DIR,
146145
config.AUTOINSTALL_DEPS,
147146
getattr(config, 'CORE_PLUGINS', None),
@@ -163,7 +162,7 @@ def setup_bot(backend_name: str, logger, config, restore=None) -> ErrBot:
163162
print('Restore complete. You can restart the bot normally')
164163
sys.exit(0)
165164

166-
errors = bot.plugin_manager.update_dynamic_plugins()
165+
errors = bot.plugin_manager.update_plugin_places(repo_manager.get_all_repos_paths())
167166
if errors:
168167
log.error('Some plugins failed to load:\n' + '\n'.join(errors.values()))
169168
bot._plugin_errors_during_startup = "\n".join(errors.values())

errbot/core_plugins/backup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def backup(self, msg, args):
2727
f.write(' log.error(bot.repo_manager.install_repo(repo))\n')
2828

2929
f.write('log.info("Restoring plugins data.")\n')
30-
f.write('bot.plugin_manager.update_dynamic_plugins()\n')
30+
f.write('bot.plugin_manager.update_plugin_places(bot.repo_manager.get_all_repos_paths())\n')
3131
for plugin in self._bot.plugin_manager.plugins.values():
3232
if plugin._store:
3333
f.write('pobj = bot.plugin_manager.plugins["' + plugin.name + '"]\n')

errbot/core_plugins/plugins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def repos_install(self, _, args):
2525
try:
2626
yield f'Installing {args}...'
2727
local_path = self._bot.repo_manager.install_repo(args)
28-
errors = self._bot.plugin_manager.update_dynamic_plugins()
28+
errors = self._bot.plugin_manager.update_plugin_places(self._bot.repo_manager.get_all_repos_paths())
2929
if errors:
3030
v = '\n'.join(errors.values())
3131
yield f'Some plugins are generating errors:\n{v}.'

errbot/plugin_manager.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from typing import Tuple, Dict, Any, Type, Set, List, Optional, Callable
1212

1313
from errbot.flow import BotFlow, Flow
14-
from errbot.repo_manager import BotRepoManager, check_dependencies
14+
from errbot.repo_manager import check_dependencies
1515
from errbot.storage.base import StoragePluginBase
1616
from .botplugin import BotPlugin
1717
from .plugin_info import PluginInfo
@@ -21,6 +21,8 @@
2121
from .core_plugins.wsview import route
2222
from .storage import StoreMixin
2323

24+
PluginInstanceCallback = Callable[[str, Type[BotPlugin]], BotPlugin]
25+
2426
log = logging.getLogger(__name__)
2527

2628
CORE_PLUGINS = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'core_plugins')
@@ -131,11 +133,10 @@ class BotPluginManager(StoreMixin):
131133

132134
def __init__(self,
133135
storage_plugin: StoragePluginBase,
134-
repo_manager: BotRepoManager,
135136
extra_plugin_dir: Optional[str],
136137
autoinstall_deps: bool,
137138
core_plugins: Tuple[str, ...],
138-
plugin_instance_callback: Callable[[str, Type[BotPlugin]], BotPlugin],
139+
plugin_instance_callback: PluginInstanceCallback,
139140
plugins_callback_order: Tuple[Optional[str], ...]):
140141
"""
141142
Creates a Plugin manager
@@ -148,16 +149,15 @@ def __init__(self,
148149
:param plugins_callback_order: the order on which the plugins will be callbacked
149150
"""
150151
super().__init__()
151-
self.autoinstall_deps = autoinstall_deps
152-
self._extra_plugin_dir = extra_plugin_dir
153-
self._plugin_instance_callback = plugin_instance_callback
154-
self.core_plugins = core_plugins
152+
self.autoinstall_deps: bool = autoinstall_deps
153+
self._extra_plugin_dir: str = extra_plugin_dir
154+
self._plugin_instance_callback: PluginInstanceCallback = plugin_instance_callback
155+
self.core_plugins: Tuple[str, ...] = core_plugins
155156
# Make sure there is a 'None' entry in the callback order, to include
156157
# any plugin not explicitly ordered.
157158
self.plugins_callback_order = plugins_callback_order
158159
if None not in self.plugins_callback_order:
159160
self.plugins_callback_order += (None,)
160-
self.repo_manager = repo_manager
161161
self.plugin_infos: Dict[str, PluginInfo] = {}
162162
self.plugins: Dict[str, BotPlugin] = {}
163163
self.flow_infos: Dict[str, PluginInfo] = {}
@@ -255,7 +255,12 @@ def _load_plugins(self) -> Dict[Path, str]:
255255
self.flows, self.flow_infos, feedback)
256256
return feedback
257257

258-
def _update_plugin_places(self, path_list) -> Dict[Path, str]:
258+
def update_plugin_places(self, path_list) -> Dict[Path, str]:
259+
"""
260+
This updates where this manager is trying to find plugins and try to load newly found ones.
261+
:param path_list: the path list where to search for plugins.
262+
:return: the feedback for any specific path in case of error.
263+
"""
259264
repo_roots = (CORE_PLUGINS, self._extra_plugin_dir, path_list)
260265

261266
all_roots = collect_roots(repo_roots)
@@ -335,11 +340,6 @@ def set_plugin_configuration(self, name, obj):
335340
configs[name] = obj
336341
self[CONFIGS] = configs
337342

338-
# this will load the plugins the admin has setup at runtime
339-
def update_dynamic_plugins(self):
340-
""" It returns a dictionary of path -> error strings."""
341-
return self._update_plugin_places(self.repo_manager.get_all_repos_paths())
342-
343343
def activate_non_started_plugins(self):
344344
"""
345345
Activates all plugins that are not activated, respecting its dependencies.

tests/base_backend_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ def __init__(self, extra_config=None):
106106
self.attach_storage_plugin(storage_plugin)
107107
self.attach_repo_manager(repo_manager)
108108
self.attach_plugin_manager(BotPluginManager(storage_plugin,
109-
repo_manager,
110109
config.BOT_EXTRA_PLUGIN_DIR,
111110
config.AUTOINSTALL_DEPS,
112111
getattr(config, 'CORE_PLUGINS', None),

tests/commands_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def test_callback_no_command(testbot):
331331

332332
testbot.exec_command('!plugin deactivate CommandNotFoundFilter')
333333
testbot.bot.plugin_manager._extra_plugin_dir = extra_plugin_dir
334-
testbot.bot.plugin_manager._update_plugin_places([])
334+
testbot.bot.plugin_manager.update_plugin_places([])
335335
testbot.exec_command('!plugin activate TestCommandNotFoundFilter')
336336
assert expected_str == testbot.exec_command(cmd)
337337

0 commit comments

Comments
 (0)