11import logging
2+ from importlib .metadata import distribution , entry_points
23from pathlib import Path
34
4- import pkg_resources
55from cryptography .exceptions import InvalidSignature
66from otumat import hash_pkg , verify
77
1313def _update_error_stack (plugin_name ):
1414 try :
1515 base_name = "datajoint"
16- base_meta = pkg_resources . get_distribution (base_name )
17- plugin_meta = pkg_resources . get_distribution (plugin_name )
16+ base_meta = distribution (base_name )
17+ plugin_meta = distribution (plugin_name )
1818
19- data = hash_pkg (pkgpath = str (Path (plugin_meta .module_path , plugin_name )))
20- signature = plugin_meta .get_metadata (f"{ plugin_name } .sig" )
21- pubkey_path = str (Path (base_meta .egg_info , f"{ base_name } .pub" ))
19+ # Get the package location - equivalent to module_path
20+ plugin_location = plugin_meta .locate_file ("" )
21+ data = hash_pkg (pkgpath = str (Path (plugin_location .parent , plugin_name )))
22+
23+ # Get signature metadata - equivalent to get_metadata()
24+ signature = plugin_meta .read_text (f"{ plugin_name } .sig" )
25+
26+ # Get public key path - equivalent to egg_info
27+ pubkey_path = str (Path (base_meta .locate_file ("" ).parent , f"{ base_name } .pub" ))
2228 verify (pubkey_path = pubkey_path , data = data , signature = signature )
2329 logger .info (f"DataJoint verified plugin `{ plugin_name } ` detected." )
2430 return True
@@ -28,17 +34,25 @@ def _update_error_stack(plugin_name):
2834
2935
3036def _import_plugins (category ):
37+ # Get entry points for the group - equivalent to iter_entry_points()
38+ group_name = f"datajoint_plugins.{ category } "
39+ eps = entry_points ()
40+
41+ # Handle both Python 3.9 and 3.10+ entry points API
42+ if hasattr (eps , "select" ):
43+ group_eps = eps .select (group = group_name )
44+ else :
45+ group_eps = eps .get (group_name , [])
46+
3147 return {
3248 entry_point .name : dict (
3349 object = entry_point ,
34- verified = _update_error_stack (entry_point .module_name .split ("." )[0 ]),
35- )
36- for entry_point in pkg_resources .iter_entry_points (
37- "datajoint_plugins.{}" .format (category )
50+ verified = _update_error_stack (entry_point .module .split ("." )[0 ]),
3851 )
52+ for entry_point in group_eps
3953 if "plugin" not in config
4054 or category not in config ["plugin" ]
41- or entry_point .module_name .split ("." )[0 ] in config ["plugin" ][category ]
55+ or entry_point .module .split ("." )[0 ] in config ["plugin" ][category ]
4256 }
4357
4458
0 commit comments