diff --git a/python/cufinufft/cufinufft/_cufinufft.py b/python/cufinufft/cufinufft/_cufinufft.py index ee51f0490..944417518 100644 --- a/python/cufinufft/cufinufft/_cufinufft.py +++ b/python/cufinufft/cufinufft/_cufinufft.py @@ -13,6 +13,8 @@ import numpy as np from ctypes.util import find_library +from packaging.version import Version + from ctypes import c_double from ctypes import c_int from ctypes import c_int64 @@ -23,6 +25,16 @@ c_float_p = ctypes.POINTER(c_float) c_double_p = ctypes.POINTER(c_double) + +# numpy.distutils has a bug that changes the logging level from under us. As a +# workaround, we save it and reset it later. This only happens on older +# versions of NumPy, so let's check the version before doing this. +reset_log_level = Version(np.__version__) < Version("1.25") + +if reset_log_level: + import logging + log_level = logging.root.level + lib = None # Try to load the library as installed in the Python package. path = pathlib.Path(__file__).parent.resolve() @@ -35,6 +47,9 @@ # Paranoid, in case lib is set to something and then an exception is thrown lib = None +if reset_log_level: + logging.root.setLevel(log_level) + if lib is None: # If that fails, try to load the library from the system path. libname = find_library('cufinufft') diff --git a/python/finufft/finufft/_finufft.py b/python/finufft/finufft/_finufft.py index fe2748d70..99969a38c 100644 --- a/python/finufft/finufft/_finufft.py +++ b/python/finufft/finufft/_finufft.py @@ -19,11 +19,22 @@ import platform from numpy.ctypeslib import ndpointer +from packaging.version import Version + c_int_p = ctypes.POINTER(c_int) c_float_p = ctypes.POINTER(c_float) c_double_p = ctypes.POINTER(c_double) c_longlong_p = ctypes.POINTER(c_longlong) +# numpy.distutils has a bug that changes the logging level from under us. As a +# workaround, we save it and reset it later. This only happens on older +# versions of NumPy, so let's check the version before doing this. +reset_log_level = Version(np.__version__) < Version("1.25") + +if reset_log_level: + import logging + log_level = logging.root.level + # TODO: See if there is a way to improve this so it is less hacky. lib = None # Try to load finufft installed from the python package. @@ -40,6 +51,9 @@ # Paranoid, in case lib is set to something and then an exception is thrown lib = None +if reset_log_level: + logging.root.setLevel(log_level) + if lib is None: # If that fails, try to load the library from the system path. libname = find_library('finufft')