diff options
| author | Doug Hellmann <doug@doughellmann.com> | 2020-07-04 15:10:29 -0400 |
|---|---|---|
| committer | Doug Hellmann <doug@doughellmann.com> | 2020-07-08 08:53:07 -0400 |
| commit | 109d41e722aec8df1a2325ea31630dc54e88e957 (patch) | |
| tree | 04245def903da08d078d9cac004a5a662a05560b /novaclient/client.py | |
| parent | 600384fa3b046f3c01e7f375f384610df99fae90 (diff) | |
| download | python-novaclient-109d41e722aec8df1a2325ea31630dc54e88e957.tar.gz | |
use stevedore to load extensions
Importing pkg_resources causes the app to scan the entire import path
for all distributions, not just those providing entry points. The
scanner in stevedore will have a cache of the entry point data, making
it significantly faster. This will be especially useful in command
line programs like python-openstackclient.
Change-Id: Ic5eb9401c8ea3bd9624b818e0ffb8dcc13f61559
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
Diffstat (limited to 'novaclient/client.py')
| -rw-r--r-- | novaclient/client.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/novaclient/client.py b/novaclient/client.py index 4b3e2281..6c15f04d 100644 --- a/novaclient/client.py +++ b/novaclient/client.py @@ -28,7 +28,7 @@ from keystoneauth1 import adapter from keystoneauth1 import identity from keystoneauth1 import session as ksession from oslo_utils import importutils -import pkg_resources +import stevedore import novaclient from novaclient import api_versions @@ -176,12 +176,15 @@ def _discover_via_python_path(): yield name, module -def _discover_via_entry_points(): - for ep in pkg_resources.iter_entry_points('novaclient.extension'): - name = ep.name - module = ep.load() +def _make_discovery_manager(): + # This function provides a place to mock out the entry point scan + return stevedore.ExtensionManager('novaclient.extension') + - yield name, module +def _discover_via_entry_points(): + mgr = _make_discovery_manager() + for extension in mgr: + yield extension.name, extension.plugin def _get_client_class_and_version(version): |
