maubot / maubot

A plugin-based Matrix bot system.
https://mau.bot
GNU Affero General Public License v3.0
719 stars 92 forks source link

pkg_resources is deprecated #232

Open chayleaf opened 8 months ago

chayleaf commented 8 months ago

The setuptools documentation mentions:

Use of pkg_resources is deprecated in favor of importlib.resources, importlib.metadata and their backports (importlib_resources, importlib_metadata). Some useful APIs are also provided by packaging (e.g. requirements and version parsing). Users should refrain from new usage of pkg_resources and should work to port to importlib-based solutions.

Currently, Maubot has the following uses of pkg_resources:

https://github.com/maubot/maubot/blob/0c72e6fb1e0dcbccc718cff60f02e951b2b2cc57/maubot/cli/util/spdx.py#L30-L33

Corresponds to files('maubot.cli').joinpath('res/spdx.json.zip').open('rb')

(side note, wouldn't spdx.json.gz be a better option here?)

https://github.com/maubot/maubot/blob/0c72e6fb1e0dcbccc718cff60f02e951b2b2cc57/maubot/server.py#L104-L106

Corresponds to as_file(files('maubot').joinpath('management/frontend/build')), but this is a context manager for use with with statement so it doesn't directly translate to the existing usage

https://github.com/maubot/maubot/blob/0c72e6fb1e0dcbccc718cff60f02e951b2b2cc57/maubot/cli/commands/init.py#L20

https://github.com/maubot/maubot/blob/0c72e6fb1e0dcbccc718cff60f02e951b2b2cc57/maubot/cli/commands/init.py#L36-L38

Corresponds to files('maubot.cli').joinpath(filename).read_text(encoding='utf-8')

This should be pretty easy to port over to importlib. That said, the pkg_resources API will stay available for the foreseeable future.

HWiese1980 commented 3 months ago

I've added #241, hope it solves the issue.