From 174cda73c3cd04f0be88b9ba047c56334dbc1b82 Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 2 Dec 2019 23:19:46 +0000 Subject: [PATCH] Index plugins by class name instead of module name Also removes case-sensitivity and throws an error if two plugins are called the same name. --- houdini/plugins/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/houdini/plugins/__init__.py b/houdini/plugins/__init__.py index 55a4be5..8b7c4ea 100644 --- a/houdini/plugins/__init__.py +++ b/houdini/plugins/__init__.py @@ -42,13 +42,18 @@ class PluginManager(_AbstractManager): async def load(self, module): plugin_class, plugin_type = inspect.getmembers(module, is_plugin).pop() + plugin_index = plugin_class.lower() - if self.server.server_config['Plugins'] is not True and \ - plugin_class not in self.server.server_config['Plugins']: + if self.server.config.plugins != '*' and \ + plugin_index not in self.server.config.plugins: return plugin_object = plugin_type(self.server) - self[module.__name__] = plugin_object + + if plugin_index in self: + raise KeyError(f'Duplicate plugin name "{plugin_index}" exists') + + self[plugin_index] = plugin_object await self.server.commands.load(plugin_object) await self.server.xt_listeners.load(plugin_object)