Skip to content

Backends entrypoints - #4577

Merged
alexamici merged 22 commits into
pydata:masterfrom
bopen:backends-entrypoints
Dec 10, 2020
Merged

Backends entrypoints#4577
alexamici merged 22 commits into
pydata:masterfrom
bopen:backends-entrypoints

Conversation

@aurghs

@aurghsaurghs commented Nov 12, 2020

Copy link
Copy Markdown
Collaborator
  • 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

pep8speaks commented Nov 12, 2020

Copy link
Copy Markdown

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

@jhammanjhamman left a comment

Copy link
Copy Markdown
Member

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.

Comment threadxarray/backends/plugins.py
Comment threadxarray/backends/plugins.py
@aurghs

aurghs commented Nov 23, 2020

Copy link
Copy Markdown
CollaboratorAuthor
  • 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.

@keewiskeewis left a comment

Copy link
Copy Markdown
Collaborator

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

@keewiskeewisDec 2, 2020

Copy link
Copy Markdown
Collaborator

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
fordinlist(decoders):
ifdecode_cfisFalseanddinopen_backend_dataset_parameters:
decoders[d] =False
ifdecoders[d] isNone:
decoders.pop(d)
returndecoders
defchoose_decoder(name):
ifdecode_cfisFalseandnameinopen_backend_dataset_parameters:
returnFalse
returndecoder
return {
choose_decoder(name)
forname, decoderindecoders.items()
ifdecoderisnotNone
}

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

Comment threadxarray/backends/plugins.py
Comment threadxarray/tests/test_plugins.py Outdated
Comment threadxarray/tests/test_plugins.py Outdated
Comment threadxarray/tests/test_plugins.py Outdated
aurghsand 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
Copy Markdown
Member

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

@alexamicialexamici changed the title WIP: Backends entrypointsBackends entrypointsDec 10, 2020
@alexamici
alexamici self-requested a review December 10, 2020 09:47
@alexamici

Copy link
Copy Markdown
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:masterDec 10, 2020
@keewis

keewis commented Dec 10, 2020

Copy link
Copy Markdown
Collaborator

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 freeto 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

@aurghs@pep8speaks@jhamman@alexamici@keewis@shoyer