Coverage for src/django_resume/plugins/registry.py: 100%
16 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-10-13 13:17 +0200
« prev ^ index » next coverage.py v7.6.1, created at 2024-10-13 13:17 +0200
1from typing import TYPE_CHECKING
3if TYPE_CHECKING:
4 from .base import Plugin
7class PluginRegistry:
8 """
9 A registry for plugins. This is used to register and unregister plugins.
10 """
12 def __init__(self):
13 self.plugins = {}
15 def register(self, plugin_class: type["Plugin"]):
16 """
17 Register a plugin class. This will instantiate the plugin and add it to the registry.
19 It will also add the plugin's inline URLs to the urlpatterns list.
20 """
21 plugin = plugin_class()
22 self.plugins[plugin.name] = plugin
23 from ..urls import urlpatterns
25 urlpatterns.extend(plugin.get_inline_urls())
27 def unregister(self, plugin_class: type["Plugin"]):
28 del self.plugins[plugin_class.name]
30 def get_plugin(self, name):
31 return self.plugins.get(name)
33 def get_all_plugins(self):
34 return self.plugins.values()
37# The global plugin registry - this is a singleton since module level variables are shared across the application.
38plugin_registry = PluginRegistry()