Skip to content

Commit f78bf99

Browse files
authored
Fix pkg_resources deprecation and CI build failures (#552)
* add setuptools limit * remove pkg resources dependency * fix import * fix windows path bug
1 parent ff92119 commit f78bf99

File tree

6 files changed

+36
-86
lines changed

6 files changed

+36
-86
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools", "numpy>=2.2.6 "]
2+
requires = ["setuptools", "numpy>=2.2.6"]
33
build-backend = "setuptools.build_meta"
44

55
[tool.pytest.ini_options]

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ scipy
44
networkx
55
pandas>=2.0
66
matplotlib
7-
setuptools
7+
setuptools<69.5.1
88

99
# Optional
1010
plotly<6.0

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
MAINTAINER_EMAIL = 'kaklise@sandia.gov'
7373
LICENSE = 'Revised BSD'
7474
URL = 'https://github.com/USEPA/WNTR'
75-
DEPENDENCIES = ['numpy>=2.2.6 ', 'scipy', 'networkx', 'pandas>=2.0', 'matplotlib', 'setuptools']
75+
DEPENDENCIES = ['numpy>=2.2.6', 'scipy', 'networkx', 'pandas>=2.0', 'matplotlib']
7676

7777
# use README file as the long description
7878
file_dir = os.path.abspath(os.path.dirname(__file__))

wntr/epanet/msx/toolkit.py

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
import sys
1717
from 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

2421
from wntr.epanet.msx.enums import TkObjectType, TkSourceType
2522

@@ -29,7 +26,6 @@
2926

3027
logger = logging.getLogger(__name__)
3128

32-
epanet_toolkit = "wntr.epanet.toolkit"
3329

3430
class 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:

wntr/epanet/toolkit.py

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
import sys
1111
from ctypes import byref
1212

13-
if sys.version_info[0:2] <= (3, 11):
14-
from pkg_resources import resource_filename
15-
else:
16-
from importlib.resources import files
13+
from importlib.resources import files
1714

1815
from .exceptions import EN_ERROR_CODES, EpanetException
1916
from .util import SizeLimits
@@ -108,30 +105,17 @@ def __init__(self, inpfile="", rptfile="", binfile="", version=2.2):
108105
self.binfile = binfile
109106

110107
try:
111-
if sys.version_info[0:2] <= (3, 11):
112-
if float(version) == 2.0:
113-
libname = libepanet.replace('epanet22.','epanet20.')
114-
if 'arm' in platform.platform():
115-
raise NotImplementedError('ARM-based processors not supported for version 2.0 of EPANET. Please use version=2.2')
116-
else:
117-
libname = libepanet
118-
libname = resource_filename(__name__, libname)
119-
if os.name in ["nt", "dos"]:
120-
self.ENlib = ctypes.windll.LoadLibrary(libname)
121-
else:
122-
self.ENlib = ctypes.cdll.LoadLibrary(libname)
108+
if float(version) == 2.0:
109+
libname = libepanet.replace('epanet22.','epanet20.')
110+
if 'arm' in platform.platform():
111+
raise NotImplementedError('ARM-based processors not supported for version 2.0 of EPANET. Please use version=2.2')
112+
else:
113+
libname = libepanet
114+
libname = str(files('wntr.epanet').joinpath(libname))
115+
if os.name in ["nt", "dos"]:
116+
self.ENlib = ctypes.windll.LoadLibrary(libname)
123117
else:
124-
if float(version) == 2.0:
125-
libname = libepanet.replace('epanet22.','epanet20.')
126-
if 'arm' in platform.platform():
127-
raise NotImplementedError('ARM-based processors not supported for version 2.0 of EPANET. Please use version=2.2')
128-
else:
129-
libname = libepanet
130-
libname = files(__name__).joinpath(libname)
131-
if os.name in ["nt", "dos"]:
132-
self.ENlib = ctypes.windll.LoadLibrary(libname)
133-
else:
134-
self.ENlib = ctypes.cdll.LoadLibrary(libname)
118+
self.ENlib = ctypes.cdll.LoadLibrary(libname)
135119
except:
136120
raise
137121
finally:

wntr/library/msx/_msxlibrary.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@
1818

1919
import json
2020
import logging
21-
import os, sys
21+
import os
2222
from typing import Any, ItemsView, Iterator, KeysView, List, Tuple, Union, ValuesView
2323

24-
if sys.version_info[0:2] <= (3, 11):
25-
from pkg_resources import resource_filename
26-
else:
27-
from importlib.resources import files
24+
from importlib.resources import files
2825

2926
from wntr.msx.base import ExpressionType, ReactionType, SpeciesType
3027
from wntr.msx.model import MsxModel
@@ -102,10 +99,7 @@ def __init__(self, extra_paths: List[str] = None, include_builtins=True,
10299
self.__data = dict()
103100

104101
if include_builtins:
105-
if sys.version_info[0:2] <= (3, 11):
106-
default_path = os.path.abspath(resource_filename(__name__, '.'))
107-
else:
108-
default_path = os.path.abspath(files('wntr.library.msx').joinpath('.'))
102+
default_path = os.path.abspath(files('wntr.library.msx').joinpath('.'))
109103
if default_path not in self.__library_paths:
110104
self.__library_paths.append(default_path)
111105

0 commit comments

Comments
 (0)