Skip to content

Commit 870cf01

Browse files
committed
switch to stevedore for entry points
Importing pkg_resources scans every installed distribution to find all of the entry points. Stevedore is adding a new caching layer using importlib.metadata, which will not. Switching to the stevedore should eventually speed up load times, especially for command line apps. This change makes the switch now to ensure API compatibility. We were already using stevedore for tests, so this moves the dependency from test-requirements.txt to requirements.txt and raises the minimum version to something more recent. Change-Id: I3e3632783bc745979b6db73e610df8a77ffaceb0 Signed-off-by: Doug Hellmann <doug@doughellmann.com>
1 parent d3691b8 commit 870cf01

4 files changed

Lines changed: 18 additions & 9 deletions

File tree

lower-constraints.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ six==1.10.0
124124
smmap==0.9.0
125125
statsd==3.2.1
126126
stestr==1.0.0
127-
stevedore==1.20.0
127+
stevedore==2.0.1
128128
sushy==0.1.0
129129
tempest==17.1.0
130130
tenacity==3.2.1

openstackclient/common/clientmanager.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515

1616
"""Manage access to the clients, including authenticating when needed."""
1717

18+
import importlib
1819
import logging
1920
import sys
2021

2122
from osc_lib import clientmanager
2223
from osc_lib import shell
23-
import pkg_resources
24+
import stevedore
2425

2526

2627
LOG = logging.getLogger(__name__)
@@ -143,17 +144,25 @@ def is_volume_endpoint_enabled(self, volume_client):
143144
def get_plugin_modules(group):
144145
"""Find plugin entry points"""
145146
mod_list = []
146-
for ep in pkg_resources.iter_entry_points(group):
147+
mgr = stevedore.ExtensionManager(group)
148+
for ep in mgr:
147149
LOG.debug('Found plugin %s', ep.name)
148150

151+
# Different versions of stevedore use different
152+
# implementations of EntryPoint from other libraries, which
153+
# are not API-compatible.
149154
try:
150-
__import__(ep.module_name)
151-
except Exception:
155+
module_name = ep.entry_point.module_name
156+
except AttributeError:
157+
module_name = ep.entry_point.module
158+
159+
try:
160+
module = importlib.import_module(module_name)
161+
except Exception as err:
152162
sys.stderr.write(
153-
"WARNING: Failed to import plugin %s.\n" % ep.name)
163+
"WARNING: Failed to import plugin %s: %s.\n" % (ep.name, err))
154164
continue
155165

156-
module = sys.modules[ep.module_name]
157166
mod_list.append(module)
158167
init_func = getattr(module, 'Initialize', None)
159168
if init_func:
@@ -164,7 +173,7 @@ def get_plugin_modules(group):
164173
clientmanager.ClientManager,
165174
module.API_NAME,
166175
clientmanager.ClientCache(
167-
getattr(sys.modules[ep.module_name], 'make_client', None)
176+
getattr(sys.modules[module_name], 'make_client', None)
168177
),
169178
)
170179
return mod_list

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ oslo.utils>=3.33.0 # Apache-2.0
1212
python-keystoneclient>=3.22.0 # Apache-2.0
1313
python-novaclient>=15.1.0 # Apache-2.0
1414
python-cinderclient>=3.3.0 # Apache-2.0
15+
stevedore>=2.0.1 # Apache-2.0

test-requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ flake8-import-order>=0.13 # LGPLv3
88
oslotest>=3.2.0 # Apache-2.0
99
requests>=2.14.2 # Apache-2.0
1010
requests-mock>=1.2.0 # Apache-2.0
11-
stevedore>=1.20.0 # Apache-2.0
1211
stestr>=1.0.0 # Apache-2.0
1312
testtools>=2.2.0 # MIT
1413
tempest>=17.1.0 # Apache-2.0

0 commit comments

Comments
 (0)