Program Listing for File python.h¶
↰ Return to documentation for file (interfaces/python.h)
#pragma once
#ifdef LUPNT_WITH_PYTHON
# include <pybind11/eigen.h>
# include <pybind11/embed.h>
# include <pybind11/pybind11.h>
# include <optional>
namespace py = pybind11;
namespace lupnt {
class PythonInterpreter {
public:
static PythonInterpreter& GetInstance() {
static PythonInterpreter instance;
return instance;
}
private:
std::optional<py::scoped_interpreter> python_; // Manages Python interpreter
PythonInterpreter() {
// Only initialize if we're not already in a Python process
if (!Py_IsInitialized()) {
python_.emplace();
}
}
~PythonInterpreter() = default;
PythonInterpreter(const PythonInterpreter&) = delete;
PythonInterpreter& operator=(const PythonInterpreter&) = delete;
};
extern py::module_ py_pnt;
extern py::module_ py_pio;
extern py::module_ py_go;
extern py::module_ py_plot;
extern py::module_ py_plt;
} // namespace lupnt
#endif // LUPNT_WITH_PYTHON