Skip to content

Commit 342ed04

Browse files
authored
More fixes (#248)
* Clean up conversion script * Error handling for getClassNames - Print error messages if omc.sendExpression failes - Fix links in README.md - Add missing NeuralNetwork to install script
1 parent d4f7f40 commit 342ed04

File tree

4 files changed

+20
-26
lines changed

4 files changed

+20
-26
lines changed

.CI/installLibraries.mos

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ for l in {
7777
{"Modelica_Synchronous", "master"},
7878
{"ModelicaByExample", "master"},
7979
{"ModelicaTestOverdetermined", "master"},
80+
{"NeuralNetwork", "main"},
8081
{"ObjectStab", "master"},
8182
{"OpenHydraulics", "main"},
8283
{"OpenIMDML", "main"},

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ defining `MSLREFERENCE` and `REFERENCEFILES`.
187187

188188
Some result file locations:
189189

190-
- Modelica Association: [https://github.com/modelica/MAP-LIB_ReferenceResults](modelica/MAP-LIB_ReferenceResults)
191-
- PNLib: [https://github.com/AMIT-HSBI/PNlib](AMIT-HSBI/PNlib)
192-
- DLR-SR: [https://github.com/DLR-SR/ThermoFluidStream-Regression](DLR-SR/ThermoFluidStream-Regression)
193-
and [https://github.com/DLR-SR/PlanarMechanics_ReferenceResults](DLR-SR/PlanarMechanics_ReferenceResults)
190+
- Modelica Association: [modelica/MAP-LIB_ReferenceResults](https://github.com/modelica/MAP-LIB_ReferenceResults)
191+
- PNLib: [AMIT-HSBI/PNlib](https://github.com/AMIT-HSBI/PNlib)
192+
- DLR-SR: [DLR-SR/ThermoFluidStream-Regression](https://github.com/DLR-SR/ThermoFluidStream-Regression)
193+
and [DLR-SR/PlanarMechanics_ReferenceResults](https://github.com/DLR-SR/PlanarMechanics_ReferenceResults)
194194

195195
To download the MSL reference files create a file
196196
installReferenceResults.sh with

conversionscript.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from multiprocessing import Pool
1414
import time
1515

16-
1716
parser = argparse.ArgumentParser(description='OpenModelica library testing tool')
1817
parser.add_argument('libdir', nargs=1)
1918
parser.add_argument('--diff', action="store_true")
@@ -33,17 +32,6 @@
3332
os.mkdir("converted-libraries/.openmodelica")
3433
os.mkdir("converted-libraries/.openmodelica/libraries")
3534

36-
def omcAssert(omc: OMCSessionZMQ, cmd: str, extra: str = ""):
37-
res = omc.sendExpression(cmd)
38-
if not res:
39-
raise Exception(cmd + "\n" + extra + "\n" + (omc.sendExpression("getErrorString()") or ""))
40-
41-
def omcSendExpression(omc: OMCSessionZMQ, cmd: str, extra: str = ""):
42-
try:
43-
return omc.sendExpression(cmd)
44-
except pyparsing.ParseException as e:
45-
raise Exception(str(e) + "\n" + cmd + "\n" + extra + "\n" + (omc.sendExpression("getErrorString()") or ""))
46-
4735
mslPath = "%s/Modelica 4.0.0+maint.om/" % libdir
4836
with open("%s/openmodelica.metadata.json" % mslPath) as f:
4937
mslData = json.load(f)
@@ -84,7 +72,7 @@ def convertPackage(p):
8472
print("Start working on %s" % libnameOnFile)
8573
omc = OMCSessionZMQ()
8674
libnameOnFileFullPath = "converted-libraries/.openmodelica/libraries/%s/package.mo" % libnameOnFile
87-
omcAssert(omc, 'loadFile("%s", uses=false)' % libnameOnFileFullPath)
75+
omc.sendExpression('loadFile("%s", uses=false)' % libnameOnFileFullPath)
8876
errString = omc.sendExpression("getErrorString()")
8977
if errString:
9078
print(errString)
@@ -93,12 +81,12 @@ def convertPackage(p):
9381
raise Exception("Expected to have loaded %s but got %s" % (libnameOnFileFullPath, loadedFilePath))
9482
gcProfStatsBeforeConversion = omc.sendExpression("GC_get_prof_stats()")
9583
timeBeforeConvert = time.time()
96-
omcAssert(omc, 'runConversionScript(%s, "%s")' % (libname, conversionScript))
84+
omc.sendExpression('runConversionScript(%s, "%s")' % (libname, conversionScript))
9785
print("runConversionScript(%s, %s) OK" % (libnameOnFile, conversionScript))
9886
uses = data["uses"]
9987
for (n,v) in data["uses"].items():
10088
if n in ["Modelica", "ModelicaServices", "Complex"]:
101-
omcAssert(omc, 'addClassAnnotation(%s, annotate=$annotation(uses(%s(version="4.0.0"))))' % (libname, n))
89+
omc.sendExpression('addClassAnnotation(%s, annotate=$annotation(uses(%s(version="4.0.0"))))' % (libname, n))
10290
data["uses"][n] = "4.0.0"
10391
names = omc.sendExpression('getClassNames(%s, sort=true, recursive=true)' % libname)
10492
names = list(names)
@@ -150,7 +138,7 @@ def convertPackage(p):
150138
print(errStr)
151139
raise Exception('--allowErrorsInDiff is not active:\necho(false);before:=readFile("%s");\nafter:=readFile("%s");echo(true);\ndiffModelicaFileListings(before, after, OpenModelica.Scripting.DiffFormat.plain, failOnSemanticsChange=true);\ngetErrorString();' % (oldFile, newFile))
152140
else:
153-
omcAssert(omc, 'writeFile("%s", res)' % (newFile))
141+
omc.sendExpression('writeFile("%s", res)' % (newFile))
154142
isDiff = before != res
155143
if before != res:
156144
nDiff += 1

test.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -665,11 +665,10 @@ def hashReferenceFiles(s):
665665

666666
try:
667667
omc.sendExpression('loadModel(%s,%s%s)' % (lib,versions,exactMatch))
668-
except OMCSessionException:
669-
try:
670-
print("Failed to load library %s %s: %s" % (library,versions,omc.sendExpression('OpenModelica.Scripting.getErrorString()')))
671-
except:
672-
print("Failed to load library %s %s. OpenModelica.Scripting.getErrorString() failed..." % (library,conf["libraryVersion"]))
668+
except OMCSessionException as e:
669+
print("Failed to load library %s %s" % (library,versions))
670+
print(e)
671+
673672
# adrpo: do not sort the top level names as sometimes that loads a bad MSL version
674673
# conf["loadFiles"] = sorted(omc.sendExpression("{getSourceFile(cl) for cl in getClassNames()}"))
675674
conf["loadFiles"] = omc.sendExpression("{getSourceFile(cl) for cl in getClassNames()}")
@@ -728,7 +727,13 @@ def hashReferenceFiles(s):
728727
if conf.get("fmi") and fmisimulatorversion:
729728
conf["libraryVersionRevision"] = conf["libraryVersionRevision"] + " " + fmisimulatorversion.decode("ascii")
730729
conf["libraryLastChange"] = conf["libraryLastChange"] + " " + fmisimulatorversion.decode("ascii")
731-
res=omc.sendExpression('{c for c guard isExperiment(c) and not regexBool(typeNameString(x), "^Modelica_Synchronous\\.WorkInProgress") in getClassNames(%s, recursive=true)}' % library)
730+
res = []
731+
try:
732+
res = omc.sendExpression('{c for c guard isExperiment(c) and not regexBool(typeNameString(x), "^Modelica_Synchronous\\\\.WorkInProgress") in getClassNames(%s, recursive=true)}' % library)
733+
except OMCSessionException as e:
734+
print("Failed to get class names of library %s", library)
735+
print(e)
736+
732737
if conf.get("ignoreModelPrefix"):
733738
if isinstance(conf["ignoreModelPrefix"], list):
734739
prefixes = conf["ignoreModelPrefix"]

0 commit comments

Comments
 (0)