1111import os
1212import pathlib
1313import queue
14+ import re
1415import textwrap
1516import threading
1617from typing import Any , cast , Optional
1718import warnings
1819import xml .etree .ElementTree as ET
1920
2021import numpy as np
21- from packaging .version import Version
2222
2323from OMPython .OMCSession import (
2424 OMCSessionException ,
@@ -351,9 +351,7 @@ def __init__(
351351
352352 # get OpenModelica version
353353 version_str = self .sendExpression (expr = "getVersion()" )
354- # remove 'OpenModelica ' at the start of the string and possible development ids (i.e. '~dev-26-g10bb273')
355- version_str = version_str [13 :version_str .find ('~' )]
356- self ._version = Version (version_str )
354+ self ._version = self ._parse_om_version (version = version_str )
357355 # set commandLineOptions using default values or the user defined list
358356 if command_line_options is None :
359357 # set default command line options to improve the performance of linearization and to avoid recompilation if
@@ -1023,6 +1021,14 @@ def getOptimizationOptions(
10231021
10241022 raise ModelicaSystemError ("Unhandled input for getOptimizationOptions()" )
10251023
1024+ def _parse_om_version (self , version : str ) -> tuple [int , int , int ]:
1025+ match = re .search (r"v?(\d+)\.(\d+)\.(\d+)" , version )
1026+ if not match :
1027+ raise ValueError (f"Version not found in: { version } " )
1028+ major , minor , patch = map (int , match .groups ())
1029+
1030+ return major , minor , patch
1031+
10261032 def _process_override_data (
10271033 self ,
10281034 om_cmd : ModelicaSystemCmd ,
@@ -1041,7 +1047,7 @@ def _process_override_data(
10411047 # pass them to simulation executable directly as individual arguments
10421048 # see https://github.com/OpenModelica/OpenModelica/pull/14813
10431049 if override_sim :
1044- if self ._version >= Version ( "1.26.0" ):
1050+ if self ._version >= ( 1 , 26 , 0 ):
10451051 for key , opt_value in override_sim .items ():
10461052 om_cmd .arg_set (key = key , val = str (opt_value ))
10471053 else :
0 commit comments