24 itsConstructionError(
"Not operational yet because pythonload() was not called")
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 =
53 "sys.path.append(\"" JEVOIS_ROOT_PATH
"/lib\")\n"
54 "sys.path.append(\"" JEVOIS_CONFIG_PATH
"\")\n"
55 "sys.path.append(\"" JEVOIS_OPENCV_PYTHON_PATH
"\")\n"
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);
70 catch (boost::python::error_already_set & e)
74 catch (std::exception
const & e)
76 itsConstructionError = e.what();
80 itsConstructionError =
"Unknown construction error";
87 if (itsConstructionError.empty() ==
false || itsInstance.is_none())
throw std::runtime_error(itsConstructionError);
93 {
return itsMainModule; }
97 {
return itsMainNamespace; }
101 {
return itsConstructionError; }
106 std::lock_guard<std::mutex> _(itsMtx);
109 if (itsInstance.is_none() ==
false)