Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logging bug caused by np.distutils #545

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions python/cufinufft/cufinufft/_cufinufft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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')
Expand Down
14 changes: 14 additions & 0 deletions python/finufft/finufft/_finufft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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')
Expand Down
Loading