Skip to content

Commit b42008d

Browse files
committed
load local dll first
Signed-off-by: Tony Xiang <19280867+TonyXiang8787@users.noreply.github.com>
1 parent 02fb305 commit b42008d

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/power_grid_model/_core/power_grid_core.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,15 @@ def _load_core() -> CDLL:
126126
Returns: DLL/SO object
127127
128128
"""
129-
if "CONDA_PREFIX" in os.environ:
130-
# if conda environment, use the dll file from the conda environment
129+
# first try to find the DLL local
130+
if platform.system() == "Windows":
131+
dll_file = "_power_grid_core.dll"
132+
else:
133+
dll_file = "_power_grid_core.so"
134+
dll_path = Path(__file__).parent / dll_file
135+
136+
# if local DLL is not found, try to find the DLL from conda environment
137+
if (not dll_path.exists()) and ("CONDA_PREFIX" in os.environ):
131138
if platform.system() == "Windows":
132139
dll_file = "power_grid_model_c.dll"
133140
elif platform.system() == "Darwin":
@@ -137,15 +144,9 @@ def _load_core() -> CDLL:
137144
else:
138145
raise NotImplementedError(f"Unsupported platform: {platform.system()}")
139146
# the dll will be found through conda environment
140-
dll_path = dll_file
141-
else:
142-
# else use the dll file from the current directory
143-
if platform.system() == "Windows":
144-
dll_file = "_power_grid_core.dll"
145-
else:
146-
dll_file = "_power_grid_core.so"
147-
dll_path = str(Path(__file__).parent / dll_file)
148-
cdll = CDLL(dll_path)
147+
dll_path = Path(dll_file)
148+
149+
cdll = CDLL(str(dll_path))
149150
# assign return types
150151
# handle
151152
cdll.PGM_create_handle.argtypes = []

0 commit comments

Comments
 (0)