Astropy's lazy loading mechanism doesn't survive deprecation warnings
See original GitHub issueDescription
In testing a project downstream astropy, I configure pytest to treat warnings as errors (so as to detect and handle deprecation warnings as soon as possible). CI started failing today with dev versions of astropy and numpy, and it seems that the warning that’s being changed into an error can’t be easily ignored with pytest because astropy’s lazy loading mechanism escalates it into an ImportError
For reference, the breaking commit upstream was https://github.com/numpy/numpy/commit/0ae08d026eaf8a975156c9149e318812bb9586bb
Steps to Reproduce
this can be reproduced against the tip of astropy (or the latest release) with
python -m pip install git+https://github.com/numpy/numpy.git
python -Werror -c "import astropy.convolution"
Actual behavior
Traceback
Traceback (most recent call last):
File "/Users/robcleme/.pyenv/versions/amical-dev/lib/python3.10/site-packages/astropy/convolution/convolve.py", line 26, in <module>
_convolve = load_library("_convolve", LIBRARY_PATH)
File "/Users/robcleme/.pyenv/versions/amical-dev/lib/python3.10/site-packages/numpy/ctypeslib.py", line 137, in load_library
from numpy.distutils.misc_util import get_shared_lib_extension
File "/Users/robcleme/.pyenv/versions/amical-dev/lib/python3.10/site-packages/numpy/distutils/__init__.py", line 26, in <module>
from . import ccompiler
File "/Users/robcleme/.pyenv/versions/amical-dev/lib/python3.10/site-packages/numpy/distutils/ccompiler.py", line 8, in <module>
from distutils import ccompiler
File "/Users/robcleme/.pyenv/versions/3.10.2/lib/python3.10/distutils/__init__.py", line 19, in <module>
warnings.warn(_DEPRECATION_MESSAGE,
DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/robcleme/.pyenv/versions/amical-dev/lib/python3.10/site-packages/astropy/convolution/__init__.py", line 8, in <module>
from .convolve import convolve, convolve_fft, interpolate_replace_nans, convolve_models, convolve_models_fft # noqa
File "/Users/robcleme/.pyenv/versions/amical-dev/lib/python3.10/site-packages/astropy/convolution/convolve.py", line 28, in <module>
raise ImportError("Convolution C extension is missing. Try re-building astropy.")
ImportError: Convolution C extension is missing. Try re-building astropy.
Expected behavior
I’d expect the deprecation warning to surface by itself instead of being escalated. Long term, this deprecation warning needs to be handled, but it’s probably a difficult process that’ll take time. On the other hand, refactoring astropy’s lazy loading mechanism doesn’t seem like a much easier task. I have no idea if there’s any viable short-term strategy to handle this situation.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
sure
Could you make a PR if you’re already working on a patch ?