Skip to content

Commit b5a42a7

Browse files
committed
[ModelicaSystem] consider relativ path if ModelicaSystem is run locally
1 parent 70e2241 commit b5a42a7

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

OMPython/ModelicaSystem.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import numbers
3939
import numpy as np
4040
import os
41+
import pathlib
4142
import platform
4243
import re
4344
import subprocess
@@ -472,18 +473,30 @@ def model(
472473
# set variables
473474
self._model_name = name # Model class name
474475
self._libraries = libraries # may be needed if model is derived from other model
475-
if file is not None:
476-
file_name = self._getconn.omcpath(file).resolve()
477-
else:
478-
file_name = None
479-
self._file_name = file_name # Model file/package name
480476
self._variable_filter = variable_filter
481477

482-
if self._file_name is not None and not self._file_name.is_file(): # if file does not exist
483-
raise IOError(f"{self._file_name} does not exist!")
484-
485478
if self._libraries:
486479
self._loadLibrary(libraries=self._libraries)
480+
481+
self._file_name = None
482+
if file is not None:
483+
file_path = pathlib.Path(file)
484+
# special handling for OMCProcessLocal - consider a relative path
485+
if isinstance(self._getconn.omc_process, OMCProcessLocal) and not file_path.is_absolute():
486+
file_path = pathlib.Path.cwd() / file_path
487+
if not file_path.is_file():
488+
raise IOError(f"Model file {file_path} does not exist!")
489+
490+
self._file_name = self.getWorkDirectory() / file_path.name
491+
if (isinstance(self._getconn.omc_process, OMCProcessLocal)
492+
and file_path.as_posix() == self._file_name.as_posix()):
493+
pass
494+
elif self._file_name.is_file():
495+
raise IOError(f"Simulation model file {self._file_name} exist - not overwriting!")
496+
else:
497+
content = file_path.read_text(encoding='utf-8')
498+
self._file_name.write_text(content)
499+
487500
if self._file_name is not None:
488501
self._loadFile(fileName=self._file_name)
489502

0 commit comments

Comments
 (0)