]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commit
mgr: stop using deprecated API to initialize Python
authorKefu Chai <tchaikov@gmail.com>
Sat, 3 Feb 2024 11:22:15 +0000 (19:22 +0800)
committerKefu Chai <tchaikov@gmail.com>
Sun, 4 Feb 2024 08:32:08 +0000 (16:32 +0800)
commita21d80c6b4c9e27e5472fed837bb6308639b0492
treeadb7135d6bc8e7cf1dbe635ad786f2e853c56c5f
parent4103b566e4b177a2d12932604b1df868022ef5d8
mgr: stop using deprecated API to initialize Python

Py_SetProgramName() is deprecated since CPython 3.11, see
https://docs.python.org/3/c-api/init_config.html .
`Py_InitializeFromConfig()` and friends were introduced by CPython 3.8,
but we still need to support CPython 3.6 which is shipped by CentOS8.
so we have to be backward compatible with the older Python versions.

so let's use new machinary to initialize the Python interpretor if the
tree is compiled with CPython 3.8 and up, i.e., PY_VERSION_HEX >= 0x03080000.
so that this piece of code can be tested on ubuntu:jammy, which ships
Python 3.10, see https://packages.ubuntu.com/jammy/amd64/python3

this change addresses following compiling warning:

```
[428/753] Building CXX object src/mgr/CMakeFiles/ceph-mgr.dir/PyModuleRegistry.cc.o
/var/ssd/ceph/src/mgr/PyModuleRegistry.cc: In member function ‘void PyModuleRegistry::init()’:
/var/ssd/ceph/src/mgr/PyModuleRegistry.cc:49:20: warning: ‘void Py_SetProgramName(const wchar_t*)’ is deprecated [-Wdeprecated-declarations]
   49 |   Py_SetProgramName(const_cast<wchar_t*>(WCHAR(MGR_PYTHON_EXECUTABLE)));
      |   ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/python3.12/Python.h:94,
                 from /var/ssd/ceph/src/mgr/PyModule.h:22,
                 from /var/ssd/ceph/src/mgr/PyModuleRegistry.h:18,
                 from /var/ssd/ceph/src/mgr/PyModuleRegistry.cc:14:
/usr/include/python3.12/pylifecycle.h:37:38: note: declared here
   37 | Py_DEPRECATED(3.11) PyAPI_FUNC(void) Py_SetProgramName(const wchar_t *);
      |                                      ^~~~~~~~~~~~~~~~~`
```

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