installer icon indicating copy to clipboard operation
installer copied to clipboard

scripts.py utilizes the deprecated read_binary function from importlib.resources.

Open stratakis opened this issue 3 years ago • 1 comments

When building for Fedora I noticed a deprecation warning:

DeprecationWarning: read_binary is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.

stratakis avatar Aug 03 '22 13:08 stratakis

As mentioned in the docs it links to, you cannot really take advantage of this deprecation warning without dropping compat for 50% of supported python versions. Honestly it always seemed odd to me that it's a warning at all (but the stability of importlib.resources is a separate topic).

eli-schwartz avatar Aug 03 '22 13:08 eli-schwartz

The current spot of use is:

https://github.com/pypa/installer/blob/8105b1d3a20f19d5a9026ede363015fbbd644ebc/src/installer/scripts.py#L6

I guess we could do something like:

if sys.version_info >= (3, 9):
    from importlib.resources import files

    def read_binary(package, file_path):
       return (files(package) / file_path).read_binary()
else:
    from importlib.resources import read_binary

It's dumb that I'll have to do this, but enough has been said about how messily the importlib.resources/importlib.metadata have handled backwards compatibility.

pradyunsg avatar Nov 25 '22 11:11 pradyunsg

This has become the case with Python 3.13 from which read_binary was removed. We are already hit by this as downstream packagers in Fedora Linux during the early integration with Python 3.13 alpha 1.

befeleme avatar Nov 22 '23 09:11 befeleme

I opened a PR: https://github.com/pypa/installer/pull/201

edgarrmondragon avatar Nov 23 '23 15:11 edgarrmondragon