96 lines
2.9 KiB
Diff
96 lines
2.9 KiB
Diff
From af20af8210384371f91f30251fc78a35ffd0c072 Mon Sep 17 00:00:00 2001
|
|
From: Steve Kowalik <steven@wedontsleep.org>
|
|
Date: Wed, 9 Aug 2023 15:15:52 +1000
|
|
Subject: [PATCH] Remove use of entrypoints
|
|
|
|
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.
|
|
---
|
|
numcodecs/registry.py | 14 +++++++++-----
|
|
numcodecs/tests/test_entrypoints.py | 2 --
|
|
pyproject.toml | 7 ++++++-
|
|
3 files changed, 15 insertions(+), 8 deletions(-)
|
|
|
|
diff --git a/numcodecs/registry.py b/numcodecs/registry.py
|
|
index 532e9967..a4dff6d7 100644
|
|
--- a/numcodecs/registry.py
|
|
+++ b/numcodecs/registry.py
|
|
@@ -1,7 +1,7 @@
|
|
"""The registry module provides some simple convenience functions to enable
|
|
applications to dynamically register and look-up codec classes."""
|
|
+from importlib.metadata import entry_points
|
|
import logging
|
|
-from contextlib import suppress
|
|
|
|
logger = logging.getLogger("numcodecs")
|
|
codec_registry = {}
|
|
@@ -9,13 +9,17 @@
|
|
|
|
|
|
def run_entrypoints():
|
|
- import entrypoints
|
|
entries.clear()
|
|
- entries.update(entrypoints.get_group_named("numcodecs.codecs"))
|
|
+ eps = entry_points()
|
|
+ if hasattr(eps, 'select'):
|
|
+ # If entry_points() has a select method, use that. Python 3.10+
|
|
+ entries.update(eps.select(group="numcodecs.codecs"))
|
|
+ else:
|
|
+ # Otherwise, fallback to using get
|
|
+ entries.update(eps.get("numcodecs.codecs", []))
|
|
|
|
|
|
-with suppress(ImportError):
|
|
- run_entrypoints()
|
|
+run_entrypoints()
|
|
|
|
|
|
def get_codec(config):
|
|
diff --git a/numcodecs/tests/test_entrypoints.py b/numcodecs/tests/test_entrypoints.py
|
|
index 81af635d..0d017f2d 100644
|
|
--- a/numcodecs/tests/test_entrypoints.py
|
|
+++ b/numcodecs/tests/test_entrypoints.py
|
|
@@ -7,7 +7,6 @@
|
|
|
|
|
|
here = os.path.abspath(os.path.dirname(__file__))
|
|
-pytest.importorskip("entrypoints")
|
|
|
|
|
|
@pytest.fixture()
|
|
@@ -20,7 +19,6 @@ def set_path():
|
|
numcodecs.registry.codec_registry.pop("test")
|
|
|
|
|
|
-@pytest.mark.xfail(reason="FIXME: not working in wheels build")
|
|
def test_entrypoint_codec(set_path):
|
|
cls = numcodecs.registry.get_codec({"id": "test"})
|
|
assert cls.codec_id == "test"
|
|
diff --git a/pyproject.toml b/pyproject.toml
|
|
index a2b50e32..147f9b54 100644
|
|
--- a/pyproject.toml
|
|
+++ b/pyproject.toml
|
|
@@ -15,7 +15,6 @@ in data storage and communication applications.
|
|
"""
|
|
readme = "README.rst"
|
|
dependencies = [
|
|
- "entrypoints",
|
|
"numpy>=1.7",
|
|
]
|
|
requires-python = ">=3.8"
|
|
@@ -71,6 +70,12 @@ package-dir = {"" = "."}
|
|
packages = ["numcodecs", "numcodecs.tests"]
|
|
zip-safe = false
|
|
|
|
+[tool.setuptools.package-data]
|
|
+numcodecs = [
|
|
+ "tests/package_with_entrypoint/__init__.py",
|
|
+ "tests/package_with_entrypoint-0.1.dist-info/entry_points.txt"
|
|
+]
|
|
+
|
|
[tool.setuptools_scm]
|
|
version_scheme = "guess-next-dev"
|
|
local_scheme = "dirty-tag"
|