keflavich / FITS_tools

Simple scipy and python based tools for FITS image manipulation
17 stars 12 forks source link

Python 3.12 deprecated imp #14

Open moemyself3 opened 9 months ago

moemyself3 commented 9 months ago

I was running some code that called FITS_tools and found that imp has been deprecated in python 3.12.

I see that the only method called is imp.reload so you may be able to swap it for importlib.reload (introduced python 3.1)

https://github.com/keflavich/FITS_tools/blob/80616e3301931e3157d54738a9c63ac03c0172f5/ah_bootstrap.py#L36

I can start a pull request if you'd like.

keflavich commented 9 months ago

yeah, the way I'd like to do it is:

try:
    import imp
except ImportError:
    import importlib as imp

A PR is welcome, though!

moemyself3 commented 9 months ago

Ohh indeed! Much better since it preserves older python.

Hmm I cracked this open a bit further. I made the change on your code, but now it falls on the deprecated and archived astropy_helpers/astropy_helpers/utils.py:

https://github.com/astropy/astropy-helpers/blob/14ca346b0da3e92e65bdc398cc8f726cbd7be57d/astropy_helpers/utils.py#L6

seems like it'll continue to fail unless the use is changed in the helpers as well. I'll try it out to see if we can get it to work.

keflavich commented 9 months ago

Yeah, I need to replace astropy-helpers entirely; that whole package is deprecated. If you want to give it a go, I'd be happy to merge that.

moemyself3 commented 9 months ago

I was able to make changes in the astropy-helpers package to the point that I was able to install FITS_tools locally using pip.

Essentially the import_file() method needed to be updated using importlib. That being said, I'm at the edge of my knowledge with git and submodules. I made the commit of changes to astropy-helpers on my local fork of FITS_tools and realized that the changes are not preserved. When I check the commit to changes on astropy-helpers it point to a 404.

I am assuming the way to make this work is to fork the astropy-helpers make changes to my fork and link the submodule to that one instead.

Let me know what you think. I know this is really just a stopgap until astropy-helpers can be replaced.

keflavich commented 9 months ago

Actually, the best thing is just to totally remove astropy-helpers.... we've done this before in, e.g., https://github.com/radio-astro-tools/spectral-cube/pull/599

mcyc commented 1 month ago

I've overhauled setup.py and made a PR (https://github.com/keflavich/FITS_tools/pull/17) to address this issue. @keflavich, can you double-check to see if I'm missing anything, including if setup.cfg is still needed? I haven't had issues with this implementation so far.

If this is good, I think we can safely remove ah_bootstrap.py as well.