Skip to content

Commit 034dc96

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. This should help xarray be more resilient in other software's bugs in case they install malformed entrypoints Example: ```python >>> from xarray.core.parallelcompat import list_chunkmanagers >>> list_chunkmanagers() <ipython-input-3-19326f4950bc>:1: UserWarning: Failed to load entrypoint MyChunkManager due to No module named 'my.array._chunkmanager'. Skipping. list_chunkmanagers() {'dask': <xarray.core.daskmanager.DaskManager at 0x7f5b826231c0>} ```
1 parent 0ad7fa7 commit 034dc96

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

xarray/core/parallelcompat.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import numpy as np
2323

2424
from xarray.core.pycompat import is_chunked_array
25+
from xarray.core.utils import emit_user_level_warning
2526

2627
T_ChunkedArray = TypeVar("T_ChunkedArray", bound=Any)
2728

@@ -57,9 +58,15 @@ def load_chunkmanagers(
5758
) -> dict[str, ChunkManagerEntrypoint]:
5859
"""Load entrypoints and instantiate chunkmanagers only once."""
5960

60-
loaded_entrypoints = {
61-
entrypoint.name: entrypoint.load() for entrypoint in entrypoints
62-
}
61+
loaded_entrypoints = {}
62+
for entrypoint in entrypoints:
63+
try:
64+
loaded_entrypoints[entrypoint.name] = entrypoint.load()
65+
except ModuleNotFoundError as e:
66+
emit_user_level_warning(
67+
f"Failed to load entrypoint {entrypoint.name} due to {e}. Skipping.",
68+
)
69+
pass
6370

6471
available_chunkmanagers = {
6572
name: chunkmanager()

0 commit comments

Comments
 (0)