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,6 +40,7 @@ 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)
|
||||
|
@ -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] = []
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue