Backends entrypoints#4577
Backends entrypoints#4577alexamici merged 22 commits intopydata:masterfrom bopen:backends-entrypoints
Conversation
add class for entrypointys
jhamman
left a comment
There was a problem hiding this comment.
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
|
keewis
left a comment
There was a problem hiding this comment.
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.
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?
# 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. |
entrypointsmodule to detect the installed engines. The detection is done atopen_datasetfunction call and it is cached. It raises a warning in case of conflicts.BackendEtrypointinstead of a function.Modified files:
add plugins.py containing
detect_enginesfunction andBackendEtrypoint.dependencies file to add
entrypoints.backend.init to add
detect_enginesapiv2.py and api.py do use
detect_engineszarr.py, h5netcdf_.py, cfgrib.py to instatiate the
BackendEtrypoint.Related to [Feature] Backend entrypoint #3166
Tests added
Passes
isort . && black . && mypy . && flake8