From 0ed8e6ea1b9aff54c2bd3011fac006608457b3a3 Mon Sep 17 00:00:00 2001 From: Robert Roos Date: Fri, 20 Sep 2024 16:19:48 +0200 Subject: [PATCH] Changed adslib DLL finder logic --- src/pyads/pyads_ex.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/pyads/pyads_ex.py b/src/pyads/pyads_ex.py index 2884f687..8b05ce65 100644 --- a/src/pyads/pyads_ex.py +++ b/src/pyads/pyads_ex.py @@ -79,14 +79,19 @@ ) elif platform_is_linux(): - # try to load local adslib.so in favor to global one - local_adslib = os.path.join(os.path.dirname(__file__), "adslib.so") - if os.path.isfile(local_adslib): - adslib = local_adslib - else: - adslib = "adslib.so" + adslib_path = None - _adsDLL = ctypes.CDLL(adslib) + for p in sys.path: + adslib_path = os.path.join(p, "adslib.so") + if os.path.exists(adslib_path): + break + + if adslib_path is None: + raise OSError(f"Failed to locate `adslib.so` library in {sys.path}") + + # For some reason loading on just "adslib.so" always fails, even if it is under + # sys.path, so manually search for it first + _adsDLL = ctypes.CDLL(adslib_path) NOTEFUNC = ctypes.CFUNCTYPE( None,