From f72bae8eecbfc801a3fc8790764f3eb32c9fb9fa Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Fri, 17 May 2024 20:48:11 -0700 Subject: [PATCH] autodiscover plugins on startup --- archivebox/core/settings.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/archivebox/core/settings.py b/archivebox/core/settings.py index 41a5eda9..870c5681 100644 --- a/archivebox/core/settings.py +++ b/archivebox/core/settings.py @@ -55,6 +55,26 @@ APPEND_SLASH = True DEBUG = DEBUG or ('--debug' in sys.argv) + +# add plugins folders to system path, and load plugins in installed_apps +BUILTIN_PLUGINS_DIR = PACKAGE_DIR / 'plugins' +USER_PLUGINS_DIR = OUTPUT_DIR / 'plugins' +sys.path.insert(0, str(BUILTIN_PLUGINS_DIR)) +sys.path.insert(0, str(USER_PLUGINS_DIR)) + +def find_plugins(plugins_dir): + return { + # plugin_entrypoint.parent.name: import_module(plugin_entrypoint.parent.name).METADATA + plugin_entrypoint.parent.name: plugin_entrypoint.parent + for plugin_entrypoint in plugins_dir.glob('*/apps.py') + } + +INSTALLED_PLUGINS = { + **find_plugins(BUILTIN_PLUGINS_DIR), + **find_plugins(USER_PLUGINS_DIR), +} + + INSTALLED_APPS = [ 'django.contrib.auth', 'django.contrib.contenttypes', @@ -70,6 +90,8 @@ INSTALLED_APPS = [ 'core', 'api', + *INSTALLED_PLUGINS.keys(), + 'admin_data_views', 'django_extensions',