Skip to content

Astropy's lazy loading mechanism doesn't survive deprecation warnings #12865

@neutrinoceros

Description

@neutrinoceros

Description

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 numpy/numpy@0ae08d0

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions