1616import sys
1717from typing import Union
1818
19- if sys .version_info [0 :2 ] <= (3 , 11 ):
20- from pkg_resources import resource_filename
21- else :
22- from importlib .resources import files
19+ from importlib .resources import files
2320
2421from wntr .epanet .msx .enums import TkObjectType , TkSourceType
2522
2926
3027logger = logging .getLogger (__name__ )
3128
32- epanet_toolkit = "wntr.epanet.toolkit"
3329
3430class MSXepanet (ENepanet ):
3531 def __init__ (self , inpfile = "" , rptfile = "" , binfile = "" , msxfile = "" ):
@@ -49,51 +45,27 @@ def __init__(self, inpfile="", rptfile="", binfile="", msxfile=""):
4945 self .msxfile = msxfile
5046
5147 try :
52- if sys .version_info [0 :2 ] <= (3 , 11 ):
53-
54- if os .name in ["nt" , "dos" ]:
55- libepanet = resource_filename (epanet_toolkit , "libepanet/windows-x64/epanet2.dll" )
56- libmsx = resource_filename (epanet_toolkit , "libepanet/windows-x64/epanetmsx.dll" )
57- elif sys .platform in ["darwin" ]:
58- if 'arm' in platform .platform ().lower ():
59- libepanet = resource_filename (epanet_toolkit , "libepanet/darwin-arm/libepanet2.dylib" )
60- libmsx = resource_filename (epanet_toolkit , "libepanet/darwin-arm/libepanetmsx.dylib" )
61- else :
62- libepanet = resource_filename (epanet_toolkit , "libepanet/darwin-x64/libepanet2.dylib" )
63- libmsx = resource_filename (epanet_toolkit , "libepanet/darwin-x64/libepanetmsx.dylib" )
48+ if os .name in ["nt" , "dos" ]:
49+ libepanet = str (files ('wntr.epanet' ).joinpath ("libepanet/windows-x64/epanet2.dll" ))
50+ libmsx = str (files ('wntr.epanet' ).joinpath ("libepanet/windows-x64/epanetmsx.dll" ))
51+ elif sys .platform in ["darwin" ]:
52+ if 'arm' in platform .platform ().lower ():
53+ libepanet = str (files ('wntr.epanet' ).joinpath ("libepanet/darwin-arm/libepanet2.dylib" ))
54+ libmsx = str (files ('wntr.epanet' ).joinpath ("libepanet/darwin-arm/libepanetmsx.dylib" ))
6455 else :
65- libepanet = resource_filename (epanet_toolkit , "libepanet/linux-x64/libepanet2.so" )
66- libmsx = resource_filename (epanet_toolkit , "libepanet/linux-x64/libepanetmsx.so" )
67-
68- dylib_dir = os .environ .get ('DYLD_FALLBACK_LIBRARY_PATH' ,'' )
69- if dylib_dir != '' :
70- if 'arm' in platform .platform ().lower ():
71- dylib_dir = dylib_dir + ':' + resource_filename (epanet_toolkit , "libepanet/darwin-arm" )
72- else :
73- dylib_dir = dylib_dir + ':' + resource_filename (epanet_toolkit , "libepanet/darwin-x64" )
74- os .environ ['DYLD_FALLBACK_LIBRARY_PATH' ] = dylib_dir
56+ libepanet = str (files ('wntr.epanet' ).joinpath ("libepanet/darwin-x64/libepanet2.dylib" ))
57+ libmsx = str (files ('wntr.epanet' ).joinpath ("libepanet/darwin-x64/libepanetmsx.dylib" ))
7558 else :
76- if os .name in ["nt" , "dos" ]:
77- libepanet = files (epanet_toolkit ).joinpath ("libepanet/windows-x64/epanet2.dll" )
78- libmsx = files (epanet_toolkit ).joinpath ("libepanet/windows-x64/epanetmsx.dll" )
79- elif sys .platform in ["darwin" ]:
80- if 'arm' in platform .platform ().lower ():
81- libepanet = files (epanet_toolkit ).joinpath ("libepanet/darwin-arm/libepanet2.dylib" )
82- libmsx = files (epanet_toolkit ).joinpath ("libepanet/darwin-arm/libepanetmsx.dylib" )
83- else :
84- libepanet = files (epanet_toolkit ).joinpath ("libepanet/darwin-x64/libepanet2.dylib" )
85- libmsx = files (epanet_toolkit ).joinpath ("libepanet/darwin-x64/libepanetmsx.dylib" )
59+ libepanet = str (files ('wntr.epanet' ).joinpath ("libepanet/linux-x64/libepanet2.so" ))
60+ libmsx = str (files ('wntr.epanet' ).joinpath ("libepanet/linux-x64/libepanetmsx.so" ))
61+
62+ dylib_dir = os .environ .get ('DYLD_FALLBACK_LIBRARY_PATH' ,'' )
63+ if dylib_dir != '' :
64+ if 'arm' in platform .platform ().lower ():
65+ dylib_dir = dylib_dir + ':' + str (files ('wntr.epanet' ).joinpath ("libepanet/darwin-arm" ))
8666 else :
87- libepanet = files (epanet_toolkit ).joinpath ("libepanet/linux-x64/libepanet2.so" )
88- libmsx = files (epanet_toolkit ).joinpath ("libepanet/linux-x64/libepanetmsx.so" )
89-
90- dylib_dir = os .environ .get ('DYLD_FALLBACK_LIBRARY_PATH' ,'' )
91- if dylib_dir != '' :
92- if 'arm' in platform .platform ().lower ():
93- dylib_dir = dylib_dir + ':' + files (epanet_toolkit ).joinpath ("libepanet/darwin-arm" )
94- else :
95- dylib_dir = dylib_dir + ':' + files (epanet_toolkit ).joinpath ("libepanet/darwin-x64" )
96- os .environ ['DYLD_FALLBACK_LIBRARY_PATH' ] = dylib_dir
67+ dylib_dir = dylib_dir + ':' + str (files ('wntr.epanet' ).joinpath ("libepanet/darwin-x64" ))
68+ os .environ ['DYLD_FALLBACK_LIBRARY_PATH' ] = dylib_dir
9769 if os .name in ["nt" , "dos" ]:
9870 self .ENlib = ctypes .windll .LoadLibrary (libmsx )
9971 else :
0 commit comments