-
-
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
Backends entrypoints #4577
Backends entrypoints #4577
Conversation
add class for entrypointys
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @aurghs for pushing this forward. I have a few small comments but think this is otherwise quite close. We should discuss (tomorrow I suppose) a plan for testing the entrypoint discovery logic and error handling.
Just to bring to the attention of the rest of @pydata/xarray, this does add a new, small dependency on the entrypoints
package.
- replace entrypoints with pkg_resources - add tests
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few suggestions which I feel will improve the readability, but I'm not sure if that's objectively true for each of these.
Also, as a note to myself and to others trying to test this (I spent way too much time trying to figure that out): after changing the entrypoints in setup.cfg
, the package has to be reinstalled for the changes to be visible (editable installs only allow changing the code without reinstalling).
for d in list(decoders): | ||
if decode_cf is False and d in open_backend_dataset_parameters: | ||
decoders[d] = False | ||
if decoders[d] is None: | ||
decoders.pop(d) | ||
return decoders |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for this sort of filtering and transformation I would usually rely on comprehensions:
for d in list(decoders): | |
if decode_cf is False and d in open_backend_dataset_parameters: | |
decoders[d] = False | |
if decoders[d] is None: | |
decoders.pop(d) | |
return decoders | |
def choose_decoder(name): | |
if decode_cf is False and name in open_backend_dataset_parameters: | |
return False | |
return decoder | |
return { | |
choose_decoder(name) | |
for name, decoder in decoders.items() | |
if decoder is not None | |
} |
but there might be a better (more readable) way to express the conditional transformation of Edit: I added the local function, but I'm still searching for a better namedecoder
. Maybe use a local function with a descriptive name?
Co-authored-by: keewis <[email protected]>
Co-authored-by: keewis <[email protected]>
# Conflicts: # xarray/backends/apiv2.py
@aurghs - I think we're basically done here. Can you clean up the remaining failing tests and we'll get this merged? |
@keewis WRT your comments on list comprehensions we at B-Open prefer to use them only when they make the code one line and actually prefer explicit loops otherwise. This is both because we find them more readable as code and because tracebacks as well are easier to parse when they point to the statement that raised. |
no worries, as I said when posting these suggestions I do know that there are different opinions about comprehensions or generator expressions. I could have been more explicit about this, though, I meant to say that you may choose not to apply suggestions you do not agree with. |
entrypoints
module to detect the installed engines. The detection is done atopen_dataset
function call and it is cached. It raises a warning in case of conflicts.BackendEtrypoint
instead of a function.Modified files:
add plugins.py containing
detect_engines
function andBackendEtrypoint
.dependencies file to add
entrypoints
.backend.init to add
detect_engines
apiv2.py and api.py do use
detect_engines
zarr.py, h5netcdf_.py, cfgrib.py to instatiate the
BackendEtrypoint
.Related to [Feature] Backend entrypoint #3166
Tests added
Passes
isort . && black . && mypy . && flake8