1515
1616"""Manage access to the clients, including authenticating when needed."""
1717
18+ import importlib
1819import logging
1920import sys
2021
2122from osc_lib import clientmanager
2223from osc_lib import shell
23- import pkg_resources
24+ import stevedore
2425
2526
2627LOG = logging .getLogger (__name__ )
@@ -143,17 +144,25 @@ def is_volume_endpoint_enabled(self, volume_client):
143144def 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
0 commit comments