Skip to content

Commit 221789b

Browse files
committed
[OMCSession] define and use OMPathBase
1 parent 4eaa243 commit 221789b

3 files changed

Lines changed: 21 additions & 16 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
OMCSession,
3030
OMCSessionLocal,
3131

32-
OMPathABC,
32+
OMPathBase,
3333
)
3434

3535
# define logger using the current module name as ID
@@ -388,13 +388,13 @@ def __init__(
388388
self._version = self._parse_om_version(version=version_str)
389389

390390
self._simulated = False # True if the model has already been simulated
391-
self._result_file: Optional[OMPathABC] = None # for storing result file
391+
self._result_file: Optional[OMPathBase] = None # for storing result file
392392

393-
self._work_dir: OMPathABC = self.setWorkDirectory(work_directory)
393+
self._work_dir: OMPathBase = self.setWorkDirectory(work_directory)
394394

395395
self._model_name: Optional[str] = None
396396
self._libraries: Optional[list[str | tuple[str, str]]] = None
397-
self._file_name: Optional[OMPathABC] = None
397+
self._file_name: Optional[OMPathBase] = None
398398
self._variable_filter: Optional[str] = None
399399

400400
def get_session(self) -> OMCSession:
@@ -412,7 +412,7 @@ def get_model_name(self) -> str:
412412

413413
return self._model_name
414414

415-
def setWorkDirectory(self, work_directory: Optional[str | os.PathLike] = None) -> OMPathABC:
415+
def setWorkDirectory(self, work_directory: Optional[str | os.PathLike] = None) -> OMPathBase:
416416
"""
417417
Define the work directory for the ModelicaSystem / OpenModelica session. The model is build within this
418418
directory. If no directory is defined a unique temporary directory is created.
@@ -434,7 +434,7 @@ def setWorkDirectory(self, work_directory: Optional[str | os.PathLike] = None) -
434434
# ... and also return the defined path
435435
return workdir
436436

437-
def getWorkDirectory(self) -> OMPathABC:
437+
def getWorkDirectory(self) -> OMPathBase:
438438
"""
439439
Return the defined working directory for this ModelicaSystem / OpenModelica session.
440440
"""
@@ -459,7 +459,7 @@ def check_model_executable(self):
459459
if returncode != 0:
460460
raise ModelicaSystemError("Model executable not working!")
461461

462-
def _xmlparse(self, xml_file: OMPathABC):
462+
def _xmlparse(self, xml_file: OMPathBase):
463463
if not xml_file.is_file():
464464
raise ModelicaSystemError(f"XML file not generated: {xml_file}")
465465

@@ -833,7 +833,7 @@ def _parse_om_version(version: str) -> tuple[int, int, int]:
833833
def _process_override_data(
834834
self,
835835
om_cmd: ModelExecutionCmd,
836-
override_file: OMPathABC,
836+
override_file: OMPathBase,
837837
override_var: dict[str, str],
838838
override_sim: dict[str, str],
839839
) -> None:
@@ -865,7 +865,7 @@ def _process_override_data(
865865

866866
def simulate_cmd(
867867
self,
868-
result_file: OMPathABC,
868+
result_file: OMPathBase,
869869
simflags: Optional[str] = None,
870870
simargs: Optional[dict[str, Optional[str | dict[str, Any] | numbers.Number]]] = None,
871871
) -> ModelExecutionCmd:
@@ -963,14 +963,14 @@ def simulate(
963963
if resultfile is None:
964964
# default result file generated by OM
965965
self._result_file = self.getWorkDirectory() / f"{self._model_name}_res.mat"
966-
elif isinstance(resultfile, OMPathABC):
966+
elif isinstance(resultfile, OMPathBase):
967967
self._result_file = resultfile
968968
else:
969969
self._result_file = self._session.omcpath(resultfile)
970970
if not self._result_file.is_absolute():
971971
self._result_file = self.getWorkDirectory() / resultfile
972972

973-
if not isinstance(self._result_file, OMPathABC):
973+
if not isinstance(self._result_file, OMPathBase):
974974
raise ModelicaSystemError(f"Invalid result file path: {self._result_file} - must be an OMCPath object!")
975975

976976
om_cmd = self.simulate_cmd(
@@ -1295,7 +1295,7 @@ def setInputs(
12951295

12961296
return True
12971297

1298-
def _createCSVData(self, csvfile: Optional[OMPathABC] = None) -> OMPathABC:
1298+
def _createCSVData(self, csvfile: Optional[OMPathBase] = None) -> OMPathBase:
12991299
"""
13001300
Create a csv file with inputs for the simulation/optimization of the model. If csvfile is provided as argument,
13011301
this file is used; else a generic file name is created.
@@ -1623,7 +1623,7 @@ def set_command_line_options(self, command_line_option: str):
16231623
expr = f'setCommandLineOptions("{command_line_option}")'
16241624
self.sendExpression(expr=expr)
16251625

1626-
def _loadFile(self, fileName: OMPathABC):
1626+
def _loadFile(self, fileName: OMPathBase):
16271627
# load file
16281628
self.sendExpression(expr=f'loadFile("{fileName.as_posix()}")')
16291629

@@ -2004,7 +2004,7 @@ def convertMo2Fmu(
20042004
fmuType: str = "me_cs",
20052005
fileNamePrefix: Optional[str] = None,
20062006
includeResources: bool = True,
2007-
) -> OMPathABC:
2007+
) -> OMPathBase:
20082008
"""Translate the model into a Functional Mockup Unit.
20092009
20102010
Args:
@@ -2043,7 +2043,7 @@ def convertMo2Fmu(
20432043
def convertFmu2Mo(
20442044
self,
20452045
fmu: os.PathLike,
2046-
) -> OMPathABC:
2046+
) -> OMPathBase:
20472047
"""
20482048
In order to load FMU, at first it needs to be translated into Modelica model. This method is used to generate
20492049
Modelica model from the given FMU. It generates "fmuName_me_FMU.mo".
@@ -2510,7 +2510,7 @@ def get_doe_solutions(
25102510

25112511
def doe_get_solutions(
25122512
msomc: ModelicaSystemOMC,
2513-
resultpath: OMPathABC,
2513+
resultpath: OMPathBase,
25142514
doe_def: Optional[dict] = None,
25152515
var_list: Optional[list] = None,
25162516
) -> Optional[tuple[str] | dict[str, dict[str, np.ndarray]]]:

OMPython/OMCSession.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ class OMPathCompatibilityWindows(pathlib.WindowsPath, OMPathCompatibility):
287287
Compatibility class for OMCPath on Windows systems (Python < 3.12)
288288
"""
289289

290+
OMPathBase = OMPathCompatibility
290291
OMCPath = OMPathCompatibility
291292
else:
292293
class OMPathABC(pathlib.PurePosixPath, metaclass=abc.ABCMeta):
@@ -513,6 +514,7 @@ def size(self) -> int:
513514

514515
raise OMCSessionException(f"Error reading file size for path {self.as_posix()}!")
515516

517+
OMPathBase = OMPathABC
516518
OMCPath = _OMCPath
517519

518520

OMPython/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
doe_get_solutions,
2424
)
2525
from OMPython.OMCSession import (
26+
OMPathBase,
2627
OMCPath,
28+
2729
OMCSession,
2830

2931
ModelExecutionData,
@@ -53,6 +55,7 @@
5355
'ModelicaDoEOMC',
5456
'ModelicaSystemError',
5557

58+
'OMPathBase',
5659
'OMCPath',
5760

5861
'OMCSession',

0 commit comments

Comments
 (0)