Skip to content

Commit 6d4ecbb

Browse files
authored
Revert #244, #246, #247, #248 (#251)
Revert update of OMPython - Keep devcontainer - Keep update to Markdown files This reverts commit 342ed04.
1 parent 342ed04 commit 6d4ecbb

File tree

6 files changed

+41
-44
lines changed

6 files changed

+41
-44
lines changed

conversionscript.py

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

4-
from OMPython import OMCSessionZMQ
5-
import pyparsing
4+
from OMPython import OMCSessionZMQ, pyparsing
65
import argparse
76
import glob
87
import json
@@ -13,6 +12,7 @@
1312
from multiprocessing import Pool
1413
import time
1514

15+
1616
parser = argparse.ArgumentParser(description='OpenModelica library testing tool')
1717
parser.add_argument('libdir', nargs=1)
1818
parser.add_argument('--diff', action="store_true")
@@ -32,6 +32,17 @@
3232
os.mkdir("converted-libraries/.openmodelica")
3333
os.mkdir("converted-libraries/.openmodelica/libraries")
3434

35+
def omcAssert(omc, cmd, extra=""):
36+
res = omc.sendExpression(cmd)
37+
if not res:
38+
raise Exception(cmd + "\n" + extra + "\n" + (omc.sendExpression("getErrorString()") or ""))
39+
40+
def omcSendExpression(omc, cmd, extra=""):
41+
try:
42+
return omc.sendExpression(cmd)
43+
except pyparsing.ParseException as e:
44+
raise Exception(str(e) + "\n" + cmd + "\n" + extra + "\n" + (omc.sendExpression("getErrorString()") or ""))
45+
3546
mslPath = "%s/Modelica 4.0.0+maint.om/" % libdir
3647
with open("%s/openmodelica.metadata.json" % mslPath) as f:
3748
mslData = json.load(f)
@@ -72,7 +83,7 @@ def convertPackage(p):
7283
print("Start working on %s" % libnameOnFile)
7384
omc = OMCSessionZMQ()
7485
libnameOnFileFullPath = "converted-libraries/.openmodelica/libraries/%s/package.mo" % libnameOnFile
75-
omc.sendExpression('loadFile("%s", uses=false)' % libnameOnFileFullPath)
86+
omcAssert(omc, 'loadFile("%s", uses=false)' % libnameOnFileFullPath)
7687
errString = omc.sendExpression("getErrorString()")
7788
if errString:
7889
print(errString)
@@ -81,12 +92,12 @@ def convertPackage(p):
8192
raise Exception("Expected to have loaded %s but got %s" % (libnameOnFileFullPath, loadedFilePath))
8293
gcProfStatsBeforeConversion = omc.sendExpression("GC_get_prof_stats()")
8394
timeBeforeConvert = time.time()
84-
omc.sendExpression('runConversionScript(%s, "%s")' % (libname, conversionScript))
95+
omcAssert(omc, 'runConversionScript(%s, "%s")' % (libname, conversionScript))
8596
print("runConversionScript(%s, %s) OK" % (libnameOnFile, conversionScript))
8697
uses = data["uses"]
8798
for (n,v) in data["uses"].items():
8899
if n in ["Modelica", "ModelicaServices", "Complex"]:
89-
omc.sendExpression('addClassAnnotation(%s, annotate=$annotation(uses(%s(version="4.0.0"))))' % (libname, n))
100+
omcAssert(omc, 'addClassAnnotation(%s, annotate=$annotation(uses(%s(version="4.0.0"))))' % (libname, n))
90101
data["uses"][n] = "4.0.0"
91102
names = omc.sendExpression('getClassNames(%s, sort=true, recursive=true)' % libname)
92103
names = list(names)
@@ -138,7 +149,7 @@ def convertPackage(p):
138149
print(errStr)
139150
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))
140151
else:
141-
omc.sendExpression('writeFile("%s", res)' % (newFile))
152+
omcAssert(omc, 'writeFile("%s", res)' % (newFile))
142153
isDiff = before != res
143154
if before != res:
144155
nDiff += 1

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==4.0
7+
ompython==3.6
88
psutil
99
simplejson

shared.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ 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-
8077
if not os.path.exists(referenceFile) and not os.path.isdir(referenceFile):
8178
if conf.get("allReferenceFilesExist"):
8279
raise Exception("Missing reference file %s for config %s" % (referenceFile,conf))
@@ -108,3 +105,5 @@ def isFMPy(fmisimulator):
108105
return 'fmpy' in fmisimulator
109106
else:
110107
return False
108+
109+

single-model.py

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

4-
import argparse
4+
import sys, argparse
5+
import simplejson as json
56
import shared
67

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

2122
libs = {}
2223

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

2527
conn = sqlite3.connect('sqlite3.db')
2628
cursor = conn.cursor()

test.py

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
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
11+
import html, shutil, os, re, glob, time, argparse, sqlite3, datetime, math, platform
1212
from joblib import Parallel, delayed
1313
import simplejson as json
1414
import psutil, subprocess, threading, hashlib
15+
from subprocess import call
1516
from monotonic import monotonic
1617
from omcommon import friendlyStr, multiple_replace
1718
from natsort import natsorted
@@ -259,19 +260,14 @@ def target():
259260
print("Error: Expected at least one configuration file to start the library test")
260261
sys.exit(1)
261262

262-
from OMPython import OMCSessionZMQ, OMCProcessDocker, OMCSessionException
263+
from OMPython import OMCSession, OMCSessionZMQ
263264

264265
# Try to make the processes a bit nicer...
265266
os.environ["GC_MARKERS"]="1"
266267

267268
print("Start OMC version")
268269

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 != "":
270+
if ompython_omhome != "":
275271
# Use a different OMC for running OMPython than for running the tests
276272
omhome = os.environ["OPENMODELICAHOME"]
277273
omc_version = check_output_log(omc_cmd + ["--version"], stderr=subprocess.STDOUT).decode("ascii").strip()
@@ -280,11 +276,10 @@ def target():
280276
ompython_omc_version=omc.sendExpression('getVersion()')
281277
os.environ["OPENMODELICAHOME"] = omhome
282278
else:
283-
omc = OMCSessionZMQ()
279+
omc = OMCSessionZMQ(docker=docker, dockerExtraArgs=dockerExtraArgs)
284280
omhome=omc.sendExpression('getInstallationDirectoryPath()')
285281
omc_version=omc.sendExpression('getVersion()')
286282
ompython_omc_version=omc_version
287-
288283
ompython_omc_version=ompython_omc_version.replace("OMCompiler","").strip()
289284

290285
def timeSeconds(f):
@@ -663,12 +658,11 @@ def hashReferenceFiles(s):
663658
raise Exception("Library %s has both libraryVersionLatestInPackageManager:true and libraryVersionExactMatch:true! Make up your mind." % libName)
664659
exactMatch=', requireExactVersion=true'
665660

666-
try:
667-
omc.sendExpression('loadModel(%s,%s%s)' % (lib,versions,exactMatch))
668-
except OMCSessionException as e:
669-
print("Failed to load library %s %s" % (library,versions))
670-
print(e)
671-
661+
if not omc.sendExpression('loadModel(%s,%s%s)' % (lib,versions,exactMatch)):
662+
try:
663+
print("Failed to load library %s %s: %s" % (library,versions,omc.sendExpression('OpenModelica.Scripting.getErrorString()')))
664+
except:
665+
print("Failed to load library %s %s. OpenModelica.Scripting.getErrorString() failed..." % (library,conf["libraryVersion"]))
672666
# adrpo: do not sort the top level names as sometimes that loads a bad MSL version
673667
# conf["loadFiles"] = sorted(omc.sendExpression("{getSourceFile(cl) for cl in getClassNames()}"))
674668
conf["loadFiles"] = omc.sendExpression("{getSourceFile(cl) for cl in getClassNames()}")
@@ -727,13 +721,7 @@ def hashReferenceFiles(s):
727721
if conf.get("fmi") and fmisimulatorversion:
728722
conf["libraryVersionRevision"] = conf["libraryVersionRevision"] + " " + fmisimulatorversion.decode("ascii")
729723
conf["libraryLastChange"] = conf["libraryLastChange"] + " " + fmisimulatorversion.decode("ascii")
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-
724+
res=omc.sendExpression('{c for c guard isExperiment(c) and not regexBool(typeNameString(x), "^Modelica_Synchronous\\.WorkInProgress") in getClassNames(%s, recursive=true)}' % library)
737725
if conf.get("ignoreModelPrefix"):
738726
if isinstance(conf["ignoreModelPrefix"], list):
739727
prefixes = conf["ignoreModelPrefix"]

testmodel.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
# -*- coding: utf-8 -*-
33

44
import argparse, os, sys, signal, threading, psutil, subprocess, shutil
5+
from asyncio.subprocess import STDOUT
56
import simplejson as json
67
from monotonic import monotonic
7-
from OMPython import OMCSessionZMQ, OMCProcessDocker
8+
from OMPython import FindBestOMCSession, OMCSession, OMCSessionZMQ
89
import shared, glob
910

1011
parser = argparse.ArgumentParser(description='OpenModelica library testing tool helper (single model)')
@@ -57,7 +58,7 @@ def writeResult():
5758

5859
startJob=monotonic()
5960

60-
def quit_omc(omc: OMCSessionZMQ | None):
61+
def quit_omc(omc):
6162
if omc is None:
6263
return omc
6364
try:
@@ -71,7 +72,7 @@ def quit_omc(omc: OMCSessionZMQ | None):
7172
omc = None
7273
return omc
7374

74-
def writeResultAndExit(exitStatus: int, useOsExit: bool = False, omc: OMCSessionZMQ | None = None, omc_new: OMCSessionZMQ | None = None):
75+
def writeResultAndExit(exitStatus, useOsExit=False, omc=None, omc_new=None):
7576
writeResult()
7677
print("Calling exit ...")
7778
with open(errFile, 'a+') as fp:
@@ -89,7 +90,7 @@ def writeResultAndExit(exitStatus: int, useOsExit: bool = False, omc: OMCSession
8990
else:
9091
sys.exit(exitStatus)
9192

92-
def sendExpressionTimeout(omc: OMCSessionZMQ, cmd: str, timeout: int):
93+
def sendExpressionTimeout(omc, cmd, timeout):
9394
with open(errFile, 'a+') as fp:
9495
fp.write("%s [Timeout %s]\n" % (cmd, timeout))
9596
def target(res):
@@ -250,11 +251,7 @@ def target(res):
250251
os.environ["OPENMODELICAHOME"] = omhome
251252

252253
def createOmcSession():
253-
if docker:
254-
return OMCProcessDocker(docker=docker, dockerExtraArgs=dockerExtraArgs, timeout=5)
255-
else:
256-
return OMCSessionZMQ(timeout=5)
257-
254+
return OMCSession(docker=docker, dockerExtraArgs=dockerExtraArgs, timeout=5) if corbaStyle else OMCSessionZMQ(docker=docker, dockerExtraArgs=dockerExtraArgs, timeout=5)
258255
def createOmcSessionNew():
259256
if ompython_omhome != "":
260257
os.environ["OPENMODELICAHOME"] = ompython_omhome

0 commit comments

Comments
 (0)