-
Notifications
You must be signed in to change notification settings - Fork 567
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
switch from entrypoints to importlib-metadata #1782
Conversation
entrypoints is deprecated and recommends switching to importlib-metadata. I've implemented this because I'm using a custom import mechanism that works with the documented importlib.metadata interface but not with entrypoints' custom logic
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.
LGTM, thanks!
pyproject.toml
Outdated
@@ -23,7 +23,7 @@ dependencies = [ | |||
"beautifulsoup4", | |||
"bleach", | |||
"defusedxml", | |||
"entrypoints>=0.2.2", | |||
"importlib-metadata;python_version<3.8", |
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.
One thing: we have been trying to avoid importlib-metadata<3.6
, and the stdlib one in python<3.10
: it loads every installed entrypoint, which can take a couple seconds.
nbconvert/exporters/base.py
Outdated
@@ -97,20 +100,14 @@ def get_exporter(name, config=get_config()): # noqa | |||
name = "notebook" | |||
|
|||
try: | |||
exporter = entrypoints.get_single("nbconvert.exporters", name).load() | |||
exporters = importlib_metadata.entry_points()["nbconvert.exporters"] |
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.
this loads every single entry_point, and can take seconds: indeed, i think it throws warnings on newer pythons.
Using entry_points(group="nbconvert.exporters.script")
will only load the one requested, but there are some version quirks (see comment on pyproject.toml
).
nbconvert/exporters/base.py
Outdated
@@ -5,7 +5,10 @@ | |||
|
|||
import os | |||
|
|||
import entrypoints | |||
try: |
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.
one last thing: because the stdlib version was broken, this is most accurate as a check of sys.version
, e.g.:
if sys.version_info < (3, 10):
from importlib_metadata import entry_points
else:
from importlib.metadata import entry_points
https://github.com/jupyterlab/jupyterlab_server/blob/main/jupyterlab_server/translation_utils.py#L20
Thanks for the notes @bollwyvl, I switched it to the group syntax |
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 again!
nbconvert/exporters/base.py
Outdated
@@ -136,7 +134,7 @@ def get_export_names(config=get_config()): # noqa | |||
Exporters can be found in external packages by registering | |||
them as an nbconvert.exporter entrypoint. | |||
""" | |||
exporters = sorted(entrypoints.get_group_named("nbconvert.exporters")) | |||
exporters = (e.name for e in entry_points(group="nbconvert.exporters")) |
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.
is this a generator? should probably still be sorted, as well...
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.
indeed, fixed
in my ci run tests are passing, but docs aren't, i assume the docs failure is unrelated? |
Yes, docs error is unrelated. Thanks again! |
entrypoints is deprecated and recommends switching to importlib-metadata. I've implemented this because I'm using a custom import mechanism that works with the documented importlib.metadata interface but not with entrypoints' custom logic