Test and enforce proper import plugin order in debug mode
This commit is contained in:
parent
90fee9788d
commit
1d4ab8833b
2 changed files with 14 additions and 2 deletions
|
@ -40,11 +40,12 @@ class PluginManager:
|
||||||
|
|
||||||
# Load all plugin
|
# Load all plugin
|
||||||
def loadPlugins(self):
|
def loadPlugins(self):
|
||||||
|
all_loaded = True
|
||||||
s = time.time()
|
s = time.time()
|
||||||
for dir_name in sorted(os.listdir(self.plugin_path)):
|
for dir_name in sorted(os.listdir(self.plugin_path)):
|
||||||
dir_path = os.path.join(self.plugin_path, dir_name)
|
dir_path = os.path.join(self.plugin_path, dir_name)
|
||||||
if dir_name == "__pycache__":
|
if dir_name == "__pycache__":
|
||||||
continue # skip
|
continue # skip
|
||||||
if dir_name.startswith("disabled"):
|
if dir_name.startswith("disabled"):
|
||||||
continue # Dont load if disabled
|
continue # Dont load if disabled
|
||||||
if not os.path.isdir(dir_path):
|
if not os.path.isdir(dir_path):
|
||||||
|
@ -56,12 +57,14 @@ class PluginManager:
|
||||||
__import__(dir_name)
|
__import__(dir_name)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
self.log.error("Plugin %s load error: %s" % (dir_name, Debug.formatException(err)))
|
self.log.error("Plugin %s load error: %s" % (dir_name, Debug.formatException(err)))
|
||||||
|
all_loaded = False
|
||||||
if dir_name not in self.plugin_names:
|
if dir_name not in self.plugin_names:
|
||||||
self.plugin_names.append(dir_name)
|
self.plugin_names.append(dir_name)
|
||||||
|
|
||||||
self.log.debug("Plugins loaded in %.3fs" % (time.time() - s))
|
self.log.debug("Plugins loaded in %.3fs" % (time.time() - s))
|
||||||
for func in self.after_load:
|
for func in self.after_load:
|
||||||
func()
|
func()
|
||||||
|
return all_loaded
|
||||||
|
|
||||||
# Reload all plugins
|
# Reload all plugins
|
||||||
def reloadPlugins(self):
|
def reloadPlugins(self):
|
||||||
|
@ -153,6 +156,13 @@ def acceptPlugins(base_class):
|
||||||
|
|
||||||
# Register plugin to class name decorator
|
# Register plugin to class name decorator
|
||||||
def registerTo(class_name):
|
def registerTo(class_name):
|
||||||
|
if config.debug:
|
||||||
|
import gc
|
||||||
|
for obj in gc.get_objects():
|
||||||
|
if type(obj).__name__ == class_name:
|
||||||
|
raise Exception("Class %s instances already present in memory" % class_name)
|
||||||
|
break
|
||||||
|
|
||||||
plugin_manager.log.debug("New plugin registered to: %s" % class_name)
|
plugin_manager.log.debug("New plugin registered to: %s" % class_name)
|
||||||
if class_name not in plugin_manager.plugins:
|
if class_name not in plugin_manager.plugins:
|
||||||
plugin_manager.plugins[class_name] = []
|
plugin_manager.plugins[class_name] = []
|
||||||
|
|
|
@ -78,7 +78,9 @@ config.data_dir = TEST_DATA_PATH # Use test data for unittests
|
||||||
|
|
||||||
os.chdir(os.path.abspath(os.path.dirname(__file__) + "/../..")) # Set working dir
|
os.chdir(os.path.abspath(os.path.dirname(__file__) + "/../..")) # Set working dir
|
||||||
|
|
||||||
PluginManager.plugin_manager.loadPlugins()
|
all_loaded = PluginManager.plugin_manager.loadPlugins()
|
||||||
|
assert all_loaded, "There was error loading plugins"
|
||||||
|
|
||||||
config.loadPlugins()
|
config.loadPlugins()
|
||||||
config.parse() # Parse again to add plugin configuration options
|
config.parse() # Parse again to add plugin configuration options
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue