esheldon / fitsio

A python package for FITS input/output wrapping cfitsio
GNU General Public License v2.0
133 stars 57 forks source link

pkg_resources is deprecated #360

Closed rmjarvis closed 1 year ago

rmjarvis commented 1 year ago

I'm getting deprecation warnings from importing fitsio lately. At least on 3.10 (I didn't try other versions).

It looks like the whole pkg_resources API is deprecated now and fitsio imports it as a top-line import, even though AFAICT it's only used in testing.

The easiest fix would be to move the import into the testGZIPTileCompressedReadLosslessAstropy function, so it would only trigger if someone ran that function. (Presumably just the CI test suite I suspect.) But probably better to figure out what the new blessed API is for this and switch over.

To replicate:

$ python -W error -c "import fitsio"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/Mike/mambaforge/envs/py3.10/lib/python3.10/site-packages/fitsio/__init__.py", line 39, in <module>
    from . import test
  File "/Users/Mike/mambaforge/envs/py3.10/lib/python3.10/site-packages/fitsio/test.py", line 7, in <module>
    from pkg_resources import resource_filename
  File "/Users/Mike/mambaforge/envs/py3.10/lib/python3.10/site-packages/pkg_resources/__init__.py", line 121, in <module>
    warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)
DeprecationWarning: pkg_resources is deprecated as an API
beckermr commented 1 year ago

Ohhhh man why. We need to move to importlib.resources and the back ports. What a pain.

beckermr commented 1 year ago

https://setuptools.pypa.io/en/latest/pkg_resources.html

Use of pkg_resources is deprecated in favor of importlib.resources, importlib.metadata, and their backports (importlib_resources, importlib_metadata). Users should refrain from new usage of pkg_resources and should work to port to importlib-based solutions.