MCPcopy Create free account
hub / github.com/NatronGitHub/Natron / interpretPythonScript

Method interpretPythonScript

Engine/AppManager.cpp:3619–3764  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3617#endif
3618
3619bool
3620NATRON_PYTHON_NAMESPACE::interpretPythonScript(const std::string& script,
3621 std::string* error,
3622 std::string* output)
3623{
3624#ifdef NATRON_RUN_WITHOUT_PYTHON
3625
3626 return true;
3627#endif
3628 PythonGILLocker pgl;
3629 PyObject* mainModule = NATRON_PYTHON_NAMESPACE::getMainModule();
3630 int status = -1;
3631#if 0 //USE_PYRUN_SIMPLESTRING
3632 status = PyRun_SimpleString(script.c_str());
3633#else
3634 PyObject* dict = PyModule_GetDict(mainModule);
3635
3636 PyErr_Clear();
3637
3638 ///This is faster than PyRun_SimpleString since is doesn't call PyImport_AddModule("__main__")
3639 PyObject* v = PyRun_String(script.c_str(), Py_file_input, dict, 0);
3640 if (v) {
3641 Py_DECREF(v);
3642 status = 0;
3643 }
3644#endif
3645
3646 if (error) {
3647 error->clear();
3648 }
3649 PyObject* ex = PyErr_Occurred();
3650 if (ex) {
3651 assert(status < 0);
3652 if (!error) {
3653 PyErr_Clear();
3654 } else {
3655 PyObject *pyExcType;
3656 PyObject *pyExcValue;
3657 PyObject *pyExcTraceback;
3658 PyErr_Fetch(&pyExcType, &pyExcValue, &pyExcTraceback); // also clears the error indicator
3659 //PyErr_NormalizeException(&pyExcType, &pyExcValue, &pyExcTraceback);
3660
3661 PyObject* pyStr = PyObject_Str(pyExcValue);
3662 if (pyStr) {
3663 std::string str = NATRON_PYTHON_NAMESPACE::PyStringToStdString(pyStr);
3664 if ( error && !str.empty() ) {
3665 *error += std::string("Python exception: ") + str + '\n';
3666 }
3667 Py_DECREF(pyStr);
3668
3669 // See if we can get a full traceback
3670#if PY_MAJOR_VERSION >= 3
3671 PyObject* module_name = PyUnicode_FromString("traceback");
3672#else
3673 PyObject* module_name = PyString_FromString("traceback");
3674#endif
3675 PyObject* pyth_module = PyImport_Import(module_name);
3676 Py_DECREF(module_name);

Callers

nothing calls this directly

Calls 4

PyStringToStdStringFunction · 0.85
emptyMethod · 0.80
clearMethod · 0.45
isBackgroundMethod · 0.45

Tested by

no test coverage detected