Skip to content

Commit 10671e8

Browse files
authored
fix OMSimulator pip package (#1285)
* fix the schema location for pip package * fix the setup.py * remove the 32 bit versions and fix the schema path
1 parent 2f38a49 commit 10671e8

4 files changed

Lines changed: 46 additions & 15 deletions

File tree

src/OMSimulatorLib/XercesValidator.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,21 @@ oms_status_enu_t oms::XercesValidator::validateSSP(const char *ssd, const std::s
179179
schemaSSCPath = schemaRootPath / "../../../share/OMSimulator/schema/ssp/SystemStructureCommon.xsd";
180180
}
181181

182+
//check schema path location in python pip package, the schemas are copied to "OMSimulator/schema"
183+
if (!filesystem::exists(schemaSSDPath))
184+
{
185+
schemaSSDPath = schemaRootPath / "schema/ssp/SystemStructureDescription.xsd";
186+
schemaSSVPath = schemaRootPath / "schema/ssp/SystemStructureParameterValues.xsd";
187+
schemaSSMPath = schemaRootPath / "schema/ssp/SystemStructureParameterMapping.xsd";
188+
schemaSSCPath = schemaRootPath / "schema/ssp/SystemStructureCommon.xsd";
189+
}
190+
191+
182192
XercesDOMParser domParser;
183193

184194
// load the schema
185195
if (domParser.loadGrammar(schemaSSDPath.generic_string().c_str(), Grammar::SchemaGrammarType) == NULL)
186-
return logError("could not load the ssd schema file: " + filesystem::absolute(schemaSSDPath).generic_string());
196+
return logWarning("could not load the ssd schema file: " + filesystem::absolute(schemaSSDPath).generic_string() + ", hence validation of ssd file will not be perfomed according to SSP Standard");
187197

188198
std::string sspVariant = "";
189199

@@ -272,11 +282,17 @@ oms_status_enu_t oms::XercesValidator::validateFMU(const char *modeldescription,
272282
schemaFmiModeldescriptionPath = schemaRootPath / "../../../share/OMSimulator/schema/fmi2/fmi2ModelDescription.xsd";
273283
}
274284

285+
//check schema path location in python pip package, the schemas are copied to "OMSimulator/schema"
286+
if (!filesystem::exists(schemaFmiModeldescriptionPath))
287+
{
288+
schemaFmiModeldescriptionPath = schemaRootPath / "schema/fmi2/fmi2ModelDescription.xsd";
289+
}
290+
275291
XercesDOMParser domParser;
276292

277293
// load the schema
278294
if (domParser.loadGrammar(schemaFmiModeldescriptionPath.generic_string().c_str(), Grammar::SchemaGrammarType) == NULL)
279-
return logError("could not load the ssd schema file: " + filesystem::absolute(schemaFmiModeldescriptionPath).generic_string());
295+
return logWarning("could not load the FMI schema file: " + filesystem::absolute(schemaFmiModeldescriptionPath).generic_string() + ", hence validation of \"modeldescription.xml\" with FMI 2.0 standard will not be performed");
280296

281297
ParserErrorHandler parserErrorHandler("modeldescription.xml", filePath.c_str());
282298

src/OMSimulatorPython/capi.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,24 @@
44
class capi:
55
def __init__(self):
66
dirname = os.path.dirname(__file__)
7+
## look for dll in the current directory for the python pip package
78
omslib = os.path.join(dirname, "@OMSIMULATORLIB_STRING@")
8-
# attempt to fix #8163 on Linux
9+
10+
dllSearchPath = False
11+
12+
## look for dll in the OpenModelica top level directory or OMSimulator stand alone directory
913
if not os.path.exists(omslib):
10-
omslib = os.path.join(dirname, "..", "@OMSIMULATORLIB_STRING@")
14+
if os.name == 'nt': # Windows
15+
omslib = os.path.join(dirname, "@OMSIMULATOR_PYTHON_RELATIVE_DLL_DIR@", "@OMSIMULATORLIB_STRING@")
16+
dllDir = os.add_dll_directory(os.path.dirname(omslib))
17+
dllSearchPath = True
18+
else:
19+
# attempt to fix #8163 on Linux
20+
omslib = os.path.join(dirname, "..", "@OMSIMULATORLIB_STRING@")
1121

12-
if os.name == 'nt': # Windows
13-
omslib = os.path.join(dirname, "@OMSIMULATOR_PYTHON_RELATIVE_DLL_DIR@", "@OMSIMULATORLIB_STRING@")
14-
dllDir = os.add_dll_directory(os.path.dirname(omslib))
1522
self.obj=ctypes.CDLL(omslib)
16-
if os.name == 'nt': # Windows
23+
24+
if os.name == 'nt' and dllSearchPath: # Windows
1725
dllDir.close()
1826

1927
self.obj.oms_activateVariant.argtypes = [ctypes.c_char_p, ctypes.c_char_p]

src/pip/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
project(pip)
22

33
set(CMAKE_INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR}/pip)
4-
set(CMAKE_INSTALL_DATADIR ${CMAKE_INSTALL_DATADIR}/pip)
4+
# set(CMAKE_INSTALL_DATADIR ${CMAKE_INSTALL_DATADIR}/pip)
55

