Skip to content

Commit b3f7996

Browse files
committed
Disable DLL interface for CADET < v5. This will break tests with CADET < v5.
1 parent 26e19e9 commit b3f7996

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

cadet/cadet.py

+20
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ def __init__(self, install_path: Optional[Path] = None, use_dll: bool = False, *
219219
self._cadet_dll_runner: Optional[CadetDLLRunner] = CadetDLLRunner(
220220
self.cadet_dll_path
221221
)
222+
self._ensure_compatible_dll_version()
222223
else:
223224
self._cadet_dll_runner: Optional[CadetCLIRunner] = None
224225
self.use_dll = use_dll
@@ -271,7 +272,26 @@ def install_path(self, install_path: Optional[os.PathLike]) -> None:
271272
self._cadet_cli_runner = CadetCLIRunner(self.cadet_cli_path)
272273
if self.cadet_dll_path is not None:
273274
self._cadet_dll_runner = CadetDLLRunner(self.cadet_dll_path)
275+
self._ensure_compatible_dll_version()
274276

277+
def _ensure_compatible_dll_version(self):
278+
"""
279+
Ensure that the CADET DLL version is compatible with the required interface.
280+
281+
Raises
282+
------
283+
RuntimeError
284+
If `use_dll` is `True` and the CADET version is outdated (less than 5), indicating that
285+
the DLL interface is not supported.
286+
"""
287+
if int(self._cadet_dll_runner.cadet_version[0]) < 5:
288+
if self.use_dll:
289+
raise RuntimeError(
290+
f"CADET was set to `use_dll` but found outdated CADET "
291+
f"version {self._cadet_dll_runner.cadet_version} "
292+
f"which does not support the DLL interface."
293+
)
294+
self._cadet_dll_runner = None
275295

276296
@property
277297
def cadet_path(self) -> Optional[Path]:

cadet/cadet_dll.py

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ctypes
22
import io
33
import os
4+
import warnings
45
from pathlib import Path
56
from typing import Any, Optional
67

@@ -1645,6 +1646,13 @@ def __init__(self, dll_path: os.PathLike | str) -> None:
16451646
cdtGetLibraryBuildType.restype = ctypes.c_char_p
16461647
self._cadet_build_type = cdtGetLibraryBuildType().decode('utf-8')
16471648

1649+
if int(self._cadet_version[0]) < 5:
1650+
warnings.warn(
1651+
f"The detected CADET installation with version {self._cadet_version}"
1652+
" is below version 5.0 and does not support the DLL interface."
1653+
)
1654+
return
1655+
16481656
# Define the log handler callback type
16491657
self.LOG_HANDLER_CLBK = ctypes.CFUNCTYPE(
16501658
None,
@@ -1684,6 +1692,9 @@ def clear(self) -> None:
16841692
16851693
This method deletes the current simulation results and resets the driver.
16861694
"""
1695+
if int(self._cadet_version[0]) < 5:
1696+
return
1697+
16871698
if hasattr(self, "res"):
16881699
del self.res
16891700

@@ -1694,6 +1705,8 @@ def __del__(self) -> None:
16941705
"""
16951706
Clean up the CADET driver on object deletion.
16961707
"""
1708+
if int(self._cadet_version[0]) < 5:
1709+
return
16971710
self._api.deleteDriver(self._driver)
16981711

16991712
def setup_log_buffer(self, log_level: int = None) -> io.StringIO:

0 commit comments

Comments
 (0)