App: Simplify and fix code for ifcopenshell version check

This commit is contained in:
wmayer
2025-02-27 10:20:39 +01:00
committed by Ladislav Michl
parent 2c25b65b92
commit 2799aa2700

View File

@@ -3702,24 +3702,23 @@ void Application::getVerboseCommonInfo(QTextStream& str, const std::map<std::str
#endif
str << "xerces-c " << fcXercescVersion << ", ";
const char* cmd = "import ifcopenshell\n"
"version = ifcopenshell.version";
PyObject * ifcopenshellVer = nullptr;
try {
ifcopenshellVer = Base::Interpreter().getValue(cmd, "version");
}
catch (const Base::Exception& e) {
Base::Console().log("%s (safe to ignore, unless using the BIM workbench and IFC).\n", e.what());
}
if (ifcopenshellVer) {
const char* ifcopenshellVerAsStr = PyUnicode_AsUTF8(ifcopenshellVer);
if (ifcopenshellVerAsStr) {
str << "IfcOpenShell " << ifcopenshellVerAsStr << ", ";
Base::PyGILStateLocker lock;
Py::Module module(PyImport_ImportModule("ifcopenshell"), true);
if (!module.isNull() && module.hasAttr("version")) {
Py::String version(module.getAttr("version"));
auto ver_str = static_cast<std::string>(version);
str << "IfcOpenShell " << ver_str.c_str() << ", ";
}
Py_DECREF(ifcopenshellVer);
else {
Base::Console().log("Module 'ifcopenshell' not found (safe to ignore, unless using "
"the BIM workbench and IFC).\n");
}
}
catch (const Py::Exception&) {
Base::PyGILStateLocker lock;
Base::PyException e;
Base::Console().log("%s\n", e.what());
}
#if defined(HAVE_OCC_VERSION)