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

Using pkg_resources makes package load really slow #59

Closed
chrisjsewell opened this issue Nov 8, 2021 · 9 comments
Closed

Using pkg_resources makes package load really slow #59

chrisjsewell opened this issue Nov 8, 2021 · 9 comments

Comments

@chrisjsewell
Copy link

chrisjsewell commented Nov 8, 2021

Heya, this change really hurts package loading times 😬

__version__ = pkg_resources.get_distribution("shortuuid").version

For example, with our CLI this change has meant an increase in load time from ~0.3 seconds to ~0.8 seconds!

pkg_resources is essentially deprecated, in part, for this very reason; replaced by https://docs.python.org/3/library/importlib.metadata.html and the https://github.com/python/importlib_metadata backport

@skorokithakis
Copy link
Owner

Hey @chrisjsewell, thanks for this! I mixed up the old and new methods :( Can you check the latest master and see that it works properly?

@chrisjsewell
Copy link
Author

Thanks for the quick reply, I haven't check the timing yet, but I would note that using importlib.metadata will mean your package no longer supports python<3.8. Is that what you want?

@skorokithakis
Copy link
Owner

Oof, no, I didn't notice the version... Do I need to use the backport then?

@chrisjsewell
Copy link
Author

Yep use the backport 👍 and also you can just do importlib_metadata.version("shortuuid")

@chrisjsewell
Copy link
Author

also, the error to catch is importlib_metadata.PackageNotFoundError

@skorokithakis
Copy link
Owner

Hm, right. Given the frequency with which this library changes, I'm just going to type the version in by hand :P

@chrisjsewell
Copy link
Author

Haha yep that's good by me!
(with setuptools or flit, you can just have the version read from the init and you don't have to put it in the pyproject.toml/setup.cfg)

@skorokithakis
Copy link
Owner

But I want it in the pyproject.toml, as it's easier for my deployment tooling to parse :/ Too bad, thanks for your help though!

@socketpair
Copy link

pypa/setuptools#926

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

No branches or pull requests

3 participants