Skip to content

Commit 8ae621c

Browse files
committed
chore: Removed deprecation by switching to importlib.metadata
1 parent 3a359b1 commit 8ae621c

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

datajoint/plugin.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
from pathlib import Path
33

4-
import pkg_resources
4+
from importlib.metadata import distribution, entry_points
55
from cryptography.exceptions import InvalidSignature
66
from otumat import hash_pkg, verify
77

@@ -13,12 +13,18 @@
1313
def _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,19 +34,28 @@ def _update_error_stack(plugin_name):
2834

2935

3036
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+
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

4559
connection_plugins = _import_plugins("connection")
4660
type_plugins = _import_plugins("datatype")
61+

0 commit comments

Comments
 (0)