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

Use importlib.metadata instead of pkg_resources #132

Closed
wants to merge 1 commit into from

Conversation

jnns
Copy link

@jnns jnns commented Apr 14, 2023

pkg_resources is deprecated and emits warning messages.

Fixes #131

@adamchainz
Copy link
Contributor

Thanks for working on this.

I would vote for dropping the __version__ attribute. Users who need the version can use importlib.metadata themselves. For the rest of us, loading and parsing it just wastes startup time.

Some data: I removed the __version__ attributes from ~20 packages in 2019, referring to importlib.metadata instead, e.g. https://github.com/adamchainz/apig-wsgi/blob/main/CHANGELOG.rst#240-2019-11-15 . I saw no complaints.

@jnns
Copy link
Author

jnns commented Apr 25, 2023

Thank you, Adam. I like your suggestion of removing __version__ and will adapt the pull request accordingly

Comment on lines +7 to +11
* Removed usage of pkg_resource to avoid derecation
warnings. If you want to inspect the installed version,
use ``importlib.metadata.version("django-widget-tweaks")``
(`docs <https://docs.python.org/3.8/library/importlib.metadata.html#distribution-versions>`__ /
`backport <https://pypi.org/project/importlib-metadata/>`__).
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix some typos, and remove the backport link, since nearly everyone runs Python 3.8+ now, and 3.7 is EOL in a couple months.

Suggested change
* Removed usage of pkg_resource to avoid derecation
warnings. If you want to inspect the installed version,
use ``importlib.metadata.version("django-widget-tweaks")``
(`docs <https://docs.python.org/3.8/library/importlib.metadata.html#distribution-versions>`__ /
`backport <https://pypi.org/project/importlib-metadata/>`__).
* Removed usage of ``pkg_resources`` to avoid deprecation
warnings. If you want to inspect the installed version,
use ``importlib.metadata.version("django-widget-tweaks")``
(`docs <https://docs.python.org/3/library/importlib.metadata.html#distribution-versions>`__).

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. 3.7 is now EOL. But we should stop testing on it too. Similar for old EOL Django versions like 2.2. Is there a policy regarding support for old versions?

@deeprave
Copy link
Contributor

+1

I recently started using Rye as my project manager - it does not install nor use pip so there is none of its vendored dependencies either including pkg_resources. setuptools is not explicitly listed as a dependency, so consequently importing this module fails.

@deeprave
Copy link
Contributor

Probably shouldn't remove version as it appears to be used by setup.py.

While setup.py is also deprecated, short of a larger change to convert to pyproject, in the meantime, importlib needs to be used (and works fine, tested locally). I will submit the alternative as a PR. Performance impact is pretty low given that python only imports a module once.

I also think it's poor practice to submit commented out code, but that is just IMHO :-)

@georgek
Copy link
Contributor

georgek commented Aug 24, 2023

Closed in favour of #135 as I don't see point of removing __version__. Also did remove 3.7 support.

@georgek georgek closed this Aug 24, 2023
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

Successfully merging this pull request may close these issues.

widget_tweaks causes 'DeprecationWarning: pkg_resources is deprecated as an API'
4 participants