Skip to content

Commit cf16d01

Browse files
committed
[ModelicaSystem] update convertMo2Fmu() and convertFmu2Mo() to use pathlib.Path()
1 parent 5bfd5b7 commit cf16d01

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,7 @@ def convertMo2Fmu(
15471547
fmuType: str = "me_cs",
15481548
fileNamePrefix: Optional[str] = None,
15491549
includeResources: bool = True,
1550-
) -> str:
1550+
) -> pathlib.Path:
15511551
"""Translate the model into a Functional Mockup Unit.
15521552
15531553
Args:
@@ -1572,29 +1572,36 @@ def convertMo2Fmu(
15721572
properties = (f'version="{version}", fmuType="{fmuType}", '
15731573
f'fileNamePrefix="{fileNamePrefix}", includeResources={includeResourcesStr}')
15741574
fmu = self._requestApi(apiName='buildModelFMU', entity=self._model_name, properties=properties)
1575+
fmu_path = pathlib.Path(fmu)
15751576

15761577
# report proper error message
1577-
if not os.path.exists(fmu):
1578-
raise ModelicaSystemError(f"Missing FMU file: {fmu}")
1578+
if not fmu_path.is_file():
1579+
raise ModelicaSystemError(f"Missing FMU file: {fmu.as_posix()}")
15791580

1580-
return fmu
1581+
return fmu_path
15811582

15821583
# to convert FMU to Modelica model
1583-
def convertFmu2Mo(self, fmuName): # 20
1584+
def convertFmu2Mo(
1585+
self,
1586+
fmuName: os.PathLike,
1587+
) -> pathlib.Path:
15841588
"""
15851589
In order to load FMU, at first it needs to be translated into Modelica model. This method is used to generate Modelica model from the given FMU. It generates "fmuName_me_FMU.mo".
15861590
Currently, it only supports Model Exchange conversion.
15871591
usage
15881592
>>> convertFmu2Mo("c:/BouncingBall.Fmu")
15891593
"""
15901594

1591-
fileName = self._requestApi(apiName='importFMU', entity=fmuName)
1595+
fmu_path = pathlib.Path(fmuName)
1596+
1597+
filename = self._requestApi(apiName='importFMU', entity=fmu_path.as_posix())
1598+
filepath = pathlib.Path(filename)
15921599

15931600
# report proper error message
1594-
if not os.path.exists(fileName):
1595-
raise ModelicaSystemError(f"Missing file {fileName}")
1601+
if not filepath.is_file():
1602+
raise ModelicaSystemError(f"Missing file {filepath.as_posix()}")
15961603

1597-
return fileName
1604+
return filepath
15981605

15991606
def optimize(self) -> dict[str, Any]:
16001607
"""Perform model-based optimization.

0 commit comments

Comments
 (0)