mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-13 22:54:27 -04:00
migrate plugin loading process to new pluggy-powered system based on djp
This commit is contained in:
parent
efd341d8ad
commit
8ed3155ec5
28 changed files with 690 additions and 321 deletions
|
@ -1,11 +1,12 @@
|
|||
__package__ = "archivebox.plugantic"
|
||||
|
||||
import abx
|
||||
from typing import List
|
||||
|
||||
from django.core.checks import Warning, Tags, register
|
||||
|
||||
from .base_hook import BaseHook, HookType
|
||||
from ..config_stubs import AttrDict
|
||||
|
||||
|
||||
class BaseCheck(BaseHook):
|
||||
hook_type: HookType = "CHECK"
|
||||
|
@ -28,21 +29,18 @@ class BaseCheck(BaseHook):
|
|||
def register(self, settings, parent_plugin=None):
|
||||
# self._plugin = parent_plugin # backref to parent is for debugging only, never rely on this!
|
||||
|
||||
self.register_with_django_check_system(settings) # (SIDE EFFECT)
|
||||
abx.pm.hook.register_django_check(check=self, settings=settings)
|
||||
|
||||
# install hook into settings.CHECKS
|
||||
settings.CHECKS = getattr(settings, "CHECKS", None) or AttrDict({})
|
||||
settings.CHECKS[self.id] = self
|
||||
|
||||
# record installed hook in settings.HOOKS
|
||||
super().register(settings, parent_plugin=parent_plugin)
|
||||
|
||||
def register_with_django_check_system(self, settings):
|
||||
def run_check(app_configs, **kwargs) -> List[Warning]:
|
||||
import logging
|
||||
return self.check(settings, logging.getLogger("checks"))
|
||||
@abx.hookspec
|
||||
@abx.hookimpl
|
||||
def register_django_check(check: BaseCheck, settings):
|
||||
def run_check(app_configs, **kwargs) -> List[Warning]:
|
||||
import logging
|
||||
return check.check(settings, logging.getLogger("checks"))
|
||||
|
||||
run_check.__name__ = self.id
|
||||
run_check.tags = [self.tag]
|
||||
register(self.tag)(run_check)
|
||||
run_check.__name__ = check.id
|
||||
run_check.tags = [check.tag]
|
||||
register(check.tag)(run_check)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue