Skip to content

Commit 3aa8a07

Browse files
authored
Updating to OMPython 4.0 (#244)
* Removing unused FindBestOMCSession * Use OMCProcessDocker - Also remove juliacall in non-BaseModelica.jl CI * Ubuntu dev-container * Make sure to always use an absolute path - On the CI path to reference files is relative, but scripts need it to be absolute.
1 parent 601633f commit 3aa8a07

File tree

12 files changed

+136
-48
lines changed

12 files changed

+136
-48
lines changed

.devcontainer/devcontainer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
3+
{
4+
"name": "Ubuntu",
5+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6+
"image": "mcr.microsoft.com/devcontainers/base:noble",
7+
8+
// Features to add to the dev container. More info: https://containers.dev/features.
9+
"features": {
10+
"ghcr.io/devcontainers/features/python:1": {
11+
"installTools": true,
12+
"version": "latest"
13+
}
14+
},
15+
16+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
17+
// "forwardPorts": [],
18+
19+
// Use 'postCreateCommand' to run commands after the container is created.
20+
"postCreateCommand": "bash .devcontainer/install.sh && omc .devcontainer/install.mos && pip install -r requirements.txt"
21+
22+
// Configure tool-specific properties.
23+
// "customizations": {},
24+
25+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
26+
// "remoteUser": "root"
27+
}

.devcontainer/install.mos

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
updatePackageIndex(); getErrorString();
2+
installPackage(Modelica, version="4.0.0", exactMatch=true); getErrorString();

.devcontainer/install.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
sudo apt-get update
4+
sudo apt-get install ca-certificates curl gnupg -qy
5+
sudo curl -fsSL http://build.openmodelica.org/apt/openmodelica.asc | \
6+
sudo gpg --dearmor -o /usr/share/keyrings/openmodelica-keyring.gpg
7+
8+
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/openmodelica-keyring.gpg] \
9+
https://build.openmodelica.org/apt \
10+
noble \
11+
stable" | sudo tee /etc/apt/sources.list.d/openmodelica.list
12+
13+
sudo apt update
14+
sudo apt install --no-install-recommends omc -qy

.github/workflows/test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@ jobs:
5353
- name: Install Python dependencies
5454
shell: bash
5555
run: |
56+
sed -i '/^juliacall/d' requirements.txt # Remove juliacall to check if it works without
5657
pip install -r requirements.txt
5758
5859
- name: Run library test
5960
shell: bash
61+
env:
62+
MY_SANITY_CHECK_DIRECTORY: sanityCheck
6063
run: |
61-
export MY_SANITY_CHECK_DIRECTORY=sanityCheck
6264
python test.py --branch="${{ matrix.omc-version }}" --noclean --verbose ${{ matrix.msysEnvironment }} configs/sanityCheck.json
6365
6466
- name: Generate HTML results
@@ -73,7 +75,7 @@ jobs:
7375
- name: Verify that overview.html contains simulation and verification
7476
shell: bash
7577
run: |
76-
if ! grep -q "<tr><td><a href=\"${{ matrix.omc-version }}/MyLibrary_1.0.0/MyLibrary_1.0.0.html\">${{ matrix.omc-version }}</a></td><td><a>2</a></td><td><a>2</a></td><td><a>2</a></td><td><a>2</a></td><td><a>2</a></td><td><a>2</a></td><td><a>2</a></td><td><a>2</a></td><td><a>2</a></td></tr></table>" overview.html; then
78+
if ! grep -q '<tr><td><a href="${{ matrix.omc-version }}/MyLibrary_1.0.0/MyLibrary_1.0.0.html">${{ matrix.omc-version }}</a></td><td><a>2</a></td><td><a>2</a></td><td><a>2</a></td><td><a>2</a></td><td><a>2</a></td><td><a>2</a></td><td><a>2</a></td><td><a>2</a></td><td><a>2</a></td></tr></table>' overview.html; then
7779
echo "Failed to find 2 simulating and 2 verifying models in overwiew.html:"
7880
cat overview.html
7981
exit 1

.github/workflows/test_julia.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ jobs:
9494
9595
- name: Run library test
9696
shell: bash
97+
env:
98+
MY_SANITY_CHECK_DIRECTORY: sanityCheck
9799
run: |
98-
export MY_SANITY_CHECK_DIRECTORY=sanityCheck
99100
python test.py --branch="${{ matrix.omc-version }}" --basemodelica-mtk-import --no-julia-sys-image --noclean --verbose configs/sanityCheck.json
100101
101102
- name: Generate HTML results

conversionscript.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4-
from OMPython import OMCSessionZMQ, pyparsing
4+
from OMPython import OMCSessionZMQ
5+
import pyparsing
56
import argparse
67
import glob
78
import json
@@ -32,12 +33,12 @@
3233
os.mkdir("converted-libraries/.openmodelica")
3334
os.mkdir("converted-libraries/.openmodelica/libraries")
3435

35-
def omcAssert(omc, cmd, extra=""):
36+
def omcAssert(omc: OMCSessionZMQ, cmd: str, extra: str = ""):
3637
res = omc.sendExpression(cmd)
3738
if not res:
3839
raise Exception(cmd + "\n" + extra + "\n" + (omc.sendExpression("getErrorString()") or ""))
3940

40-
def omcSendExpression(omc, cmd, extra=""):
41+
def omcSendExpression(omc: OMCSessionZMQ, cmd: str, extra: str = ""):
4142
try:
4243
return omc.sendExpression(cmd)
4344
except pyparsing.ParseException as e:

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ juliacall
44
matplotlib
55
monotonic
66
natsort
7-
ompython==3.6
7+
OMPython==4.0
88
psutil
99
simplejson

shared.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ def getReferenceFileName(conf):
7474
else:
7575
modelName += "."+conf["referenceFileNameExtraName"]
7676
referenceFile = conf["referenceFiles"]+"/"+modelName.replace(".",conf["referenceFileNameDelimiter"])+(conf.get("referenceFinalDot") or ".")+conf["referenceFileExtension"]
77+
if os.path.exists(referenceFile):
78+
referenceFile = os.path.abspath(referenceFile)
79+
7780
if not os.path.exists(referenceFile) and not os.path.isdir(referenceFile):
7881
if conf.get("allReferenceFilesExist"):
7982
raise Exception("Missing reference file %s for config %s" % (referenceFile,conf))
@@ -105,5 +108,3 @@ def isFMPy(fmisimulator):
105108
return 'fmpy' in fmisimulator
106109
else:
107110
return False
108-
109-

single-model.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4-
import sys, argparse
5-
import simplejson as json
4+
import argparse
65
import shared
76

87
parser = argparse.ArgumentParser(description='OpenModelica model testing report generation tool')
@@ -21,8 +20,7 @@
2120

2221
libs = {}
2322

24-
import cgi, sqlite3, time, datetime
25-
from omcommon import friendlyStr, multiple_replace
23+
import sqlite3, datetime
2624

2725
conn = sqlite3.connect('sqlite3.db')
2826
cursor = conn.cursor()

test.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
if (sys.version_info < (3, 0)):
99
raise Exception("Python2 is no longer supported")
1010

11-
import html, shutil, os, re, glob, time, argparse, sqlite3, datetime, math, platform
11+
import html, shutil, os, re, glob, time, argparse, sqlite3, datetime, math
1212
from joblib import Parallel, delayed
1313
import simplejson as json
1414
import psutil, subprocess, threading, hashlib
15-
from subprocess import call
1615
from monotonic import monotonic
1716
from omcommon import friendlyStr, multiple_replace
1817
from natsort import natsorted
@@ -260,14 +259,19 @@ def target():
260259
print("Error: Expected at least one configuration file to start the library test")
261260
sys.exit(1)
262261

263-
from OMPython import OMCSession, OMCSessionZMQ
262+
from OMPython import OMCSessionZMQ, OMCProcessDocker
264263

265264
# Try to make the processes a bit nicer...
266265
os.environ["GC_MARKERS"]="1"
267266

268267
print("Start OMC version")
269268

270-
if ompython_omhome != "":
269+
if docker:
270+
omc = OMCProcessDocker(docker=docker, dockerExtraArgs=dockerExtraArgs)
271+
omhome=omc.sendExpression('getInstallationDirectoryPath()')
272+
omc_version=omc.sendExpression('getVersion()')
273+
ompython_omc_version=omc_version
274+
elif ompython_omhome != "":
271275
# Use a different OMC for running OMPython than for running the tests
272276
omhome = os.environ["OPENMODELICAHOME"]
273277
omc_version = check_output_log(omc_cmd + ["--version"], stderr=subprocess.STDOUT).decode("ascii").strip()
@@ -276,10 +280,11 @@ def target():
276280
ompython_omc_version=omc.sendExpression('getVersion()')
277281
os.environ["OPENMODELICAHOME"] = omhome
278282
else:
279-
omc = OMCSessionZMQ(docker=docker, dockerExtraArgs=dockerExtraArgs)
283+
omc = OMCSessionZMQ()
280284
omhome=omc.sendExpression('getInstallationDirectoryPath()')
281285
omc_version=omc.sendExpression('getVersion()')
282286
ompython_omc_version=omc_version
287+
283288
ompython_omc_version=ompython_omc_version.replace("OMCompiler","").strip()
284289

285290
def timeSeconds(f):

0 commit comments

Comments
 (0)