summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2024-04-08 11:33:17 +0200
committerAnton Khirnov <anton@khirnov.net>2024-04-08 11:33:17 +0200
commitfdbb76ee8175e3e7133c12d7711faf059a090746 (patch)
tree06a3ab97cf3dad3dfe59ef29544f2ed8dfd706e3
parent01dc6b4cb806f953710fa158d529b98cd27a6c9a (diff)
interp: print a more informative message on SO loading failureHEADmaster
-rw-r--r--interp.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/interp.py b/interp.py
index 6ba20bc..c7c6f64 100644
--- a/interp.py
+++ b/interp.py
@@ -1,4 +1,5 @@
import ctypes
+from errno import ENOENT
import numpy as np
@@ -75,6 +76,14 @@ def interp2d(src_start, src_step, src_val, dst_coords, stencil):
_doubleptr = ctypes.POINTER(ctypes.c_double)
+class LibError(Exception):
+ _errmsg = """
+ Cannot load the interpolation library. Make sure you've built it (run 'make')
+ and the dynamic loader can locate it (e.g. add the directory to LD_LIBRARY_PATH).
+ """
+ def __init__(self):
+ super().__init__(self._errmsg)
+
class Interp2D_C:
_lib = None
_interp_func = None
@@ -93,8 +102,10 @@ class Interp2D_C:
_ret_c = None
def __init__(self, src_start, src_step, src_val, stencil):
- self._lib = ctypes.CDLL('lib_interp_c.so')
-
+ try:
+ self._lib = ctypes.CDLL('lib_interp_c.so')
+ except OSError as e:
+ raise LibError
func = getattr(self._lib, 'interp2d_%d' % stencil)
func.argtypes = [_doubleptr, _doubleptr, _doubleptr,