Skip to content

Commit c58f210

Browse files
authored
Fix default entrypoint handling on older Pythons (#475)
1 parent c28f5c9 commit c58f210

File tree

8 files changed

+43
-5
lines changed

8 files changed

+43
-5
lines changed

.github/workflows/ci-linux.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
run: |
5151
conda activate env
5252
export DISABLE_NUMCODECS_AVX2=""
53-
python -m pip install -v -e .[test,msgpack,zfpy]
53+
python -m pip install -v -e .[test,test_extras,msgpack,zfpy]
5454
5555
- name: List installed packages
5656
shell: "bash -l {0}"

.github/workflows/ci-osx.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
run: |
5151
conda activate env
5252
export DISABLE_NUMCODECS_AVX2=""
53-
python -m pip install -v -e .[test,msgpack,zfpy]
53+
python -m pip install -v -e .[test,test_extras,msgpack,zfpy]
5454
5555
- name: List installed packages
5656
shell: "bash -l {0}"

.github/workflows/ci-windows.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
shell: "bash -l {0}"
4343
run: |
4444
conda activate env
45-
python -m pip install -v -e .[test,msgpack,zfpy]
45+
python -m pip install -v -e .[test,test_extras,msgpack,zfpy]
4646
4747
- name: List installed packages
4848
shell: "bash -l {0}"

docs/release.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Fix
1616

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

numcodecs/registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def run_entrypoints():
1616
entries.update({e.name: e for e in eps.select(group="numcodecs.codecs")})
1717
else:
1818
# Otherwise, fallback to using get
19-
entries.update(eps.get("numcodecs.codecs", []))
19+
entries.update({e.name: e for e in eps.get("numcodecs.codecs", [])})
2020

2121

2222
run_entrypoints()

numcodecs/tests/test_entrypoints.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def set_path():
1919
numcodecs.registry.codec_registry.pop("test")
2020

2121

22-
def test_entrypoint_codec(set_path):
22+
@pytest.mark.usefixtures("set_path")
23+
def test_entrypoint_codec():
2324
cls = numcodecs.registry.get_codec({"id": "test"})
2425
assert cls.codec_id == "test"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os.path
2+
import pkgutil
3+
import sys
4+
5+
import pytest
6+
7+
from multiprocessing import Process
8+
9+
import numcodecs.registry
10+
11+
if not pkgutil.find_loader("importlib_metadata"): # pragma: no cover
12+
pytest.skip("This test module requires importlib_metadata to be installed")
13+
14+
here = os.path.abspath(os.path.dirname(__file__))
15+
16+
17+
def get_entrypoints_with_importlib_metadata_loaded():
18+
# importlib_metadata patches importlib.metadata, which can lead to breaking changes
19+
# to the APIs of EntryPoint objects used when registering entrypoints. Attempt to
20+
# isolate those changes to just this test.
21+
import importlib_metadata # noqa: F401
22+
sys.path.append(here)
23+
numcodecs.registry.run_entrypoints()
24+
cls = numcodecs.registry.get_codec({"id": "test"})
25+
assert cls.codec_id == "test"
26+
27+
28+
def test_entrypoint_codec_with_importlib_metadata():
29+
p = Process(target=get_entrypoints_with_importlib_metadata_loaded)
30+
p.start()
31+
p.join()
32+
assert p.exitcode == 0

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ test = [
5656
"pytest",
5757
"pytest-cov",
5858
]
59+
test_extras = [
60+
"importlib_metadata",
61+
]
5962
msgpack = [
6063
"msgpack",
6164
]

0 commit comments

Comments
 (0)