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

pkg_resources should be replaced with importlib.metadata #11

Open
dgw opened this issue May 28, 2024 · 1 comment
Open

pkg_resources should be replaced with importlib.metadata #11

dgw opened this issue May 28, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@dgw
Copy link
Member

dgw commented May 28, 2024

Sopel itself did this some time ago (sopel-irc/sopel#2261) for 8.0. The setuptools project discourages new usage of its pkg_resources library, and I should also note that a fresh installation of Python* raised an error when trying to load this plugin because it couldn't find pkg_resources; the setuptools package wasn't installed by default, and the plugin doesn't declare it as a runtime dependency.

Since using pkg_resources is discouraged, I'm opening an issue reminding us that a migration needs to happen instead of just making a quick PR to add setuptools as a runtime requirement.

Like sopel itself, this plugin should probably make use of the importlib_metadata backport package instead of try/except around different ways of calling importlib.metadata.entry_points(). The simple approach (subscripting as entry_points()['name'] or using entry_points().get('name)) worked up until Python 3.12, which now always returns an EntryPoints object instead of a dict-like.

The most natural time for this migration to happen, IMO, would be in the first release of sopel-help that no longer supports Sopel 7.x—meaning it would only need to make sure the importlib-based solution works on Python 3.8+ and not all the way back to py2.7.


* — In this specific case I was curiously testing sopel's master branch on Windows after recent chat in our IRC channel, but *nix Python environments that don't have setuptools unless it's manually installed from the system package manager or pip also exist.

@dgw
Copy link
Member Author

dgw commented Oct 19, 2024

#12 gets this most of the way to completion.

It has to use importlib_metadata (a backport library installable from PyPI) for the same reason as Sopel does upstream: API features that it needs around entry points don't exist in the stdlib importlib.metadata until Python 3.10.

When dropping Python 3.9, the importlib_metadata usage in this plugin can be converted to importlib.metadata, and the backport requirement dropped from package metadata.

@Exirel Exirel added the enhancement New feature or request label Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants