|
11 | 11 | import os |
12 | 12 | import pathlib |
13 | 13 | import queue |
14 | | -import re |
15 | 14 | import textwrap |
16 | 15 | import threading |
17 | 16 | from typing import Any, cast, Optional |
18 | 17 | import warnings |
19 | 18 | import xml.etree.ElementTree as ET |
20 | 19 |
|
21 | 20 | import numpy as np |
| 21 | +from packaging.version import Version |
22 | 22 |
|
23 | 23 | from OMPython.OMCSession import ( |
24 | 24 | OMCSessionException, |
@@ -350,7 +350,8 @@ def __init__( |
350 | 350 | self._session = OMCSessionLocal(omhome=omhome) |
351 | 351 |
|
352 | 352 | # get OpenModelica version |
353 | | - self._version = self._session.sendExpression("getVersion()", parsed=True) |
| 353 | + version_str = self._session.sendExpression("getVersion()", parsed=True) |
| 354 | + self._version = Version(version_str) |
354 | 355 | # set commandLineOptions using default values or the user defined list |
355 | 356 | if command_line_options is None: |
356 | 357 | # set default command line options to improve the performance of linearization and to avoid recompilation if |
@@ -1022,13 +1023,6 @@ def getOptimizationOptions( |
1022 | 1023 |
|
1023 | 1024 | raise ModelicaSystemError("Unhandled input for getOptimizationOptions()") |
1024 | 1025 |
|
1025 | | - def parse_om_version(self, version: str) -> tuple[int, int, int]: |
1026 | | - match = re.search(r"v?(\d+)\.(\d+)\.(\d+)", version) |
1027 | | - if not match: |
1028 | | - raise ValueError(f"Version not found in: {version}") |
1029 | | - major, minor, patch = map(int, match.groups()) |
1030 | | - return major, minor, patch |
1031 | | - |
1032 | 1026 | def simulate_cmd( |
1033 | 1027 | self, |
1034 | 1028 | result_file: OMCPath, |
@@ -1078,8 +1072,7 @@ def simulate_cmd( |
1078 | 1072 | # simulation options are not read from override file from version >= 1.26.0, |
1079 | 1073 | # pass them to simulation executable directly as individual arguments |
1080 | 1074 | # see https://github.com/OpenModelica/OpenModelica/pull/14813 |
1081 | | - major, minor, patch = self.parse_om_version(self._version) |
1082 | | - if (major, minor, patch) >= (1, 26, 0): |
| 1075 | + if self._version >= Version("1.26.0"): |
1083 | 1076 | for key, opt_value in self._simulate_options_override.items(): |
1084 | 1077 | om_cmd.arg_set(key=key, val=str(opt_value)) |
1085 | 1078 | override_content = ( |
@@ -1775,8 +1768,7 @@ def linearize( |
1775 | 1768 | ) |
1776 | 1769 |
|
1777 | 1770 | # See comment in simulate_cmd regarding override file and OM version |
1778 | | - major, minor, patch = self.parse_om_version(self._version) |
1779 | | - if (major, minor, patch) >= (1, 26, 0): |
| 1771 | + if self._version >= Version("1.26.0"): |
1780 | 1772 | for key, opt_value in self._linearization_options.items(): |
1781 | 1773 | om_cmd.arg_set(key=key, val=str(opt_value)) |
1782 | 1774 | override_content = ( |
|
0 commit comments