MCPcopy Index your code
hub / github.com/pydata/xarray / get_backend

Function get_backend

xarray/backends/plugins.py:220–246  ·  view source on GitHub ↗

Select open_dataset method based on current engine.

(engine: str | type[BackendEntrypoint])

Source from the content-addressed store, hash-verified

218
219
220def get_backend(engine: str | type[BackendEntrypoint]) -> BackendEntrypoint:
221 """Select open_dataset method based on current engine."""
222 if isinstance(engine, str):
223 if engine in BACKEND_ENTRYPOINTS:
224 # fast path for built-in engines
225 backend_cls = BACKEND_ENTRYPOINTS[engine][1]
226 set_missing_parameters({engine: backend_cls})
227 backend = backend_cls()
228 else:
229 engines = list_engines()
230 if engine not in engines:
231 raise ValueError(
232 f"unrecognized engine '{engine}' must be one of your download engines: {list(engines)}. "
233 "To install additional dependencies, see:\n"
234 "https://docs.xarray.dev/en/stable/user-guide/io.html \n"
235 "https://docs.xarray.dev/en/stable/getting-started-guide/installing.html"
236 )
237 backend = engines[engine]
238 elif issubclass(engine, BackendEntrypoint):
239 backend = engine()
240 else:
241 raise TypeError(
242 "engine must be a string or a subclass of "
243 f"xarray.backends.BackendEntrypoint: {engine}"
244 )
245
246 return backend

Callers

nothing calls this directly

Calls 2

set_missing_parametersFunction · 0.85
list_enginesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…