mirror of
https://github.com/NLnetLabs/unbound.git
synced 2025-12-20 23:00:56 -05:00
Merge pull request #896 from socketpair/bugfix
Fix: #895: pythonmodule: add all site-packages directories to sys.path
This commit is contained in:
commit
0585b1d75a
1 changed files with 4 additions and 36 deletions
|
|
@ -328,44 +328,12 @@ int pythonmod_init(struct module_env* env, int id)
|
||||||
env->cfg->directory);
|
env->cfg->directory);
|
||||||
PyRun_SimpleString(wdir);
|
PyRun_SimpleString(wdir);
|
||||||
}
|
}
|
||||||
/* Check if sysconfig is there and use that instead of distutils;
|
if(PyRun_SimpleString("import site\n") < 0) {
|
||||||
* distutils.sysconfig is deprecated in Python 3.10. */
|
goto python_init_fail;
|
||||||
#if PY_MAJOR_VERSION <= 2 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 9)
|
|
||||||
/* For older versions, first try distutils.sysconfig because the
|
|
||||||
* sysconfig paths may contain wrong values, eg. on Debian10 for
|
|
||||||
* python 2.7 and 3.7. */
|
|
||||||
if(PyRun_SimpleString("import distutils.sysconfig \n") < 0) {
|
|
||||||
log_info("pythonmod: module distutils.sysconfig not available; "
|
|
||||||
"falling back to sysconfig.");
|
|
||||||
if(PyRun_SimpleString("import sysconfig \n") < 0
|
|
||||||
|| PyRun_SimpleString("sys.path.append("
|
|
||||||
"sysconfig.get_path('platlib')) \n") < 0) {
|
|
||||||
goto python_init_fail;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(PyRun_SimpleString("sys.path.append("
|
|
||||||
"distutils.sysconfig.get_python_lib(1,0)) \n") < 0) {
|
|
||||||
goto python_init_fail;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#else
|
if(PyRun_SimpleString("sys.path.extend(site.getsitepackages())\n") < 0) {
|
||||||
/* Python 3.10 and higher, check sysconfig first,
|
goto python_init_fail;
|
||||||
* distutils is deprecated. */
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
if(PyRun_SimpleString("from unboundmodule import *\n") < 0)
|
if(PyRun_SimpleString("from unboundmodule import *\n") < 0)
|
||||||
{
|
{
|
||||||
goto python_init_fail;
|
goto python_init_fail;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue