1
1
import logging
2
2
from pathlib import Path
3
3
4
- import pkg_resources
4
+ from importlib . metadata import distribution , entry_points
5
5
from cryptography .exceptions import InvalidSignature
6
6
from otumat import hash_pkg , verify
7
7
13
13
def _update_error_stack (plugin_name ):
14
14
try :
15
15
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 )
18
18
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" ))
22
28
verify (pubkey_path = pubkey_path , data = data , signature = signature )
23
29
logger .info (f"DataJoint verified plugin `{ plugin_name } ` detected." )
24
30
return True
@@ -28,19 +34,28 @@ def _update_error_stack(plugin_name):
28
34
29
35
30
36
def _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
+
31
47
return {
32
48
entry_point .name : dict (
33
49
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 ]),
38
51
)
52
+ for entry_point in group_eps
39
53
if "plugin" not in config
40
54
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 ]
42
56
}
43
57
44
58
45
59
connection_plugins = _import_plugins ("connection" )
46
60
type_plugins = _import_plugins ("datatype" )
61
+
0 commit comments