]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commit
mgr: add site package paths in PyModuleRegistry
authorKefu Chai <tchaikov@gmail.com>
Sat, 3 Feb 2024 13:09:27 +0000 (21:09 +0800)
committerKefu Chai <tchaikov@gmail.com>
Sun, 4 Feb 2024 08:32:08 +0000 (16:32 +0800)
commit45832deb6ccdc4886a27cf506bb46e9edacd3299
tree23ef461785ab4f7ef88b4100125fd39bfcf1441e
parente417c1c935a35dbed838f1e664729647817a47e2
mgr: add site package paths in PyModuleRegistry

before this change, we add the paths of site packages to sys.path
when starting subinterpretors for each of the mgr modules. this
works just fine. but in Python 3.11, it deprecates `PySys_SetPath()`
in favor of PyConfig machinary, which sets the module search paths
in PyConfig, before calling `Py_InitializeFromConfig()`. so, to
set the module search paths with the new machinary, we need to do
this in `PyModuleRegistry`, where we initialize the global Python
interpretor using the new PyConfig machinary. and since we've
switched to the new PyConfig machinary when compiling with Python 3.8
and up.

in this change, to unify the implementation of pre and post Python 3.8,
we set the module search paths in PyModuleRegistry. because PyConfig
imports the site packages by default, and we are allowed to append
a new path to the existing search paths, we just append the configured
`mgr_module_path` when compiling with Python 3.8 and up. and when it
comes to lower versions of Python, the existing behavior is preserved.

this change should silence the compiling warning like:

```
/var/ssd/ceph/src/mgr/PyModule.cc:368:20: warning: ‘void PySys_SetPath(const wchar_t*)’ is deprecated [-Wdeprecated-declarations]
  368 |       PySys_SetPath(const_cast<wchar_t*>(sys_path.c_str()));
      |       ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/python3.12/sysmodule.h:15:38: note: declared here
   15 | Py_DEPRECATED(3.11) PyAPI_FUNC(void) PySys_SetPath(const wchar_t *);
      |                                      ^~~~~~~~~~~~~
```

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
src/mgr/PyModule.cc
src/mgr/PyModule.h
src/mgr/PyModuleRegistry.cc
src/mgr/PyModuleRegistry.h