diff --git a/.github/workflows/ci-linux.yaml b/.github/workflows/ci-linux.yaml index 20e79eed..b5d1571a 100644 --- a/.github/workflows/ci-linux.yaml +++ b/.github/workflows/ci-linux.yaml @@ -50,7 +50,7 @@ jobs: run: | conda activate env export DISABLE_NUMCODECS_AVX2="" - python -m pip install -v -e .[test,msgpack,zfpy] + python -m pip install -v -e .[test,test_extras,msgpack,zfpy] - name: List installed packages shell: "bash -l {0}" diff --git a/.github/workflows/ci-osx.yaml b/.github/workflows/ci-osx.yaml index 7757bc02..db09a12e 100644 --- a/.github/workflows/ci-osx.yaml +++ b/.github/workflows/ci-osx.yaml @@ -50,7 +50,7 @@ jobs: run: | conda activate env export DISABLE_NUMCODECS_AVX2="" - python -m pip install -v -e .[test,msgpack,zfpy] + python -m pip install -v -e .[test,test_extras,msgpack,zfpy] - name: List installed packages shell: "bash -l {0}" diff --git a/.github/workflows/ci-windows.yaml b/.github/workflows/ci-windows.yaml index bc62f301..201a2ac4 100644 --- a/.github/workflows/ci-windows.yaml +++ b/.github/workflows/ci-windows.yaml @@ -42,7 +42,7 @@ jobs: shell: "bash -l {0}" run: | conda activate env - python -m pip install -v -e .[test,msgpack,zfpy] + python -m pip install -v -e .[test,test_extras,msgpack,zfpy] - name: List installed packages shell: "bash -l {0}" diff --git a/docs/release.rst b/docs/release.rst index c1504201..2ec8e1b9 100644 --- a/docs/release.rst +++ b/docs/release.rst @@ -16,6 +16,8 @@ Fix * ``Codec`` is now derived from ``abc.ABC`` By :user:`Mads R. B. Kristensen `, :issue:`472`. +* Fix handling of entry points on older Python versions where ``importlib_metadata`` compatibility is concerned + By :user:`Vyas Ramasubramani `, :issue:`478`. * Make shuffle pyx functions ``noexcept`` By :user:`Martin Durant `, :issue:`477`. diff --git a/numcodecs/registry.py b/numcodecs/registry.py index 24186fa5..d0cd0748 100644 --- a/numcodecs/registry.py +++ b/numcodecs/registry.py @@ -16,7 +16,7 @@ def run_entrypoints(): entries.update({e.name: e for e in eps.select(group="numcodecs.codecs")}) else: # Otherwise, fallback to using get - entries.update(eps.get("numcodecs.codecs", [])) + entries.update({e.name: e for e in eps.get("numcodecs.codecs", [])}) run_entrypoints() diff --git a/numcodecs/tests/test_entrypoints.py b/numcodecs/tests/test_entrypoints.py index 0d017f2d..2923ac22 100644 --- a/numcodecs/tests/test_entrypoints.py +++ b/numcodecs/tests/test_entrypoints.py @@ -19,6 +19,7 @@ def set_path(): numcodecs.registry.codec_registry.pop("test") -def test_entrypoint_codec(set_path): +@pytest.mark.usefixtures("set_path") +def test_entrypoint_codec(): cls = numcodecs.registry.get_codec({"id": "test"}) assert cls.codec_id == "test" diff --git a/numcodecs/tests/test_entrypoints_backport.py b/numcodecs/tests/test_entrypoints_backport.py new file mode 100644 index 00000000..4e0459e5 --- /dev/null +++ b/numcodecs/tests/test_entrypoints_backport.py @@ -0,0 +1,32 @@ +import os.path +import pkgutil +import sys + +import pytest + +from multiprocessing import Process + +import numcodecs.registry + +if not pkgutil.find_loader("importlib_metadata"): # pragma: no cover + pytest.skip("This test module requires importlib_metadata to be installed") + +here = os.path.abspath(os.path.dirname(__file__)) + + +def get_entrypoints_with_importlib_metadata_loaded(): + # importlib_metadata patches importlib.metadata, which can lead to breaking changes + # to the APIs of EntryPoint objects used when registering entrypoints. Attempt to + # isolate those changes to just this test. + import importlib_metadata # noqa: F401 + sys.path.append(here) + numcodecs.registry.run_entrypoints() + cls = numcodecs.registry.get_codec({"id": "test"}) + assert cls.codec_id == "test" + + +def test_entrypoint_codec_with_importlib_metadata(): + p = Process(target=get_entrypoints_with_importlib_metadata_loaded) + p.start() + p.join() + assert p.exitcode == 0 diff --git a/pyproject.toml b/pyproject.toml index 6167147c..31268274 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,6 +56,9 @@ test = [ "pytest", "pytest-cov", ] +test_extras = [ + "importlib_metadata", +] msgpack = [ "msgpack", ]