diff options
| author | Zuul <zuul@review.opendev.org> | 2020-07-07 06:23:55 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2020-07-07 06:23:55 +0000 |
| commit | 42692264f7089b99e9db627ba7a1f961d829e03b (patch) | |
| tree | a128a52cb9c94af94d780d6fe598d6dfac54804d /openstackclient | |
| parent | d0741d78533ae5f538f3f0be0a8a0035581745cc (diff) | |
| parent | 870cf0114848f145f15a78415e3f4203c6338cd1 (diff) | |
| download | python-openstackclient-42692264f7089b99e9db627ba7a1f961d829e03b.tar.gz | |
Merge "switch to stevedore for entry points"
Diffstat (limited to 'openstackclient')
| -rw-r--r-- | openstackclient/common/clientmanager.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/openstackclient/common/clientmanager.py b/openstackclient/common/clientmanager.py index c1118ad3..66dc880e 100644 --- a/openstackclient/common/clientmanager.py +++ b/openstackclient/common/clientmanager.py @@ -15,12 +15,13 @@ """Manage access to the clients, including authenticating when needed.""" +import importlib import logging import sys from osc_lib import clientmanager from osc_lib import shell -import pkg_resources +import stevedore LOG = logging.getLogger(__name__) @@ -143,17 +144,25 @@ class ClientManager(clientmanager.ClientManager): def get_plugin_modules(group): """Find plugin entry points""" mod_list = [] - for ep in pkg_resources.iter_entry_points(group): + mgr = stevedore.ExtensionManager(group) + for ep in mgr: LOG.debug('Found plugin %s', ep.name) + # Different versions of stevedore use different + # implementations of EntryPoint from other libraries, which + # are not API-compatible. try: - __import__(ep.module_name) - except Exception: + module_name = ep.entry_point.module_name + except AttributeError: + module_name = ep.entry_point.module + + try: + module = importlib.import_module(module_name) + except Exception as err: sys.stderr.write( - "WARNING: Failed to import plugin %s.\n" % ep.name) + "WARNING: Failed to import plugin %s: %s.\n" % (ep.name, err)) continue - module = sys.modules[ep.module_name] mod_list.append(module) init_func = getattr(module, 'Initialize', None) if init_func: @@ -164,7 +173,7 @@ def get_plugin_modules(group): clientmanager.ClientManager, module.API_NAME, clientmanager.ClientCache( - getattr(sys.modules[ep.module_name], 'make_client', None) + getattr(sys.modules[module_name], 'make_client', None) ), ) return mod_list |
