Test and enforce proper import plugin order in debug mode

This commit is contained in:
shortcutme 2019-04-15 22:18:18 +02:00
parent 90fee9788d
commit 1d4ab8833b
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
2 changed files with 14 additions and 2 deletions

View File

@ -40,11 +40,12 @@ class PluginManager:
# Load all plugin
def loadPlugins(self):
all_loaded = True
s = time.time()
for dir_name in sorted(os.listdir(self.plugin_path)):
dir_path = os.path.join(self.plugin_path, dir_name)
if dir_name == "__pycache__":
continue # skip
continue # skip
if dir_name.startswith("disabled"):
continue # Dont load if disabled
if not os.path.isdir(dir_path):
@ -56,12 +57,14 @@ class PluginManager:
__import__(dir_name)
except Exception as 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:
self.plugin_names.append(dir_name)
self.log.debug("Plugins loaded in %.3fs" % (time.time() - s))
for func in self.after_load:
func()
return all_loaded
# Reload all plugins
def reloadPlugins(self):
@ -153,6 +156,13 @@ def acceptPlugins(base_class):
# Register plugin to class name decorator
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)
if class_name not in plugin_manager.plugins:
plugin_manager.plugins[class_name] = []

View File

@ -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
PluginManager.plugin_manager.loadPlugins()
all_loaded = PluginManager.plugin_manager.loadPlugins()
assert all_loaded, "There was error loading plugins"
config.loadPlugins()
config.parse() # Parse again to add plugin configuration options