Skip to content

Commit

Permalink
Disable DLL interface for CADET < v5. This will break tests with CADE…
Browse files Browse the repository at this point in the history
…T < v5.
  • Loading branch information
ronald-jaepel committed Aug 20, 2024
1 parent 26e19e9 commit b3f7996
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cadet/cadet.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def __init__(self, install_path: Optional[Path] = None, use_dll: bool = False, *
self._cadet_dll_runner: Optional[CadetDLLRunner] = CadetDLLRunner(
self.cadet_dll_path
)
self._ensure_compatible_dll_version()
else:
self._cadet_dll_runner: Optional[CadetCLIRunner] = None
self.use_dll = use_dll
Expand Down Expand Up @@ -271,7 +272,26 @@ def install_path(self, install_path: Optional[os.PathLike]) -> None:
self._cadet_cli_runner = CadetCLIRunner(self.cadet_cli_path)
if self.cadet_dll_path is not None:
self._cadet_dll_runner = CadetDLLRunner(self.cadet_dll_path)
self._ensure_compatible_dll_version()

def _ensure_compatible_dll_version(self):
"""
Ensure that the CADET DLL version is compatible with the required interface.
Raises
------
RuntimeError
If `use_dll` is `True` and the CADET version is outdated (less than 5), indicating that
the DLL interface is not supported.
"""
if int(self._cadet_dll_runner.cadet_version[0]) < 5:
if self.use_dll:
raise RuntimeError(
f"CADET was set to `use_dll` but found outdated CADET "
f"version {self._cadet_dll_runner.cadet_version} "
f"which does not support the DLL interface."
)
self._cadet_dll_runner = None

@property
def cadet_path(self) -> Optional[Path]:
Expand Down
13 changes: 13 additions & 0 deletions cadet/cadet_dll.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ctypes
import io
import os
import warnings
from pathlib import Path
from typing import Any, Optional

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

if int(self._cadet_version[0]) < 5:
warnings.warn(
f"The detected CADET installation with version {self._cadet_version}"
" is below version 5.0 and does not support the DLL interface."
)
return

# Define the log handler callback type
self.LOG_HANDLER_CLBK = ctypes.CFUNCTYPE(
None,
Expand Down Expand Up @@ -1684,6 +1692,9 @@ def clear(self) -> None:
This method deletes the current simulation results and resets the driver.
"""
if int(self._cadet_version[0]) < 5:
return

if hasattr(self, "res"):
del self.res

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

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

0 comments on commit b3f7996

Please sign in to comment.