66
IF (OMS_VERSION_STRING MATCHES "^(.*)\\.post(.*)-g(.*)$")
77
set(OMS_BUILD_TYPE "nightly")
@@ -14,4 +14,4 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/setup.py" "${CMAKE_CURRENT_BINARY_DI
1414
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/setup.py"
1515
TYPE BIN)
1616
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/README.md" "${CMAKE_SOURCE_DIR}/OSMC-License.txt"
17-
TYPE DATA)
17+
TYPE BIN)

src/pip/setup.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import tempfile
3838
from distutils.command.build_py import build_py
3939
from distutils.dir_util import copy_tree
40+
from distutils.file_util import copy_file
4041

4142
from setuptools import setup
4243

@@ -70,16 +71,16 @@ def fetch_oms(self):
7071
# download the zip directory from url
7172
if (sysconfig.get_platform() == 'linux-x86_64'):
7273
response = requests.get('https://build.openmodelica.org/omsimulator/nightly/linux-amd64/OMSimulator-linux-amd64-@OMS_VERSION_STRING@.tar.gz')
73-
elif (sysconfig.get_platform() == 'linux-i386'):
74-
response = requests.get('https://build.openmodelica.org/omsimulator/nightly/linux-i386/OMSimulator-linux-i386-@OMS_VERSION_STRING@.tar.gz')
75-
elif (sysconfig.get_platform() == 'linux-arm32'):
76-
response = requests.get('https://build.openmodelica.org/omsimulator/nightly/linux-arm32/OMSimulator-linux-arm32-@OMS_VERSION_STRING@.tar.gz')
77-
elif (sysconfig.get_platform() == 'mingw' and platform.architecture()[0] == '64bit'):
74+
dllpath = "lib/x86_64-linux-gnu/libOMSimulator.so"
75+
elif (sysconfig.get_platform() == "mingw_x86_64_ucrt" or (sysconfig.get_platform() == 'mingw' and platform.architecture()[0] == '64bit')):
7876
response = requests.get('https://build.openmodelica.org/omsimulator/nightly/win-mingw-ucrt64/OMSimulator-mingw-ucrt64-@OMS_VERSION_STRING@.zip')
77+
dllpath = "bin/libOMSimulator.dll"
7978
elif (sysconfig.get_platform() == 'win-amd64'):
8079
response = requests.get('https://build.openmodelica.org/omsimulator/nightly/win-msvc64/OMSimulator-win64-@OMS_VERSION_STRING@.zip')
80+
dllpath = "bin/OMSimulator.dll"
8181
elif (platform.system() == 'Darwin'):
8282
response = requests.get('https://build.openmodelica.org/omsimulator/nightly/osx/OMSimulator-osx-@OMS_VERSION_STRING@.zip')
83+
dllpath = "lib/libOMSimulator.dylib"
8384
else:
8485
raise Exception("Platform not supported for {} ".format(sysconfig.get_platform()))
8586

@@ -112,6 +113,12 @@ def fetch_oms(self):
112113
# copy OMSimulator package to root directory
113114
copy_tree(os.path.join(zipDir, 'lib/OMSimulator'), target_dir)
114115

116+
# copy schema path to OMSimulator/schema
117+
copy_tree(os.path.join(zipDir, 'share/OMSimulator/schema'), target_dir +"/schema")
118+
119+
# copy dll to root directory
120+
copy_file(os.path.join(zipDir, dllpath), target_dir)
121+
115122
# remove the zip directory after copying the files
116123
shutil.rmtree(zipDir)
117124

0 commit comments

Comments
 (0)