Skip to content

Commit 4bd8128

Browse files
committed
fmk - replacing pkg_resource as module deprecated
1 parent 32fc25e commit 4bd8128

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

modules/Workflow/whale/main.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,33 @@
6969
from copy import deepcopy
7070
from datetime import datetime
7171
from pathlib import Path, PurePath
72-
import pkg_resources
72+
import platform
7373

7474
# check python
7575

7676
python_path= sys.executable
7777
a = platform.uname()
78+
7879
if a.system == "Darwin" and (not a.machine=='x86_64'):
7980
raise ValueError(f"Python version mismatch. Please update the python following the installation instruction. Current python {python_path} is based on machine={a.machine}, but we need the one for x86_64")
8081
exit(-2)
8182

8283
# checking if nheri-simcenter is installed
83-
if not ('nheri-simcenter' in [p.project_name for p in pkg_resources.working_set]):
84-
if (platform.system() == 'Windows'):
85-
raise ValueError(f"Essential python package (nheri-simcenter) is not installed. Please go to file-preference and press reset to initialize the python path.")
86-
exit(-2)
84+
required_pkg = "nheri-simcenter"
85+
installed_pkgs = {dist.metadata['Name'].lower() for dist in metadata.distributions()}
86+
if required_pkg.lower() not in installed_pkgs:
87+
if platform.system() == 'Windows':
88+
raise ValueError(
89+
f"Essential Python package ({required_pkg}) is not installed. "
90+
"Please go to File → Preferences and press Reset to initialize the Python path."
91+
)
8792
else:
88-
raise ValueError(f"Essential python package (nheri-simcenter) is not installed. Please follow the installation instruction or run: {python_path} -m pip3 install nheri-simcenter")
89-
exit(-2)
90-
93+
python_path = sys.executable
94+
raise ValueError(
95+
f"Essential Python package ({required_pkg}) is not installed. "
96+
f"Please follow the installation instructions or run:\n\n"
97+
f"{python_path} -m pip install {required_pkg}"
98+
)
9199

92100
import shutil
93101
import numpy as np

0 commit comments

Comments
 (0)