From fa15e74700f737b4affb47ad6e58685f24f6dca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20And=C3=A9n?= Date: Mon, 18 Dec 2023 22:12:58 +0100 Subject: [PATCH] cuda+py: swap out `imp` for `importlib` --- python/cufinufft/cufinufft/_cufinufft.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/python/cufinufft/cufinufft/_cufinufft.py b/python/cufinufft/cufinufft/_cufinufft.py index d1553c72e..e2dc0d2d7 100644 --- a/python/cufinufft/cufinufft/_cufinufft.py +++ b/python/cufinufft/cufinufft/_cufinufft.py @@ -8,14 +8,7 @@ import ctypes import os import warnings - -# While imp is deprecated, it is currently the inspection solution -# that works for all versions of Python 2 and 3. -# One day if that changes, can be replaced -# with importlib.find_spec. -with warnings.catch_warnings(): - warnings.filterwarnings("ignore", category=DeprecationWarning) - import imp +import importlib.util from ctypes import c_double from ctypes import c_int @@ -42,10 +35,9 @@ try: if lib is None: # Find the library. - fh = imp.find_module('cufinufftc')[0] + lib_path = importlib.util.find_spec('cufinufftc').origin # Get the full path for the ctypes loader. - full_lib_path = os.path.realpath(fh.name) - fh.close() # Be nice and close the open file handle. + full_lib_path = os.path.realpath(lib_path) # Load the library, # which rpaths the libraries we care about.