i have below openstack rally code dynamically loading python modules given path using below function.
def load_plugins(dir_or_file): if os.path.isdir(dir_or_file): directory = dir_or_file log.info(_("loading plugins directories %s/*") % directory.rstrip("/")) to_load = [] root, dirs, files in os.walk(directory, followlinks=true): to_load.extend((plugin[:-3], root) plugin in files if plugin.endswith(".py")) plugin, directory in to_load: if directory not in sys.path: sys.path.append(directory) fullpath = os.path.join(directory, plugin) try: fp, pathname, descr = imp.find_module(plugin, [directory]) imp.load_module(plugin, fp, pathname, descr) fp.close() log.info(_("\t loaded module plugins: %s.py") % fullpath) except exception e: log.warning( "\t failed load module plugins %(path)s.py: %(e)s" % {"path": fullpath, "e": e}) if logging.is_debug(): log.exception(e) elif os.path.isfile(dir_or_file): plugin_file = dir_or_file log.info(_("loading plugins file %s") % plugin_file) if plugin_file not in sys.path: sys.path.append(plugin_file) try: plugin_name = os.path.splitext(plugin_file.split("/")[-1])[0] imp.load_source(plugin_name, plugin_file) log.info(_("\t loaded module plugins: %s.py") % plugin_name) except exception e: log.warning(_( "\t failed load module plugins %(path)s: %(e)s") % {"path": plugin_file, "e": e}) if logging.is_debug(): log.exception(e)
this working absolutely fine till 2 days ago. not getting error not loading classes well. first log information printed , getting printed , while looking loaded classes fails. below ensure_plugins_are_loaded internally calling above function.
file "<decorator-gen-3>", line 2, in _run file "build/bdist.linux-x86_64/egg/rally/plugins/__init__.py", in ensure_plugins_are_loaded file "build/bdist.linux-x86_64/egg/rally/task/engine.py", in validate
update 1
i tried calling simple importlib.import_module('/opt/plugins'). still not error thrown import_module python still can't find loaded modules. trying find modules using subs = cls.subclasses() extends given subclass.
update 2
i tried use same code without creating bdist_egg package. did
python setup.py develop
and works fine. not sure problem when using bdist_egg.
Comments
Post a Comment