From 54554c403e8ea6db677033e699f21792a15b7d2d Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Mon, 9 Oct 2023 15:07:52 -0700 Subject: [PATCH 01/14] Replace default list with dict --- numcodecs/registry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numcodecs/registry.py b/numcodecs/registry.py index 24186fa5..d6911aa5 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(eps.get("numcodecs.codecs", {})) run_entrypoints() From cc88a87b489770b1448503a302a0fdbe6349d4a6 Mon Sep 17 00:00:00 2001 From: jakirkham Date: Mon, 9 Oct 2023 15:24:49 -0700 Subject: [PATCH 02/14] Add 0.12.1 release note w/entrypoint bug fix --- docs/release.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/release.rst b/docs/release.rst index 680dd186..e57b32cd 100644 --- a/docs/release.rst +++ b/docs/release.rst @@ -7,6 +7,17 @@ Release notes # re-indented so that it does not show up in the notes. +.. _release_0.12.1: + +0.12.1 +------ + +Fix +~~~ + +* Fix default entrypoint handling on older Pythons + By :user:`Vyas Ramasubramani `, :issue:`475`. + .. _release_0.12.0: 0.12.0 From a43ff0484c2c5da40841c35dca9359f5e8d2d51c Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Tue, 10 Oct 2023 10:37:14 -0700 Subject: [PATCH 03/14] Tag to issue rather than PR --- docs/release.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/release.rst b/docs/release.rst index e57b32cd..6bb69b02 100644 --- a/docs/release.rst +++ b/docs/release.rst @@ -16,7 +16,7 @@ Fix ~~~ * Fix default entrypoint handling on older Pythons - By :user:`Vyas Ramasubramani `, :issue:`475`. + By :user:`Vyas Ramasubramani `, :issue:`478`. .. _release_0.12.0: From e227e5df0881966de71659c22e3258abb06d87aa Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Tue, 10 Oct 2023 12:15:33 -0700 Subject: [PATCH 04/14] Proper fix --- numcodecs/registry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numcodecs/registry.py b/numcodecs/registry.py index d6911aa5..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() From a21a20a44c3522df4c367096258e32d836c9584a Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Tue, 10 Oct 2023 14:16:58 -0700 Subject: [PATCH 05/14] Update release notes --- docs/release.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/release.rst b/docs/release.rst index 6bb69b02..8cc571bb 100644 --- a/docs/release.rst +++ b/docs/release.rst @@ -15,7 +15,7 @@ Release notes Fix ~~~ -* Fix default entrypoint handling on older Pythons +* Fix handling of entry points on older Python versions where importlib_metadata compatibility is concerned By :user:`Vyas Ramasubramani `, :issue:`478`. .. _release_0.12.0: From fb8653b4a82c85945fd66f3251ec99ff4206bd25 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Tue, 10 Oct 2023 16:17:36 -0700 Subject: [PATCH 06/14] Add a test --- numcodecs/tests/test_entrypoints.py | 25 +++++++++++++++++++++++-- pyproject.toml | 1 + 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/numcodecs/tests/test_entrypoints.py b/numcodecs/tests/test_entrypoints.py index 0d017f2d..b7db75e9 100644 --- a/numcodecs/tests/test_entrypoints.py +++ b/numcodecs/tests/test_entrypoints.py @@ -1,5 +1,6 @@ import os.path import sys +from unittest import mock import pytest @@ -9,7 +10,6 @@ here = os.path.abspath(os.path.dirname(__file__)) -@pytest.fixture() def set_path(): sys.path.append(here) numcodecs.registry.run_entrypoints() @@ -19,6 +19,27 @@ def set_path(): numcodecs.registry.codec_registry.pop("test") -def test_entrypoint_codec(set_path): +@pytest.fixture() +def set_path_fixture(): + yield from set_path() + + +@pytest.mark.usefixtures("set_path_fixture") +def test_entrypoint_codec(): cls = numcodecs.registry.get_codec({"id": "test"}) assert cls.codec_id == "test" + + +def test_entrypoint_codec_with_importlib_metadata(): + # 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. + with mock.patch.dict(sys.modules): + import importlib_metadata + sys.path.append(here) + numcodecs.registry.run_entrypoints() + cls = numcodecs.registry.get_codec({"id": "test"}) + assert cls.codec_id == "test" + sys.path.remove(here) + numcodecs.registry.run_entrypoints() + numcodecs.registry.codec_registry.pop("test") diff --git a/pyproject.toml b/pyproject.toml index e68dabd7..b9a1eb74 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,6 +55,7 @@ test = [ "flake8", "pytest", "pytest-cov", + "importlib_metadata", ] msgpack = [ "msgpack", From 9d5cbd989aa431a85561390b07905ef982fa9edf Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Tue, 10 Oct 2023 18:08:42 -0700 Subject: [PATCH 07/14] Add noqa --- numcodecs/tests/test_entrypoints.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numcodecs/tests/test_entrypoints.py b/numcodecs/tests/test_entrypoints.py index b7db75e9..d144298e 100644 --- a/numcodecs/tests/test_entrypoints.py +++ b/numcodecs/tests/test_entrypoints.py @@ -35,7 +35,7 @@ def test_entrypoint_codec_with_importlib_metadata(): # to the APIs of EntryPoint objects used when registering entrypoints. Attempt to # isolate those changes to just this test. with mock.patch.dict(sys.modules): - import importlib_metadata + import importlib_metadata # noqa: F401 sys.path.append(here) numcodecs.registry.run_entrypoints() cls = numcodecs.registry.get_codec({"id": "test"}) From b52d1c0c3ba1787c1420b4fe7a0af8bf81f5dc45 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Tue, 10 Oct 2023 18:11:10 -0700 Subject: [PATCH 08/14] Change test to fork --- numcodecs/tests/test_entrypoints.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/numcodecs/tests/test_entrypoints.py b/numcodecs/tests/test_entrypoints.py index d144298e..bed63433 100644 --- a/numcodecs/tests/test_entrypoints.py +++ b/numcodecs/tests/test_entrypoints.py @@ -4,6 +4,8 @@ import pytest +from multiprocessing import Process + import numcodecs.registry @@ -30,16 +32,19 @@ def test_entrypoint_codec(): assert cls.codec_id == "test" -def test_entrypoint_codec_with_importlib_metadata(): +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. - with mock.patch.dict(sys.modules): - 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" - sys.path.remove(here) - numcodecs.registry.run_entrypoints() - numcodecs.registry.codec_registry.pop("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 From 5dcc33469e3cefa28a06cb36757f236092e23b13 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Wed, 11 Oct 2023 09:15:14 -0700 Subject: [PATCH 09/14] Remove unused import --- numcodecs/tests/test_entrypoints.py | 1 - 1 file changed, 1 deletion(-) diff --git a/numcodecs/tests/test_entrypoints.py b/numcodecs/tests/test_entrypoints.py index bed63433..ff6b3e1a 100644 --- a/numcodecs/tests/test_entrypoints.py +++ b/numcodecs/tests/test_entrypoints.py @@ -1,6 +1,5 @@ import os.path import sys -from unittest import mock import pytest From 30cc25f5623669b9e04e39bb737e34920920f773 Mon Sep 17 00:00:00 2001 From: jakirkham Date: Mon, 16 Oct 2023 21:28:22 -0700 Subject: [PATCH 10/14] Merge 0.12.1 release notes --- docs/release.rst | 9 --------- 1 file changed, 9 deletions(-) diff --git a/docs/release.rst b/docs/release.rst index fed28cb6..be2c4fd8 100644 --- a/docs/release.rst +++ b/docs/release.rst @@ -16,15 +16,6 @@ Fix * `Codec` is now derived from `abc.ABC` By :user:`Mads R. B. Kristensen `, :issue:`472`. - -.. _release_0.12.1: - -0.12.1 ------- - -Fix -~~~ - * Fix handling of entry points on older Python versions where importlib_metadata compatibility is concerned By :user:`Vyas Ramasubramani `, :issue:`478`. From 2ce2444703dbdda3088c5745804c0b6f45010400 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Tue, 17 Oct 2023 14:38:48 -0700 Subject: [PATCH 11/14] Move importlib_metadata to a separate extra --- .github/workflows/ci-linux.yaml | 2 +- .github/workflows/ci-osx.yaml | 2 +- .github/workflows/ci-windows.yaml | 2 +- pyproject.toml | 2 ++ 4 files changed, 5 insertions(+), 3 deletions(-) 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/pyproject.toml b/pyproject.toml index 5d56d929..31268274 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,6 +55,8 @@ test = [ "flake8", "pytest", "pytest-cov", +] +test_extras = [ "importlib_metadata", ] msgpack = [ From d243624d3aded9150218571b8854a0e422e3cfb7 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Tue, 17 Oct 2023 14:42:32 -0700 Subject: [PATCH 12/14] Move test to its own module --- numcodecs/tests/test_entrypoints.py | 20 ------------ numcodecs/tests/test_entrypoints_backport.py | 32 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 20 deletions(-) create mode 100644 numcodecs/tests/test_entrypoints_backport.py diff --git a/numcodecs/tests/test_entrypoints.py b/numcodecs/tests/test_entrypoints.py index ff6b3e1a..9702e9b2 100644 --- a/numcodecs/tests/test_entrypoints.py +++ b/numcodecs/tests/test_entrypoints.py @@ -3,8 +3,6 @@ import pytest -from multiprocessing import Process - import numcodecs.registry @@ -29,21 +27,3 @@ def set_path_fixture(): def test_entrypoint_codec(): cls = numcodecs.registry.get_codec({"id": "test"}) assert cls.codec_id == "test" - - -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/numcodecs/tests/test_entrypoints_backport.py b/numcodecs/tests/test_entrypoints_backport.py new file mode 100644 index 00000000..82d66623 --- /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"): + 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 From a5951d4ab838f2e39759e5a8218fbb3c461002c4 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Tue, 17 Oct 2023 14:44:09 -0700 Subject: [PATCH 13/14] Clean up old test --- numcodecs/tests/test_entrypoints.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/numcodecs/tests/test_entrypoints.py b/numcodecs/tests/test_entrypoints.py index 9702e9b2..2923ac22 100644 --- a/numcodecs/tests/test_entrypoints.py +++ b/numcodecs/tests/test_entrypoints.py @@ -9,6 +9,7 @@ here = os.path.abspath(os.path.dirname(__file__)) +@pytest.fixture() def set_path(): sys.path.append(here) numcodecs.registry.run_entrypoints() @@ -18,12 +19,7 @@ def set_path(): numcodecs.registry.codec_registry.pop("test") -@pytest.fixture() -def set_path_fixture(): - yield from set_path() - - -@pytest.mark.usefixtures("set_path_fixture") +@pytest.mark.usefixtures("set_path") def test_entrypoint_codec(): cls = numcodecs.registry.get_codec({"id": "test"}) assert cls.codec_id == "test" From aeef7614f000be2922f42def7e555bee2cbf9b80 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Tue, 17 Oct 2023 15:39:32 -0700 Subject: [PATCH 14/14] Apply suggestions from code review Co-authored-by: jakirkham --- docs/release.rst | 2 +- numcodecs/tests/test_entrypoints_backport.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/release.rst b/docs/release.rst index 7a0a6d83..2ec8e1b9 100644 --- a/docs/release.rst +++ b/docs/release.rst @@ -16,7 +16,7 @@ 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 +* 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/tests/test_entrypoints_backport.py b/numcodecs/tests/test_entrypoints_backport.py index 82d66623..4e0459e5 100644 --- a/numcodecs/tests/test_entrypoints_backport.py +++ b/numcodecs/tests/test_entrypoints_backport.py @@ -8,7 +8,7 @@ import numcodecs.registry -if not pkgutil.find_loader("importlib_metadata"): +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__))