mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 07:05:41 +00:00 
			
		
		
		
	just run install
This commit is contained in:
		@@ -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?
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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')
 | 
				
			||||||
 | 
					        except subprocess.CalledProcessError as error:  # pragma: no cover
 | 
				
			||||||
 | 
					            logger.error(f'Ran into error while trying to install plugins!\n{str(error)}')
 | 
				
			||||||
 | 
					            return False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for requirement in requirements:
 | 
					        logger.info(f'plugin requirements were run\n{output}')
 | 
				
			||||||
            try:
 | 
					
 | 
				
			||||||
                pkg_resources.require(str(requirement))
 | 
					        # do not run again
 | 
				
			||||||
            except Exception as error:
 | 
					        settings.PLUGIN_FILE_CHECKED = True
 | 
				
			||||||
                handle_error(error, log_name='init', do_raise=False)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # endregion
 | 
					    # endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user