Skip to content

Commit 54e3324

Browse files
committed
Make list_chunkmanagers more resilient to broken entrypoints
As I'm a developing my custom chunk manager, I'm often checking out between my development branch and production branch breaking the entrypoint. This made xarray impossible to import unless I re-ran `pip install -e . -vv` which is somewhat tiring.
1 parent d644607 commit 54e3324

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

xarray/namedarray/parallelcompat.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import numpy as np
1717

1818
from xarray.namedarray.pycompat import is_chunked_array
19+
from xarray.core.utils import emit_user_level_warning
1920

2021
if TYPE_CHECKING:
2122
from xarray.namedarray._typing import (
@@ -73,9 +74,15 @@ def load_chunkmanagers(
7374
) -> dict[str, ChunkManagerEntrypoint[Any]]:
7475
"""Load entrypoints and instantiate chunkmanagers only once."""
7576

76-
loaded_entrypoints = {
77-
entrypoint.name: entrypoint.load() for entrypoint in entrypoints
78-
}
77+
loaded_entrypoints = {}
78+
for entrypoint in entrypoints:
79+
try:
80+
loaded_entrypoints[entrypoint.name] = entrypoint.load()
81+
except ModuleNotFoundError as e:
82+
emit_user_level_warning(
83+
f"Failed to load chunk manager entrypoint {entrypoint.name} due to {e}. Skipping.",
84+
)
85+
pass
7986

8087
available_chunkmanagers = {
8188
name: chunkmanager()

xarray/tests/test_parallelcompat.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from importlib.metadata import EntryPoint
34
from typing import Any
45

56
import numpy as np
@@ -13,6 +14,7 @@
1314
get_chunked_array_type,
1415
guess_chunkmanager,
1516
list_chunkmanagers,
17+
load_chunkmanagers,
1618
)
1719
from xarray.tests import has_dask, requires_dask
1820

@@ -218,3 +220,10 @@ def test_raise_on_mixed_array_types(self, register_dummy_chunkmanager) -> None:
218220

219221
with pytest.raises(TypeError, match="received multiple types"):
220222
get_chunked_array_type(*[dask_arr, dummy_arr])
223+
224+
def test_bogus_entrypoint():
225+
# Create a bogus entry-point as if the user broke their setup.cfg
226+
# or is actively developing their new chunk manager
227+
entry_point = EntryPoint("bogus", "xarray.bogus.doesnotwork", "xarray.chunkmanagers")
228+
with pytest.warns(UserWarning, match="Failed to load chunk manager"):
229+
assert len(load_chunkmanagers([entry_point])) == 0

0 commit comments

Comments
 (0)