Skip to content

Commit cb15543

Browse files
Remove use of entrypoints (#442)
Since Python 3.8, the standard library has included functionality to query entry points directly using importlib.metadata. Since the API has changed for the better with Python 3.10, we need to support both ways of using it.
1 parent d667b31 commit cb15543

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

numcodecs/registry.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
"""The registry module provides some simple convenience functions to enable
22
applications to dynamically register and look-up codec classes."""
3+
from importlib.metadata import entry_points
34
import logging
4-
from contextlib import suppress
55

66
logger = logging.getLogger("numcodecs")
77
codec_registry = {}
88
entries = {}
99

1010

1111
def run_entrypoints():
12-
import entrypoints
1312
entries.clear()
14-
entries.update(entrypoints.get_group_named("numcodecs.codecs"))
13+
eps = entry_points()
14+
if hasattr(eps, 'select'):
15+
# If entry_points() has a select method, use that. Python 3.10+
16+
entries.update(eps.select(group="numcodecs.codecs"))
17+
else:
18+
# Otherwise, fallback to using get
19+
entries.update(eps.get("numcodecs.codecs", []))
1520

1621

17-
with suppress(ImportError):
18-
run_entrypoints()
22+
run_entrypoints()
1923

2024

2125
def get_codec(config):

numcodecs/tests/test_entrypoints.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88

99
here = os.path.abspath(os.path.dirname(__file__))
10-
pytest.importorskip("entrypoints")
1110

1211

1312
@pytest.fixture()
@@ -20,7 +19,6 @@ def set_path():
2019
numcodecs.registry.codec_registry.pop("test")
2120

2221

23-
@pytest.mark.xfail(reason="FIXME: not working in wheels build")
2422
def test_entrypoint_codec(set_path):
2523
cls = numcodecs.registry.get_codec({"id": "test"})
2624
assert cls.codec_id == "test"

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ in data storage and communication applications.
1515
"""
1616
readme = "README.rst"
1717
dependencies = [
18-
"entrypoints",
1918
"numpy>=1.7",
2019
]
2120
requires-python = ">=3.8"
@@ -71,6 +70,12 @@ package-dir = {"" = "."}
7170
packages = ["numcodecs", "numcodecs.tests"]
7271
zip-safe = false
7372

73+
[tool.setuptools.package-data]
74+
numcodecs = [
75+
"tests/package_with_entrypoint/__init__.py",
76+
"tests/package_with_entrypoint-0.1.dist-info/entry_points.txt"
77+
]
78+
7479
[tool.setuptools_scm]
7580
version_scheme = "guess-next-dev"
7681
local_scheme = "dirty-tag"

0 commit comments

Comments
 (0)