Skip to content

Commit 1d6e210

Browse files
DaanVanVugtclaude
andcommitted
Fix compatibility with imas-python >= 2.2
imas-python 2.2 removed the has_imas attribute, and importing imas.backends.imas_core.imas_interface now raises ImportError when imas_core is not installed (iterorganization/IMAS-Python#92), crashing _check_imas_version with AttributeError. Detect the access layer by importing ll_interface and checking _al_version instead, which works on both old and new imas-python. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent abc227a commit 1d6e210

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

‎imas_validator/validate/validate.py‎

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,25 @@ def validate(
6262
def _check_imas_version() -> None:
6363
"""Check if the installed IMAS version is sufficient."""
6464
# TODO: check if this is the best level to test for the IMAS version
65-
if not imas.backends.imas_core.imas_interface.has_imas:
66-
version_found = imas.backends.imas_core.imas_interface.ll_interface._al_version
67-
if version_found is None:
68-
logger.info(
69-
"No IMAS install could be found."
70-
"IDS Validation will work with limited functionality."
71-
)
72-
return
73-
else:
74-
logger.info(f"Found IMAS install with version {version_found}.")
75-
76-
if imas.backends.imas_core.imas_interface.ll_interface._al_version < Version("5.1"):
65+
try:
66+
# On imas-python >= 2.2 this import raises ImportError when imas_core
67+
# is not installed. On older versions the import always succeeds and
68+
# _al_version is None when the access layer is missing.
69+
from imas.backends.imas_core.imas_interface import ll_interface
70+
except ImportError:
71+
version_found = None
72+
else:
73+
version_found = ll_interface._al_version
74+
75+
if version_found is None:
76+
logger.info(
77+
"No IMAS install could be found."
78+
"IDS Validation will work with limited functionality."
79+
)
80+
return
81+
82+
logger.info(f"Found IMAS install with version {version_found}.")
83+
if version_found < Version("5.1"):
7784
logger.info(
7885
"IDS Validation requires an IMAS installation of version 5.1 or newer."
7986
"See the README for more details."

0 commit comments

Comments
 (0)