diff --git a/xarray/core/parallelcompat.py b/xarray/core/parallelcompat.py index c009ef48419..de28a8bc99a 100644 --- a/xarray/core/parallelcompat.py +++ b/xarray/core/parallelcompat.py @@ -22,6 +22,7 @@ import numpy as np from xarray.core.pycompat import is_chunked_array +from xarray.core.utils import emit_user_level_warning T_ChunkedArray = TypeVar("T_ChunkedArray", bound=Any) @@ -57,9 +58,15 @@ def load_chunkmanagers( ) -> dict[str, ChunkManagerEntrypoint]: """Load entrypoints and instantiate chunkmanagers only once.""" - loaded_entrypoints = { - entrypoint.name: entrypoint.load() for entrypoint in entrypoints - } + loaded_entrypoints = {} + for entrypoint in entrypoints: + try: + loaded_entrypoints[entrypoint.name] = entrypoint.load() + except ModuleNotFoundError as e: + emit_user_level_warning( + f"Failed to load chunk manager entrypoint {entrypoint.name} due to {e}. Skipping.", + ) + pass available_chunkmanagers = { name: chunkmanager() diff --git a/xarray/tests/test_parallelcompat.py b/xarray/tests/test_parallelcompat.py index ea324cafb76..fb876108b3b 100644 --- a/xarray/tests/test_parallelcompat.py +++ b/xarray/tests/test_parallelcompat.py @@ -1,5 +1,6 @@ from __future__ import annotations +from importlib.metadata import EntryPoint from typing import Any import numpy as np @@ -11,6 +12,7 @@ get_chunked_array_type, guess_chunkmanager, list_chunkmanagers, + load_chunkmanagers, ) from xarray.core.types import T_Chunks, T_DuckArray, T_NormalizedChunks from xarray.tests import has_dask, requires_dask @@ -217,3 +219,10 @@ def test_raise_on_mixed_array_types(self, register_dummy_chunkmanager) -> None: with pytest.raises(TypeError, match="received multiple types"): get_chunked_array_type(*[dask_arr, dummy_arr]) + +def test_bogus_entrypoint(): + # Create a bogus entry-point as if the user broke their setup.cfg + # or is actively developing their new chunk manager + entry_point = EntryPoint("bogus", "xarray.bogus.doesnotwork", "xarray.chunkmanagers") + with pytest.warns(UserWarning, match="Failed to load chunk manager"): + assert len(load_chunkmanagers([entry_point])) == 0