diff --git a/src/Python/ccpi/filters/utils.py b/src/Python/ccpi/filters/utils.py index 59661b3..0ef3c4b 100644 --- a/src/Python/ccpi/filters/utils.py +++ b/src/Python/ccpi/filters/utils.py @@ -1,31 +1,21 @@ import platform import ctypes import os +import warnings -if platform.system() == 'Linux': - dll = 'libcilreg.so' -elif platform.system() == 'Windows': - dll_file = 'cilreg.dll' - dll = ctypes.util.find_library(dll_file) -elif platform.system() == 'Darwin': - dll = 'libcilreg.dylib' -else: - raise ValueError('Not supported platform, ', platform.system()) +try: + pre = {'Linux': 'lib', 'Windows': '', 'Darwin': 'lib'}[platform.system()] + ext = {'Linux': '.so', 'Windows': '.dll', 'Darwin': '.dylib'}[platform.system()] +except KeyError: + raise ValueError(f"unsupported platform: {platform.system()}") -cilreg = ctypes.cdll.LoadLibrary(os.path.join(os.path.dirname(__file__), dll)) +_here = os.path.dirname(__file__) +dll = f'{pre}cilreg{ext}' +cilreg = ctypes.cdll.LoadLibrary(os.path.join(_here, dll)) +gpudll = f'{pre}cilregcuda{ext}' try: - if platform.system() == 'Linux': - gpudll = 'libcilregcuda.so' - elif platform.system() == 'Windows': - gpudll_file = 'cilregcuda.dll' - gpudll = ctypes.util.find_library(gpudll_file) - elif platform.system() == 'Darwin': - gpudll = 'libcilregcuda.dylib' - else: - raise ValueError('Not supported platform, ', platform.system()) - - cilregcuda = ctypes.cdll.LoadLibrary(os.path.join(os.path.dirname(__file__), gpudll)) -except OSError as ose: - print(ose) + cilregcuda = ctypes.cdll.LoadLibrary(os.path.join(_here, gpudll)) +except OSError as exc: + warnings.warn(str(exc), ImportWarning, stacklevel=2) cilregcuda = None