WIP-0004: Django App Plugin Specification¶
Introduction¶
This document proposes a new way to integrate Django applications into the Whitebox backend that is more compatible with using Django and allows a whitebox plugin to extend the Whitebox backend just like any other Django application while ensuring that the plugin is isolated from the rest of the backend.
Approach¶
The approach is to leverage the capabilities of importlib.metadata
's entry_points
function that specifically allows us to discover and load plugin like components registered by installed packages. It's essentially a way to implement plugins or extensions in a standardized way.
Plugins will register an entry point in their pyproject.toml
file under the Poetry’s plugins
section, which is used for defining entry points. It will look something like this:
[tool.poetry.plugins."whitebox.plugin"]
whitebox_plugin_wip_194 = "whitebox_plugin_wip_194.apps:WhiteboxPluginWip194Config"
The Django backend can then discover these entry points when installed like so:
def discover_plugins():
plugin_apps = []
try:
for entry_point in entry_points(group='whitebox.plugin'):
app_config_class = entry_point.load()
app_name = app_config_class.name
plugin_apps.append(app_name)
logger.info(f"Discovered plugin via entry point: {app_name}")
except Exception as e:
logger.warning(f"Error discovering plugins via entry points: {e}")
return plugin_apps
and add them to the INSTALLED_APPS
list in Django settings.
This way ensures that plugins work like any native Django app, allowing us to create models, views, and other components as we would in a normal Django application. It also allows us to leverage Django's built-in features like migrations, admin interface, etc., while keeping the plugin isolated from the rest of the backend.