]> 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>
Sat, 22 Jun 2024 01:23:30 +0000 (09:23 +0800)
commit51a5774aa605f3b976ced47902e15ce450f50339
tree835e1c3d1c1dd568adc4716e41020aba8c64e318
parent07773617f339a2779aa7cf910c0361c937ffe4c2
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, 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`.

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 *);
      |                                      ^~~~~~~~~~~~~
```

Fixes https://tracker.ceph.com/issues/66399
Signed-off-by: Kefu Chai <tchaikov@gmail.com>
src/mgr/PyModule.cc
src/mgr/PyModule.h
src/mgr/PyModuleRegistry.cc
src/mgr/PyModuleRegistry.h