MCPcopy Create free account
hub / github.com/BespokeSynth/BespokeSynth / InitializePythonIfNecessary

Method InitializePythonIfNecessary

Source/ScriptModule.cpp:163–187  ·  view source on GitHub ↗

static

Source from the content-addressed store, hash-verified

161
162//static
163void ScriptModule::InitializePythonIfNecessary()
164{
165 if (!sPythonInitialized)
166 {
167#ifdef BESPOKE_PORTABLE_PYTHON
168 static const auto pythonHomeUtf8{ ofToFactoryPath("python") };
169 static auto PYTHONHOME{ toPythonHome(pythonHomeUtf8, Py_SetPythonHome) };
170 Py_SetPythonHome(PYTHONHOME.data());
171#endif
172 py::initialize_interpreter();
173#ifdef BESPOKE_PORTABLE_PYTHON
174 py::exec(std::string{ "import sys; sys.executable = '" } + pythonHomeUtf8 + "/" BESPOKE_PORTABLE_PYTHON "'; del sys");
175#endif
176 py::exec(GetBootstrapImportString(), py::globals());
177
178 CodeEntry::OnPythonInit();
179 }
180 sPythonInitialized = true;
181
182 if (!sHasPythonEverSuccessfullyInitialized)
183 {
184 File(ofToDataPath("internal/python_" + std::string(Bespoke::PYTHON_VERSION) + "_installed")).create();
185 sHasPythonEverSuccessfullyInitialized = true;
186 }
187}
188
189//static
190void ScriptModule::CheckIfPythonEverSuccessfullyInitialized()

Callers

nothing calls this directly

Calls 5

ofToFactoryPathFunction · 0.85
toPythonHomeFunction · 0.85
ofToDataPathFunction · 0.85
dataMethod · 0.80
createMethod · 0.80

Tested by

no test coverage detected