Skip to content

Commit 4f056f2

Browse files
syntronadeas31
andauthored
(A009) [ModelicaSystem] small fixes (#419)
* [ModelicaSystemOMC] add docstring for sendExpression() * [ModelicaSystemBase] define parse_om_version() as staticmethod * [ModelicaSystemBase] include the original exception if reraised as ModelExecutionException --------- Co-authored-by: Adeel Asghar <adeel.asghar@liu.se>
1 parent 998b0f7 commit 4f056f2

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,9 @@ def buildModel(self, variableFilter: Optional[str] = None):
556556
self._xmlparse(xml_file=xml_file)
557557

558558
def sendExpression(self, expr: str, parsed: bool = True) -> Any:
559+
"""
560+
Wrapper for OMCSession.sendExpression().
561+
"""
559562
try:
560563
retval = self._session.sendExpression(expr=expr, parsed=parsed)
561564
except OMCSessionException as ex:
@@ -1136,8 +1139,12 @@ def getOptimizationOptions(
11361139

11371140
raise ModelicaSystemError("Unhandled input for getOptimizationOptions()")
11381141

1139-
def _parse_om_version(self, version: str) -> tuple[int, int, int]:
1140-
match = re.search(r"v?(\d+)\.(\d+)\.(\d+)", version)
1142+
@staticmethod
1143+
def _parse_om_version(version: str) -> tuple[int, int, int]:
1144+
"""
1145+
Evaluate an OMC version string and return a tuple of (epoch, major, minor).
1146+
"""
1147+
match = re.search(pattern=r"v?(\d+)\.(\d+)\.(\d+)", string=version)
11411148
if not match:
11421149
raise ValueError(f"Version not found in: {version}")
11431150
major, minor, patch = map(int, match.groups())
@@ -1966,7 +1973,7 @@ def linearize(
19661973

19671974
linear_data[target] = value_ast
19681975
except (AttributeError, IndexError, ValueError, SyntaxError, TypeError) as ex:
1969-
raise ModelicaSystemError(f"Error parsing linearization file {linear_file}!") from ex
1976+
raise ModelicaSystemError(f"Error parsing linearization file {linear_file}: {ex}") from ex
19701977

19711978
# remove the file
19721979
linear_file.unlink()

0 commit comments

Comments
 (0)