Skip to content
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

Merged
merged 22 commits into from
Dec 10, 2020
Merged

Backends entrypoints #4577

merged 22 commits into from
Dec 10, 2020

Conversation

aurghs
Copy link
Collaborator

@aurghs aurghs commented Nov 12, 2020

  • It's an update of @jhamman pull request [Feature] Backend entrypoint #3166
  • It uses entrypoints module to detect the installed engines. The detection is done at open_dataset function call and it is cached. It raises a warning in case of conflicts.
  • Add a class for the backend interface BackendEtrypoint instead of a function.

Modified files:

  • add plugins.py containing detect_engines function and BackendEtrypoint.

  • 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

@pep8speaks
Copy link

pep8speaks commented Nov 12, 2020

Hello @aurghs! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-12-10 09:10:08 UTC

Copy link
Member

@jhamman jhamman left a 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.

xarray/backends/plugins.py Show resolved Hide resolved
xarray/backends/plugins.py Show resolved Hide resolved
@aurghs
Copy link
Collaborator Author

aurghs commented Nov 23, 2020

  • I have replaced entrypoints with pkg_resources. I can't see any drawback in this change, but only advantages, the main one is that we remove an external dependency.
  • I have added the tests.
  • I didn't remove the signature inspection, since we have already talked about it widely with @shoyer, and in the end, we decided to keep the inspection and add the checks on the signature to be sure that neither *args nor **kwargs will be used.

Copy link
Collaborator

@keewis keewis left a 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).

Comment on lines +76 to +81
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
Copy link
Collaborator

@keewis keewis Dec 2, 2020

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:

Suggested change
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 decoder. Maybe use a local function with a descriptive name? Edit: I added the local function, but I'm still searching for a better name

xarray/backends/plugins.py Show resolved Hide resolved
xarray/tests/test_plugins.py Outdated Show resolved Hide resolved
xarray/tests/test_plugins.py Outdated Show resolved Hide resolved
xarray/tests/test_plugins.py Outdated Show resolved Hide resolved
aurghs and others added 3 commits December 3, 2020 08:24
Co-authored-by: keewis <keewis@users.noreply.github.com>
Co-authored-by: keewis <keewis@users.noreply.github.com>
@jhamman
Copy link
Member

jhamman commented Dec 9, 2020

@aurghs - I think we're basically done here. Can you clean up the remaining failing tests and we'll get this merged?

@alexamici alexamici changed the title WIP: Backends entrypoints Backends entrypoints Dec 10, 2020
@alexamici alexamici self-requested a review December 10, 2020 09:47
@alexamici
Copy link
Collaborator

@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.

@alexamici alexamici merged commit 74dffff into pydata:master Dec 10, 2020
@keewis
Copy link
Collaborator

keewis commented Dec 10, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants