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

Replace use of pkg_resources with importlib_metadata #789

Closed
corranwebster opened this issue Nov 2, 2020 · 5 comments · Fixed by #790
Closed

Replace use of pkg_resources with importlib_metadata #789

corranwebster opened this issue Nov 2, 2020 · 5 comments · Fixed by #790
Labels
difficulty: intermediate Issues which need some context about the package. type: enhancement

Comments

@corranwebster
Copy link
Contributor

Python 3.8 introduces standard library code for entrypoint handling via the importlib.metadata module. This is back-ported to earlier versions of Python via importlib_metadata.

This should give better forward compatibility, and may help people who want to freeze Pyface/TraitsUI apps.

@corranwebster corranwebster added type: enhancement difficulty: intermediate Issues which need some context about the package. labels Nov 2, 2020
@rahulporuri
Copy link
Contributor

Using importlib.metadata instead of pkg_resources also improves startup time.

❯ python -Ximporttime -c "import importlib.metadata"
import time: self [us] | cumulative | imported package
...
import time:      6528 |     141065 | importlib.metadata

❯ python -Ximporttime -c "import pkg_resources"
import time: self [us] | cumulative | imported package
...
import time:     28439 |     441931 | pkg_resources

I consistently see 400-450 ms for pkg_resources vs 100-150 ms for importlib.metadata. Note that this is with python 3.8.6. I mostly see the same numbers on python 3.9.

@rahulporuri rahulporuri added this to Sprint backlog in Enthought OSS Q4 2020 Nov 2, 2020
@rahulporuri
Copy link
Contributor

@corranwebster i've added this to the Q4 2020 sprint backlog, in hopes that we can find time to address this before the end of the quarter.

@mdickinson
Copy link
Member

mdickinson commented Nov 3, 2020

Current uses of pkg_resources fall into two different categories: resource location and entry-point enumeration - we'll need importlib.resources rather than importlib.metadata for the first category.

Last time we looked at importlib.resources, it had issues (namely that data directories had to be full-blown Python packages for things to work). That's changed since Python 3.9, and in the importlib_resources backport, so it may be worth another look.

Related issue: https://gitlab.com/python-devs/importlib_resources/-/issues/58

@kitchoi
Copy link
Contributor

kitchoi commented Nov 13, 2020

#790 only resolves half of the usage of pkg_resources, we still have #791 pending.

@kitchoi kitchoi reopened this Nov 13, 2020
@rahulporuri rahulporuri moved this from Done to In Progress in Enthought OSS Q4 2020 Nov 13, 2020
@rahulporuri
Copy link
Contributor

closing as #791 is also merged.

@rahulporuri rahulporuri moved this from In Progress to Done in Enthought OSS Q4 2020 Nov 24, 2020
@rahulporuri rahulporuri moved this from Done to Sprint 4 : Nov 16 - Nov 27 2020 in Enthought OSS Q4 2020 Nov 29, 2020
yoda-vid added a commit to sanderslab/magellanmapper that referenced this issue Mar 10, 2021
Pyface now depends on the `import_metadata` and `import_resources` (see enthought/pyface#789), which do not appear to be picked up as dependencies in the current Conda package (see enthought/mayavi#1000). As a workaround, add these packages explicitly in the Conda environment spec.
yoda-vid added a commit to sanderslab/magellanmapper that referenced this issue Mar 10, 2021
Pyface now depends on the `import_metadata` and `import_resources` (see enthought/pyface#789), which do not appear to be picked up as dependencies in the current Conda package (see enthought/mayavi#1000). As a workaround, add these packages explicitly in the Conda environment spec.

(cherry picked from commit 3ded78f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: intermediate Issues which need some context about the package. type: enhancement
Projects
No open projects
Enthought OSS Q4 2020
Sprint 4 : Nov 16 - Nov 27 2020
Development

Successfully merging a pull request may close this issue.

4 participants