def load_plugins(self):
"""
Load all plug-ins from a configuration module
"""
plugin_dir = os.path.join(self._path, "plugins")
if not os.path.exists(plugin_dir):
return
if not os.path.exists(os.path.join(plugin_dir, "__init__.py")):
raise CompilerException(
"The plugin directory %s should be a valid python package with a __init__.py file" % plugin_dir)
try:
mod_name = self._meta["name"]
imp.load_package("inmanta_plugins." + mod_name, plugin_dir)
self._plugin_namespaces.append(mod_name)
for py_file in glob.glob(os.path.join(plugin_dir, "*.py")):
if not py_file.endswith("__init__.py"):
# name of the python module
sub_mod = "inmanta_plugins." + mod_name + "." + os.path.basename(py_file).split(".")[0]
self._plugin_namespaces.append(sub_mod)
# load the python file
imp.load_source(sub_mod, py_file)
except ImportError as e:
raise CompilerException("Unable to load all plug-ins for module %s" % self._meta["name"]) from e
评论列表
文章目录