-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve discoverability of backend engine options #8447
Comments
This was my question on looking at it initially. Traditionally the main advantage of a builder pattern like this would be to incrementally add options |
Yes I agree I mostly copied and adapted the suggestion here from #8002, for which we cannot easily reuse For the backends, |
I really like the idea of making engine-specific kwargs more discoverable. It does make me a little sad though, because I really want people to be able to use the
I'm not totally sure how to test this, but I'm not confident that static type checkers will be able to deduce the kwargs for backends loaded from entrypoints. I think in order to implement this we'd need to add some kind of stubs to xarray itself so that it knows that if you do All this is to say that I think autocomplete will work fine in dynamic IDEs (like ipython or jupyter) but I do not think it will work in static environments. Also there might be some limitation on the amount of deduction that even an ipython will do. Not sure if this makes sense as an example, but I was just testing this out in ipython: See how |
Unfortunately, it looks like you are right @jsignell and I was a little too optimistic about how dev tools support entry-points. # test.py (xpystack is installed)
import xarray as xr
engine = xr.backends.plugins.get_backend("stac")
reveal_type(engine)
There's still the option of explicitly importing the backend class but sadly we're losing the niceties of entry-points: # assuming we can pass options via `BackendEntryPoint.__init__()`
import xarray as xr
import xpystack
ds = xr.open_dataset(obj, engine=xpystack.STACBackend(stacking_library="stackstac")) |
Oh wow, without checking open issues I have accidentally created a PR that solves exactly this #8520. This allows passing backends instances directly as engine argument, while still supporting passing these options as kwargs directly in |
Is your feature request related to a problem?
Backend engine options are not easily discoverable and we need to know or figure out them before passing it as kwargs to
xr.open_dataset()
.Describe the solution you'd like
The solution is similar to the one proposed in #8002 for setting a new index.
The API could look like this:
where
xr.backends.engine("myengine")
returns theMyEngineBackendEntrypoint
subclass.We would need to extend the API for
BackendEntrypoint
with a.with_options()
factory method:Such that
Pros:
.with_options(...)
would seamlessly work with IDE auto-completion, static type checkers (I guess? I'm not sure how static checkers support entry-points), documentation, etc.xr.open_dataset(obj, engine=...)
accepts either a string or a BackenEntryPoint subtype but not yet a BackendEntryPoint object) and this feature could be adopted progressively by existing 3rd-party backends.Cons:
open_dataset_parameters
,.with_options()
and.open_dataset()
does not look super nice but I don't really know how to avoid that.Describe alternatives you've considered
A
BackendEntryPoint.with_options()
factory is not really needed and we could just go withBackendEntryPoint.__init__()
instead. Perhapswith_options
looks a bit clearer and leaves room for more flexibility in__init__
, though?Additional context
cc @jsignell stac-utils/pystac#846 (comment)
The text was updated successfully, but these errors were encountered: