1 #ifndef MHO_PyConfigurePath_HH__
2 #define MHO_PyConfigurePath_HH__
11 #include <pybind11/embed.h>
12 #include <pybind11/pybind11.h>
13 namespace py = pybind11;
26 static void configure_pypath()
28 if(Py_IsInitialized() == 0)
31 msg_warn(
"python_bindings",
"python interpreter not running/initialized, cannot configure path " << eom);
38 std::stringstream pyss;
39 pyss <<
"import sys\n";
42 if(default_path.empty())
45 "could not determine HOPS install prefix; using relative path for default plugins directory" << eom);
48 default_path +=
"/plugin_scripts";
49 if(default_path.back() !=
'/')
51 default_path.push_back(
'/');
53 msg_info(
"main",
"adding HOPS_DEFAULT_PLUGINS_DIR to search path: " << default_path << eom);
54 pyss <<
"sys.path.append(\"" << default_path <<
"\") \n";
59 #ifdef HOPS_PYTHON_SITE_SUBDIR
64 if(site_dir.back() !=
'/')
66 site_dir.push_back(
'/');
68 site_dir += HOPS_PYTHON_SITE_SUBDIR;
69 msg_info(
"main",
"adding HOPS python module dir to search path: " << site_dir << eom);
70 pyss <<
"sys.path.insert(0, \"" << site_dir <<
"\")\n";
75 const char* user_plugin_env = std::getenv(
"HOPS_USER_PLUGINS_DIR");
76 if(user_plugin_env !=
nullptr)
78 std::string user_specified_path = std::string(user_plugin_env);
79 if(user_specified_path.back() !=
'/')
81 user_specified_path.push_back(
'/');
83 msg_info(
"main",
"adding HOPS_USER_PLUGINS_DIR to search path: " << user_specified_path << eom);
84 pyss <<
"sys.path.append(\"" << user_specified_path <<
"\") \n";
89 pyss <<
"sys.stdout.reconfigure(line_buffering=True)\n";
92 pyss <<
"import pyMHO_Containers\n";
93 pyss <<
"import pyMHO_Operators\n";
94 pyss <<
"import pyMHO_Calibration\n";
103 py::exec(pyss.str().c_str());
#define msg_warn(xKEY, xCONTENT)
Definition: MHO_Message.hh:248
#define msg_info(xKEY, xCONTENT)
Definition: MHO_Message.hh:268
static std::string GetHopsInstallPrefix()
Returns the absolute path of the HOPS install prefix, determined at runtime from the on-disk location...
Definition: MHO_DirectoryInterface.cc:73
Definition: MHO_AdhocFlagging.hh:18