Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mo2fmu: Check omc can be run #108

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions otfmi/mo2fmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ def mo2fmu(
except Exception:
raise TypeError("platforms must be a sequence of str")

# check omc can be run
try:
subprocess.run(["omc", "--version"], check=True)
except subprocess.CalledProcessError:
raise RuntimeError("could not run the omc OpenModelica compiler command line executable")

workdir = tempfile.mkdtemp()
path_mos = os.path.join(workdir, "mo2fmu.mos")
# assume the model name is the file name
Expand Down Expand Up @@ -88,6 +94,8 @@ def mo2fmu(
check=True,
)
temp_fmu = os.path.join(workdir, model_name) + ".fmu"
if not os.path.exists(temp_fmu):
raise RuntimeError(f"omc failed to generate the FMU file {temp_fmu}")
if path_fmu == "":
path_fmu = os.path.join(os.getcwd(), model_name) + ".fmu"
shutil.move(temp_fmu, path_fmu)
Expand Down