Skip to content

Commit 3464502

Browse files
committed
revert part of [ModelicaSystem] use packaging.version.Version to replace parse_om_version()
* the OM version does not match to the one expected by packaging.version.Version * keep it simple ...
1 parent 28fa972 commit 3464502

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
import os
1212
import pathlib
1313
import queue
14+
import re
1415
import textwrap
1516
import threading
1617
from typing import Any, cast, Optional
1718
import warnings
1819
import xml.etree.ElementTree as ET
1920

2021
import numpy as np
21-
from packaging.version import Version
2222

2323
from 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:

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ license = { file = "LICENSE" }
1717
requires-python = ">=3.10"
1818
dependencies = [
1919
"numpy",
20-
"packaging",
2120
"psutil",
2221
"pyparsing",
2322
"pyzmq",

0 commit comments

Comments
 (0)