From dc3f67dbc6c0bdddf0d42a8ad7423f2ffab7b86e Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Mon, 18 Mar 2013 15:48:28 +0000 Subject: [PATCH] [molecule.specs.factory] add support for out of tree plugins, through MOLECULE_PLUGIN_MODULES --- molecule/specs/factory.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/molecule/specs/factory.py b/molecule/specs/factory.py index cfe7688..475d169 100644 --- a/molecule/specs/factory.py +++ b/molecule/specs/factory.py @@ -27,6 +27,9 @@ class PluginFactory: _PLUGIN_SUFFIX = "_plugin" _PYTHON_EXTENSION = ".py" + # A colon separated list of modules to load, looking for + # Molecule plugins. + _PLUGIN_MODULES = os.getenv("MOLECULE_PLUGIN_MODULES") def __init__(self, base_plugin_class, plugin_package_module, default_plugin_name = None, fallback_plugin_name = None, @@ -182,6 +185,7 @@ class PluginFactory: available = {} pkg_modname = self.__plugin_package_module.__name__ mod_dir = os.path.dirname(self.__modfile) + modules = [] for modname in os.listdir(mod_dir): @@ -201,6 +205,14 @@ class PluginFactory: modname_clean = modname[:-len(PluginFactory._PLUGIN_SUFFIX)] modpath = "%s.%s" % (pkg_modname, modname,) + modules.append(modpath) + + + plugin_modules = self._PLUGIN_MODULES + if plugin_modules: + modules.extend(plugin_modules.split(":")) + + for modpath in modules: try: __import__(modpath)