From 70b8dbd467959c2a3c45ae03897f56e71928b840 Mon Sep 17 00:00:00 2001 From: aferust Date: Mon, 27 Sep 2021 10:52:38 +0300 Subject: [PATCH] dylib loading for Darwin, and fix relative dllpath --- epanet-module/epamodule.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/epanet-module/epamodule.py b/epanet-module/epamodule.py index 71552aa..98e23c1 100644 --- a/epanet-module/epamodule.py +++ b/epanet-module/epamodule.py @@ -2,18 +2,22 @@ added function ENsimtime""" - +import sys +import os import ctypes import platform import datetime +this_dir = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(this_dir) + _plat= platform.system() if _plat=='Linux': _lib = ctypes.CDLL("libepanet2.so.2") elif _plat=='Windows': try: # if epanet2.dll compiled with __cdecl (as in OpenWaterAnalytics) - _lib = ctypes.CDLL("epamodule\epanet2.dll") + _lib = ctypes.CDLL(os.path.join(this_dir, "epamodule", "epanet2.dll")) _lib.ENgetversion(ctypes.byref(ctypes.c_int())) except ValueError: # if epanet2.dll compiled with __stdcall (as in EPA original DLL) @@ -22,7 +26,8 @@ _lib.ENgetversion(ctypes.byref(ctypes.c_int())) except ValueError: raise Exception("epanet2.dll not suitable") - +elif _plat=='Darwin': + _lib = ctypes.CDLL(os.path.join(this_dir, "epamodule", "libepanet2.dylib")) else: Exception('Platform '+ _plat +' unsupported (not yet)')