36 std::lock_guard<std::mutex> _(itsMtx);
38 itsConstructionError.clear();
44 itsMainModule = boost::python::import(
"__main__");
45 itsMainNamespace = itsMainModule.attr(
"__dict__");
48 size_t last_slash = path.rfind(
'/');
49 std::string
const pydir = path.substr(0, last_slash);
50 std::string
const pyclass = path.substr(last_slash + 1, path.length() - last_slash - 4);
51 std::string
const execstr =
56 "sys.path.append(\"" + pydir +
"\")\n" +
57 "import " + pyclass +
"\n" +
58 "import importlib\n" +
59 "importlib.reload(" + pyclass +
")\n";
61 boost::python::exec(execstr.c_str(), itsMainNamespace, itsMainNamespace);
64 itsInstance = boost::python::eval((pyclass +
"." + pyclass +
"()").c_str(), itsMainNamespace, itsMainNamespace);
68 if (comp) comp->engine()->registerPythonComponent(comp, itsInstance.ptr()->ob_type);
70 catch (boost::python::error_already_set & e)
74 catch (std::exception
const & e)
76 itsConstructionError = e.what();
80 itsConstructionError =
"Unknown construction error";