MCPcopy Create free account
hub / github.com/Cantera/cantera / loadCanteraPython

Function loadCanteraPython

src/extensions/pythonShim.cpp:67–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65}
66
67void loadCanteraPython()
68{
69 // Prevent output buffering managed by Python.
70 // @todo: It may be better to avoid replacing the existing Logger instance
71 // with a PythonLogger in the case of an embedded Python interpreter.
72 const char* venv_path = getenv("VIRTUAL_ENV");
73 if (venv_path != nullptr) {
74 PyConfig pyconf;
75 pyconf.buffered_stdio = 0;
76 PyConfig_InitPythonConfig(&pyconf);
77
78 #ifdef _WIN32
79 string suffix = "\\Scripts\\python.exe";
80 #else
81 string suffix = "/bin/python";
82 #endif
83 string path(venv_path);
84 path += suffix;
85 wstring wpath = std::filesystem::path(path).wstring();
86 PyStatus status = PyConfig_SetString(&pyconf, &pyconf.program_name,
87 wpath.c_str());
88 checkPythonError(PyStatus_Exception(status), "PyConfig_SetString failed");
89 Py_InitializeFromConfig(&pyconf);
90 } else {
91 #ifdef _WIN32
92 setPythonHome();
93 #endif
94 Py_Initialize();
95 }
96 PyObject* pythonExt = PyImport_ImportModule("cantera");
97 checkPythonError(pythonExt == nullptr, "cantera import failed");
98 Py_DecRef(pythonExt);
99}
100
101// This creates and exports the name that is imported from Application::loadExtension
102BOOST_DLL_ALIAS(loadCanteraPython,

Callers

nothing calls this directly

Calls 2

checkPythonErrorFunction · 0.85
setPythonHomeFunction · 0.85

Tested by

no test coverage detected