From 777694eb1a0c4c3f3b81b1785ac69dc7b1d102e8 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Thu, 8 Feb 2024 05:55:02 -0800 Subject: [PATCH] add type hints to plugin config models --- archivebox/plugins/defaults/models.py | 27 ++++++++++++++------------- archivebox/plugins/gallerydl/apps.py | 13 +++++++++---- archivebox/plugins/system/apps.py | 3 +-- archivebox/plugins/system/models.py | 24 ++++++++++++------------ 4 files changed, 36 insertions(+), 31 deletions(-) diff --git a/archivebox/plugins/defaults/models.py b/archivebox/plugins/defaults/models.py index f1113d57..9c6d6578 100644 --- a/archivebox/plugins/defaults/models.py +++ b/archivebox/plugins/defaults/models.py @@ -42,20 +42,20 @@ class ArchiveBoxBaseDependency(models.Model): LABEL = "Default" REQUIRED = False - PARENT_DEPENDENCIES = [] + PARENT_DEPENDENCIES: List[str] = [] - BIN_DEPENDENCIES = [] - APT_DEPENDENCIES = [] - BREW_DEPENDENCIES = [] - PIP_DEPENDENCIES = [] - NPM_DEPENDENCIES = [] + BIN_DEPENDENCIES: List[str] = [] + APT_DEPENDENCIES: List[str] = [] + BREW_DEPENDENCIES: List[str] = [] + PIP_DEPENDENCIES: List[str] = [] + NPM_DEPENDENCIES: List[str] = [] - DEFAULT_BINARY = '/bin/bash' - DEFAULT_START_CMD = '/bin/bash -c "while true; do sleep 1; done"' - DEFAULT_PID_FILE = 'logs/{NAME}_WORKER.pid' - DEFAULT_STOP_CMD = 'kill "$(<{PID_FILE})"' - DEFAULT_VERSION_COMMAND = '{BINARY} --version' - DEFAULT_ARGS = '' + DEFAULT_BINARY: str | None = '/bin/bash' + DEFAULT_START_CMD: str | None = '/bin/bash -c "while true; do sleep 1; done"' + DEFAULT_PID_FILE: str | None = 'logs/{NAME}_WORKER.pid' + DEFAULT_STOP_CMD: str | None = 'kill "$(<{PID_FILE})"' + DEFAULT_VERSION_COMMAND: str | None = '{BINARY} --version' + DEFAULT_ARGS: str | None = '' VERSION_CMD = '{BINARY} --version' @@ -136,7 +136,8 @@ class ArchiveBoxBaseDependency(models.Model): # @helper def install_parents(self, config): return { - parent_dependency.NAME: parent_dependency.get_solo().install_self() + # parent_dependency.NAME: parent_dependency.get_solo().install_self() + parent_dependency: parent_dependency for parent_dependency in self.PARENT_DEPENDENCIES } diff --git a/archivebox/plugins/gallerydl/apps.py b/archivebox/plugins/gallerydl/apps.py index 8187202d..cdd25e67 100644 --- a/archivebox/plugins/gallerydl/apps.py +++ b/archivebox/plugins/gallerydl/apps.py @@ -1,8 +1,13 @@ from django.apps import AppConfig -class ReplayWebPageConfig(AppConfig): - label = "ReplayWeb.Page" - name = "plugin_replaywebpage" +class GalleryDLAppConfig(AppConfig): + label = "Gallery-DL" + name = "plugin_gallerydl" - default_auto_field = "django.db.models.BigAutoField" \ No newline at end of file + default_auto_field = "django.db.models.BigAutoField" + + def ready(self): + # querying models is ok, but don't fetch rows from DB or perform stateful actions here + + print('√ Loaded GalleryDL Plugin') diff --git a/archivebox/plugins/system/apps.py b/archivebox/plugins/system/apps.py index dbcf5574..8744859e 100644 --- a/archivebox/plugins/system/apps.py +++ b/archivebox/plugins/system/apps.py @@ -1,4 +1,4 @@ -# __package__ = 'archivebox.plugins.system' +__package__ = 'archivebox.plugins.system' from django.apps import AppConfig @@ -6,7 +6,6 @@ from django.apps import AppConfig class SystemPluginAppConfig(AppConfig): name = "plugins.system" - # label = "ArchiveBox System" verbose_name = "Host System Configuration" default_auto_field = "django.db.models.AutoField" diff --git a/archivebox/plugins/system/models.py b/archivebox/plugins/system/models.py index 6ff609e0..dfcf07b8 100644 --- a/archivebox/plugins/system/models.py +++ b/archivebox/plugins/system/models.py @@ -34,11 +34,11 @@ class BashEnvironmentDependency(ArchiveBoxBaseDependency): PARENT_DEPENDENCIES = [] - BIN_DEPENDENCIES = ['bash'] - APT_DEPENDENCIES = [] - BREW_DEPENDENCIES = [] - PIP_DEPENDENCIES = [] - NPM_DEPENDENCIES = [] + BIN_DEPENDENCIES: List[str] = ['bash'] + APT_DEPENDENCIES: List[str] = [] + BREW_DEPENDENCIES: List[str] = [] + PIP_DEPENDENCIES: List[str] = [] + NPM_DEPENDENCIES: List[str] = [] DEFAULT_BINARY = 'bash' DEFAULT_START_CMD = None @@ -152,7 +152,7 @@ class AptEnvironmentDependency(ArchiveBoxBaseDependency, SingletonModel): LABEL = "apt" REQUIRED = False - PARENT_DEPENDENCIES = [BashEnvironmentDependency] + PARENT_DEPENDENCIES = ['BashEnvironmentDependency'] BIN_DEPENDENCIES = ['apt-get'] APT_DEPENDENCIES = [] @@ -196,7 +196,7 @@ class BrewEnvironmentDependency(ArchiveBoxBaseDependency, SingletonModel): LABEL = "homebrew" REQUIRED = False - PARENT_DEPENDENCIES = [BashEnvironmentDependency] + PARENT_DEPENDENCIES = ['BashEnvironmentDependency'] BIN_DEPENDENCIES = ['brew'] APT_DEPENDENCIES = [] @@ -242,7 +242,7 @@ class PipEnvironmentDependency(ArchiveBoxBaseDependency, SingletonModel): LABEL = "pip" REQUIRED = False - PARENT_DEPENDENCIES = [BashEnvironmentDependency] + PARENT_DEPENDENCIES = ['BashEnvironmentDependency'] BIN_DEPENDENCIES = ['python3', 'pip3'] APT_DEPENDENCIES = ['python3.11', 'pip3', 'pipx'] @@ -285,7 +285,7 @@ class NPMEnvironmentDependency(ArchiveBoxBaseDependency, SingletonModel): LABEL = "NodeJS" REQUIRED = False - PARENT_DEPENDENCIES = [BashEnvironmentDependency] + PARENT_DEPENDENCIES = ['BashEnvironmentDependency'] BIN_DEPENDENCIES = ['node', 'npm'] APT_DEPENDENCIES = ['node', 'npm'] @@ -412,9 +412,9 @@ class ArchiveBoxDependency(ArchiveBoxBaseDependency): REQUIRED = True PARENT_DEPENDENCIES = [ - PipEnvironmentDependency, - DjangoDependency, - SQLiteDependency, + 'PipEnvironmentDependency', + 'DjangoDependency', + 'SQLiteDependency', ] BIN_DEPENDENCIES = ['archivebox']