Skip to content

Commit fc247ee

Browse files
committed
[ModelicaSystem] update convertMo2Fmu() and convertFmu2Mo() to use pathlib.Path()
1 parent 0849e13 commit fc247ee

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
@@ -1587,7 +1587,7 @@ def convertMo2Fmu(
15871587
fmuType: str = "me_cs",
15881588
fileNamePrefix: Optional[str] = None,
15891589
includeResources: bool = True,
1590-
) -> str:
1590+
) -> pathlib.Path:
15911591
"""Translate the model into a Functional Mockup Unit.
15921592
15931593
Args:
@@ -1613,15 +1613,19 @@ def convertMo2Fmu(
16131613
properties = (f'version="{version}", fmuType="{fmuType}", '
16141614
f'fileNamePrefix="{fileNamePrefix}", includeResources={includeResourcesStr}')
16151615
fmu = self._requestApi(apiName='buildModelFMU', entity=self._model_name, properties=properties)
1616+
fmu_path = pathlib.Path(fmu)
16161617

16171618
# report proper error message
1618-
if not os.path.exists(fmu):
1619-
raise ModelicaSystemError(f"Missing FMU file: {fmu}")
1619+
if not fmu_path.is_file():
1620+
raise ModelicaSystemError(f"Missing FMU file: {fmu.as_posix()}")
16201621

1621-
return fmu
1622+
return fmu_path
16221623

16231624
# to convert FMU to Modelica model
1624-
def convertFmu2Mo(self, fmuName): # 20
1625+
def convertFmu2Mo(
1626+
self,
1627+
fmuName: os.PathLike,
1628+
) -> pathlib.Path:
16251629
"""
16261630
In order to load FMU, at first it needs to be translated into Modelica model. This method is used to generate
16271631
Modelica model from the given FMU. It generates "fmuName_me_FMU.mo".
@@ -1630,13 +1634,16 @@ def convertFmu2Mo(self, fmuName): # 20
16301634
>>> convertFmu2Mo("c:/BouncingBall.Fmu")
16311635
"""
16321636

1633-
fileName = self._requestApi(apiName='importFMU', entity=fmuName)
1637+
fmu_path = pathlib.Path(fmuName)
1638+
1639+
filename = self._requestApi(apiName='importFMU', entity=fmu_path.as_posix())
1640+
filepath = pathlib.Path(filename)
16341641

16351642
# report proper error message
1636-
if not os.path.exists(fileName):
1637-
raise ModelicaSystemError(f"Missing file {fileName}")
1643+
if not filepath.is_file():
1644+
raise ModelicaSystemError(f"Missing file {filepath.as_posix()}")
16381645

1639-
return fileName
1646+
return filepath
16401647

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

0 commit comments

Comments
 (0)