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

switch from entrypoints to importlib-metadata #1782

Merged
merged 4 commits into from
Jun 8, 2022

Conversation

konstin
Copy link
Contributor

@konstin konstin commented Jun 1, 2022

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

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
Copy link
Contributor

@blink1073 blink1073 left a 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",
Copy link
Contributor

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.

@@ -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"]
Copy link
Contributor

@bollwyvl bollwyvl Jun 2, 2022

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

@@ -5,7 +5,10 @@

import os

import entrypoints
try:
Copy link
Contributor

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

@konstin
Copy link
Contributor Author

konstin commented Jun 5, 2022

Thanks for the notes @bollwyvl, I switched it to the group syntax

Copy link
Contributor

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again!

@@ -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"))
Copy link
Contributor

@bollwyvl bollwyvl Jun 7, 2022

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, fixed

@konstin
Copy link
Contributor Author

konstin commented Jun 8, 2022

in my ci run tests are passing, but docs aren't, i assume the docs failure is unrelated?

@blink1073
Copy link
Contributor

Yes, docs error is unrelated. Thanks again!

@blink1073 blink1073 merged commit 1038482 into jupyter:main Jun 8, 2022
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.

3 participants