just run install

This commit is contained in:
Matthias 2022-03-15 01:24:58 +01:00
parent 38938e892b
commit d9d2f39072
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
3 changed files with 20 additions and 13 deletions

View File

@ -900,3 +900,4 @@ if DEBUG or TESTING:
PLUGIN_TESTING = get_setting('PLUGIN_TESTING', TESTING) # are plugins beeing tested? PLUGIN_TESTING = get_setting('PLUGIN_TESTING', TESTING) # are plugins beeing tested?
PLUGIN_TESTING_SETUP = get_setting('PLUGIN_TESTING_SETUP', False) # load plugins from setup hooks in testing? PLUGIN_TESTING_SETUP = get_setting('PLUGIN_TESTING_SETUP', False) # load plugins from setup hooks in testing?
PLUGIN_RETRY = get_setting('PLUGIN_RETRY', 5) # how often should plugin loading be tried? PLUGIN_RETRY = get_setting('PLUGIN_RETRY', 5) # how often should plugin loading be tried?
PLUGIN_FILE_CHECKED = False # Was the plugin file checked?

View File

@ -30,7 +30,7 @@ class PluginAppConfig(AppConfig):
if not registry.is_loading: if not registry.is_loading:
# this is the first startup # this is the first startup
registry.check_plugin_file() registry.install_plugin_file()
registry.collect_plugins() registry.collect_plugins()
registry.load_plugins() registry.load_plugins()

View File

@ -8,9 +8,10 @@ Registry for loading and managing multiple plugins at run-time
import importlib import importlib
import pathlib import pathlib
import logging import logging
import os
import subprocess
from typing import OrderedDict from typing import OrderedDict
from importlib import reload from importlib import reload
import pkg_resources
from django.apps import apps from django.apps import apps
from django.conf import settings from django.conf import settings
@ -214,21 +215,26 @@ class PluginsRegistry:
logger.info(f'Collected {len(self.plugin_modules)} plugins!') logger.info(f'Collected {len(self.plugin_modules)} plugins!')
logger.info(", ".join([a.__module__ for a in self.plugin_modules])) logger.info(", ".join([a.__module__ for a in self.plugin_modules]))
def check_plugin_file(self): def install_plugin_file(self):
""" """
Check if all plugins are installed in the current enviroment Make sure all plugins are installed in the current enviroment
""" """
# many thanks to Asclepius
# https://stackoverflow.com/questions/16294819/check-if-my-python-has-all-required-packages/45474387#45474387 if settings.PLUGIN_FILE_CHECKED:
logger.info('Plugin file was already checked')
return
plugin_file = pathlib.Path(get_plugin_file()) plugin_file = pathlib.Path(get_plugin_file())
requirements = pkg_resources.parse_requirements(plugin_file.open()) try:
output = str(subprocess.check_output(['pip', 'install', '-r', str(plugin_file.absolute())], cwd=os.path.dirname(settings.BASE_DIR)), 'utf-8')
for requirement in requirements: except subprocess.CalledProcessError as error: # pragma: no cover
try: logger.error(f'Ran into error while trying to install plugins!\n{str(error)}')
pkg_resources.require(str(requirement)) return False
except Exception as error:
handle_error(error, log_name='init', do_raise=False) logger.info(f'plugin requirements were run\n{output}')
# do not run again
settings.PLUGIN_FILE_CHECKED = True
# endregion # endregion