sopel-irc / sopel-help

Help plugin for Sopel
Other
0 stars 1 forks source link

`pkg_resources` should be replaced with `importlib.metadata` #11

Open dgw opened 3 months ago

dgw commented 3 months ago

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.