Skip to content

Commit

Permalink
Fix default entrypoint handling on older Pythons (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
vyasr authored Oct 17, 2023
1 parent c28f5c9 commit c58f210
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-osx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 2 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Fix

* ``Codec`` is now derived from ``abc.ABC``
By :user:`Mads R. B. Kristensen <madsbk>`, :issue:`472`.
* Fix handling of entry points on older Python versions where ``importlib_metadata`` compatibility is concerned
By :user:`Vyas Ramasubramani <vyasr>`, :issue:`478`.
* Make shuffle pyx functions ``noexcept``
By :user:`Martin Durant <martindurant>`, :issue:`477`.

Expand Down
2 changes: 1 addition & 1 deletion numcodecs/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion numcodecs/tests/test_entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
32 changes: 32 additions & 0 deletions numcodecs/tests/test_entrypoints_backport.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ test = [
"pytest",
"pytest-cov",
]
test_extras = [
"importlib_metadata",
]
msgpack = [
"msgpack",
]
Expand Down

0 comments on commit c58f210

Please sign in to comment.