1 #ifndef MHO_PyConfigurePath_HH__
2 #define MHO_PyConfigurePath_HH_
10 #include <pybind11/embed.h>
11 #include <pybind11/pybind11.h>
12 namespace py = pybind11;
25 static void configure_pypath()
27 if(Py_IsInitialized() == 0)
30 msg_warn(
"python_bindings",
"python interpreter not running/initialized, cannot configure path " << eom);
37 std::stringstream pyss;
38 pyss <<
"import sys\n";
39 std::string default_path =
STRING(HOPS_DEFAULT_PLUGINS_DIR);
40 if(default_path.back() !=
'/')
42 default_path.push_back(
'/');
44 msg_info(
"main",
"adding HOPS_DEFAULT_PLUGINS_DIR to search path: " << default_path << eom);
45 pyss <<
"sys.path.append(\"" << default_path <<
"\") \n";
46 const char* user_plugin_env = std::getenv(
"HOPS_USER_PLUGINS_DIR");
47 if(user_plugin_env !=
nullptr)
49 std::string user_specified_path = std::string(user_plugin_env);
50 if(user_specified_path.back() !=
'/')
52 user_specified_path.push_back(
'/');
54 msg_info(
"main",
"adding HOPS_USER_PLUGINS_DIR to search path: " << user_specified_path << eom);
55 pyss <<
"sys.path.append(\"" << user_specified_path <<
"\") \n";
59 pyss <<
"import pyMHO_Containers\n";
60 pyss <<
"import pyMHO_Operators\n";
71 py::exec(pyss.str().c_str());
#define msg_warn(xKEY, xCONTENT)
Definition: MHO_Message.hh:254
#define msg_info(xKEY, xCONTENT)
Definition: MHO_Message.hh:274
#define STRING(str)
Definition: MHO_Message.hh:22
Definition: MHO_ChannelLabeler.hh:17