@@ -93,19 +93,24 @@ def import_hook(module):
9393 callback = getattr (callback , attr )
9494 return callback (module )
9595
96+ def import_hook_legacy (module ):
97+ __import__ (entrypoint .module_name )
98+ callback = sys .modules [entrypoint .module_name ]
99+ for attr in entrypoint .attrs :
100+ callback = getattr (callback , attr )
101+ return callback (module )
102+
103+ if sys .version_info < (3 , 10 ):
104+ return import_hook_legacy
96105 return import_hook
97106
98107def discover_post_import_hooks (group ):
99- from importlib .metadata import entry_points
100-
101- try :
102- # Python 3.10+ style with select parameter
103- entrypoints = entry_points (group = group )
104- except TypeError :
105- # Python 3.8-3.9 style that returns a dict
106- entrypoints = entry_points ().get (group , ())
107-
108- for entrypoint in entrypoints :
108+ if sys .version_info >= (3 , 10 ):
109+ from importlib .metadata import entry_points
110+ else :
111+ from pkg_resources import iter_entry_points as entry_points
112+
113+ for entrypoint in entry_points (group = group ):
109114 entrypoint .load ()
110115 callback = _create_import_hook_from_entrypoint (entrypoint )
111116 register_post_import_hook (callback , entrypoint .name )
0 commit comments