diff options
| author | Doug Hellmann <doug@doughellmann.com> | 2020-07-05 15:51:53 -0400 |
|---|---|---|
| committer | Doug Hellmann <doug@doughellmann.com> | 2020-07-05 15:51:53 -0400 |
| commit | 37f6a3079434186a534864b8a3e919232f56ff27 (patch) | |
| tree | f85022fd7f17af4e5fb849afa9d0f94d1a70c4a6 /cinderclient/utils.py | |
| parent | b6b308ed23b5b3d9ddd8aa946a31edec6b35cbe4 (diff) | |
| download | python-cinderclient-37f6a3079434186a534864b8a3e919232f56ff27.tar.gz | |
use stevedore to load util plugins
Importing pkg_resources has a side-effect of scanning all of the
installed python modules looking for entrypoints to build an in-memory
cache. Stevedore will be adding an on-disk cache to speed that process
up, which should provide significant performance benefits for client
applications such as python-openstackclient. This change introduces
stevedore to replace pkg_resources.
Change-Id: I66decf6d5a4f79ddaa6617737e9334a56dbbbad4
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
Diffstat (limited to 'cinderclient/utils.py')
| -rw-r--r-- | cinderclient/utils.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/cinderclient/utils.py b/cinderclient/utils.py index 28c458d..681a2d4 100644 --- a/cinderclient/utils.py +++ b/cinderclient/utils.py @@ -17,13 +17,13 @@ from __future__ import print_function import collections import os -import pkg_resources import sys import uuid import prettytable import six from six.moves.urllib import parse +import stevedore from cinderclient import exceptions from oslo_utils import encodeutils @@ -332,11 +332,16 @@ def safe_issubclass(*args): def _load_entry_point(ep_name, name=None): """Try to load the entry point ep_name that matches name.""" - for ep in pkg_resources.iter_entry_points(ep_name, name=name): - try: - return ep.load() - except (ImportError, pkg_resources.UnknownExtra, AttributeError): - continue + mgr = stevedore.NamedExtensionManager( + namespace=ep_name, + names=[name], + # Ignore errors on load + on_load_failure_callback=lambda mgr, entry_point, error: None, + ) + try: + return mgr[name].plugin + except KeyError: + pass def get_function_name(func): |
