Whamcloud - gitweb
LU-17160 build: Use PyConfig_InitPythonConfig 3.11 and later 58/52558/7
authorShaun Tancheff <shaun.tancheff@hpe.com>
Sat, 11 Nov 2023 01:40:22 +0000 (19:40 -0600)
committerOleg Drokin <green@whamcloud.com>
Wed, 10 Jan 2024 07:28:57 +0000 (07:28 +0000)
Python PEP https://peps.python.org/pep-0587 changed the python
initialization scheme and deprecated Py_SetProgramName() among
other functions.

As of python 3.11 the new init scheme is available.

Test-Parameters: trivial
Signed-off-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Change-Id: Ia7bdb63a74295ab8cf0313f16bfd03d78cf8fcf7
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52558
Tested-by: Maloo <maloo@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Frank Sehr <fsehr@whamcloud.com>
Reviewed-by: Cyril Bordage <cbordage@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/tests/lutf/src/lutf_python.c

index 1c1d64f..d1b6e97 100644 (file)
@@ -206,11 +206,26 @@ python_shutdown:
  */
 lutf_rc_t python_init(void)
 {
+       lutf_rc_t rc = EN_LUTF_RC_FAIL;
        wchar_t program[5];
-       lutf_rc_t rc;
 
        swprintf(program, 3, L"%hs", "lutf");
 
+#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 11) || PY_MAJOR_VERSION > 3
+       PyStatus status;
+       PyConfig config;
+
+       PyConfig_InitPythonConfig(&config);
+
+       status = PyConfig_SetString(&config, &config.program_name, program);
+       if (!PyStatus_Exception(status))
+               status = Py_InitializeFromConfig(&config);
+       if (!PyStatus_Exception(status))
+               rc = python_run_interactive_shell();
+       PyConfig_Clear(&config);
+       if (PyStatus_Exception(status))
+               Py_ExitStatusException(status);
+#else
        //char *path;
        //char new_path[MAX_STR_LEN];
        Py_SetProgramName(program);
@@ -230,6 +245,7 @@ lutf_rc_t python_init(void)
        Py_Finalize();
 
        PDEBUG("Python finalized");
+#endif
 
        return rc;
 }