From: George Thessalonikefs Date: Wed, 9 Nov 2022 10:41:28 +0000 (+0100) Subject: - Complementary fix for distutils.sysconfig deprecation in Python 3.10 X-Git-Tag: release-1.17.1rc1~19 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4e305e644bddae5e697584a3605c7adcc38ae561;p=thirdparty%2Funbound.git - Complementary fix for distutils.sysconfig deprecation in Python 3.10 to commit 62c5039ab9da42713e006e840b7578e01d66e7f2. --- diff --git a/doc/Changelog b/doc/Changelog index b21f3415d..85a22e58e 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,7 @@ +9 November 2022: George + - Complementary fix for distutils.sysconfig deprecation in Python 3.10 + to commit 62c5039ab9da42713e006e840b7578e01d66e7f2. + 8 November 2022: Wouter - Fix to ignore tcp events for closed comm points. - Fix to make sure to not read again after a tcp comm point is closed. diff --git a/pythonmod/pythonmod.c b/pythonmod/pythonmod.c index 4bea54e6a..7c7da5489 100644 --- a/pythonmod/pythonmod.c +++ b/pythonmod/pythonmod.c @@ -255,7 +255,7 @@ cleanup: int pythonmod_init(struct module_env* env, int id) { int py_mod_idx = py_mod_count++; - + /* Initialize module */ FILE* script_py = NULL; PyObject* py_init_arg, *res; @@ -316,23 +316,37 @@ int pythonmod_init(struct module_env* env, int id) if (py_mod_count==1) { /* Initialize Python */ - PyRun_SimpleString("import sys \n"); + if(PyRun_SimpleString("import sys \n") < 0 ) { + goto python_init_fail; + } PyRun_SimpleString("sys.path.append('.') \n"); + PyRun_SimpleString("sys.path.append('"RUN_DIR"') \n"); + PyRun_SimpleString("sys.path.append('"SHARE_DIR"') \n"); if(env->cfg->directory && env->cfg->directory[0]) { char wdir[1524]; snprintf(wdir, sizeof(wdir), "sys.path.append('%s') \n", env->cfg->directory); PyRun_SimpleString(wdir); } - PyRun_SimpleString("sys.path.append('"RUN_DIR"') \n"); - PyRun_SimpleString("sys.path.append('"SHARE_DIR"') \n"); - PyRun_SimpleString("import distutils.sysconfig \n"); - PyRun_SimpleString("sys.path.append(distutils.sysconfig.get_python_lib(1,0)) \n"); - if (PyRun_SimpleString("from unboundmodule import *\n") < 0) + /* Check if sysconfig is there and use that instead of distutils; + * distutils.sysconfig is deprecated in Python 3.10. */ + if(PyRun_SimpleString("import sysconfig \n") < 0) { + log_info("pythonmod: module sysconfig not available; " + "falling back to distutils.sysconfig."); + if(PyRun_SimpleString("import distutils.sysconfig \n") < 0 + || PyRun_SimpleString("sys.path.append(" + "distutils.sysconfig.get_python_lib(1,0)) \n") < 0) { + goto python_init_fail; + } + } else { + if(PyRun_SimpleString("sys.path.append(" + "sysconfig.get_path('platlib')) \n") < 0) { + goto python_init_fail; + } + } + if(PyRun_SimpleString("from unboundmodule import *\n") < 0) { - log_err("pythonmod: cannot initialize core module: unboundmodule.py"); - PyGILState_Release(gil); - return 0; + goto python_init_fail; } } @@ -480,6 +494,11 @@ int pythonmod_init(struct module_env* env, int id) PyGILState_Release(gil); return 1; + +python_init_fail: + log_err("pythonmod: cannot initialize core module: unboundmodule.py"); + PyGILState_Release(gil); + return 0; } void pythonmod_deinit(struct module_env* env, int id)