gncmod-python.c (gnucash-5.0.tar.bz2) | : | gncmod-python.c (gnucash-5.1.tar.bz2) | ||
---|---|---|---|---|
skipping to change at line 58 | skipping to change at line 58 | |||
{ | { | |||
return g_strdup("gnucash/python"); | return g_strdup("gnucash/python"); | |||
} | } | |||
char * | char * | |||
libgncmod_python_gnc_module_description(void) | libgncmod_python_gnc_module_description(void) | |||
{ | { | |||
return g_strdup("An embedded Python interpreter"); | return g_strdup("An embedded Python interpreter"); | |||
} | } | |||
//extern PyObject* PyInit__sw_app_utils(void); | #if PY_VERSION_HEX >= 0x030b0000 | |||
//extern PyObject* PyInit__sw_core_utils(void); | // PySys_SetArgv is deprecated in 3.11 | |||
#pragma GCC diagnostic warning "-Wdeprecated-declarations" | ||||
#endif | ||||
int | int | |||
libgncmod_python_gnc_module_init(int refcount) | libgncmod_python_gnc_module_init(int refcount) | |||
{ | { | |||
/* There isn't yet a python module to init. | ||||
PyObject *pName, *pModule; | ||||
*/ | ||||
FILE *fp; | ||||
gchar *pkgdatadir, *init_filename; | ||||
wchar_t* argv = NULL; | ||||
Py_Initialize(); | Py_Initialize(); | |||
wchar_t* argv = NULL; | ||||
PySys_SetArgv(0, &argv); | PySys_SetArgv(0, &argv); | |||
// I don't quite understand why these are loaded here | ||||
// - these are python modules so should be able to just import them | ||||
// in init.py | ||||
//PyInit__sw_app_utils(); | ||||
//PyInit__sw_core_utils(); | ||||
/* There isn't yet a python module to init. | ||||
pName = PyString_FromString("path/to/init.py"); | ||||
pModule = PyImport_Import(pName); | ||||
if (!pModule) { | ||||
PyErr_Print(); | ||||
return FALSE; | ||||
} | ||||
Py_DECREF(pName); | gchar *pkgdatadir = gnc_path_get_pkgdatadir(); | |||
Py_DECREF(pModule); | gchar *init_filename = g_build_filename(pkgdatadir, "python/init.py", (char* | |||
*/ | )NULL); | |||
g_debug("Looking for python init script at %s", init_filename); | ||||
pkgdatadir = gnc_path_get_pkgdatadir(); | FILE *fp = fopen(init_filename, "r"); | |||
init_filename = g_build_filename(pkgdatadir, "python/init.py", (char*)NULL); | ||||
g_debug("Looking for python init script at %s", (init_filename ? init_filena | ||||
me : "<null>")); | ||||
fp = fopen(init_filename, "r"); | ||||
if (fp) | if (fp) | |||
{ | { | |||
PyRun_SimpleFile(fp, init_filename); | PyRun_SimpleFile(fp, init_filename); | |||
fclose(fp); | fclose(fp); | |||
/* PyRun_InteractiveLoop(stdin, "foo"); */ | /* PyRun_InteractiveLoop(stdin, "foo"); */ | |||
} | } | |||
else | else | |||
{ | { | |||
g_warning("Unable to initialize Python module (unable to open %s)", init _filename); | g_warning("Unable to initialize Python module (unable to open %s)", init _filename); | |||
End of changes. 5 change blocks. | ||||
32 lines changed or deleted | 11 lines changed or added |