]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-105145: Deprecate Py_GetPath() function (#105179)
authorVictor Stinner <vstinner@python.org>
Thu, 1 Jun 2023 12:06:32 +0000 (14:06 +0200)
committerGitHub <noreply@github.com>
Thu, 1 Jun 2023 12:06:32 +0000 (12:06 +0000)
Deprecate old Python initialization functions:

* PySys_ResetWarnOptions()
* Py_GetExecPrefix()
* Py_GetPath()
* Py_GetPrefix()
* Py_GetProgramFullPath()
* Py_GetProgramName()
* Py_GetPythonHome()

_tkinter.c uses sys.executable instead of Py_GetProgramName()
and uses sys.prefix instead of Py_GetPrefix().

Doc/c-api/init.rst
Doc/c-api/sys.rst
Doc/whatsnew/3.13.rst
Include/pylifecycle.h
Include/sysmodule.h
Misc/NEWS.d/next/C API/2023-06-01-09-40-30.gh-issue-105145.WOOE-w.rst [new file with mode: 0644]
Modules/_tkinter.c

index dfb381953dd51d5506e8736dd2b10538aca15bac..1dab0af2659b4ec5c9a4e3a13d6f7650e366acac 100644 (file)
@@ -429,6 +429,9 @@ Process-wide parameters
    .. versionchanged:: 3.10
       It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
 
+   .. deprecated-removed:: 3.13 3.15
+      Get :data:`sys.executable` instead.
+
 
 .. c:function:: wchar_t* Py_GetPrefix()
 
@@ -448,6 +451,9 @@ Process-wide parameters
    .. versionchanged:: 3.10
       It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
 
+   .. deprecated-removed:: 3.13 3.15
+      Get :data:`sys.prefix` instead.
+
 
 .. c:function:: wchar_t* Py_GetExecPrefix()
 
@@ -489,6 +495,9 @@ Process-wide parameters
    .. versionchanged:: 3.10
       It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
 
+   .. deprecated-removed:: 3.13 3.15
+      Get :data:`sys.exec_prefix` instead.
+
 
 .. c:function:: wchar_t* Py_GetProgramFullPath()
 
@@ -507,6 +516,9 @@ Process-wide parameters
    .. versionchanged:: 3.10
       It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
 
+   .. deprecated-removed:: 3.13 3.15
+      Get :data:`sys.executable` instead.
+
 
 .. c:function:: wchar_t* Py_GetPath()
 
@@ -532,6 +544,9 @@ Process-wide parameters
    .. versionchanged:: 3.10
       It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
 
+   .. deprecated-removed:: 3.13 3.15
+      Get :data:`sys.path` instead.
+
 
 .. c:function:: const char* Py_GetVersion()
 
@@ -615,6 +630,10 @@ Process-wide parameters
    .. versionchanged:: 3.10
       It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
 
+   .. deprecated-removed:: 3.13 3.15
+      Get :c:member:`PyConfig.home` or :envvar:`PYTHONHOME` environment
+      variable instead.
+
 
 .. _threads:
 
index ad6005b7c7a878b7b10cdfce14e42b90dc4539b5..c4077b2a5620d66d2f3889ae42015a08845258cd 100644 (file)
@@ -237,6 +237,9 @@ accessible to C code.  They all work with the current interpreter thread's
    Reset :data:`sys.warnoptions` to an empty list. This function may be
    called prior to :c:func:`Py_Initialize`.
 
+   .. deprecated-removed:: 3.13 3.15
+      Clear :data:`sys.warnoptions` and :data:`!warnings.filters` instead.
+
 .. c:function:: void PySys_WriteStdout(const char *format, ...)
 
    Write the output string described by *format* to :data:`sys.stdout`.  No
index f3ded6ae34eca3fd4a3b107f8b11a6e84bbb5fe0..8427bda514ba5e4205694773fb70986d566b06b3 100644 (file)
@@ -357,6 +357,20 @@ Deprecated
   ``PY_UNICODE_TYPE`` are just aliases to ``wchar_t``.
   (Contributed by Victor Stinner in :gh:`105156`.)
 
+* Deprecate old Python initialization functions:
+
+  * :c:func:`PySys_ResetWarnOptions`:
+    clear :data:`sys.warnoptions` and :data:`!warnings.filters` instead.
+  * :c:func:`Py_GetExecPrefix`: get :data:`sys.exec_prefix` instead.
+  * :c:func:`Py_GetPath`: get :data:`sys.path` instead.
+  * :c:func:`Py_GetPrefix`: get :data:`sys.prefix` instead.
+  * :c:func:`Py_GetProgramFullPath`: get :data:`sys.executable` instead.
+  * :c:func:`Py_GetProgramName`: get :data:`sys.executable` instead.
+  * :c:func:`Py_GetPythonHome`: get :c:member:`PyConfig.home` or
+    :envvar:`PYTHONHOME` environment variable instead.
+
+  (Contributed by Victor Stinner in :gh:`105145`.)
+
 Removed
 -------
 
index 0190b4c3f5dedaceaf85d24c6633ce9665a668e3..34f32a5000e9d5ff4c4a6b83e6bd165327a7cb7f 100644 (file)
@@ -34,12 +34,12 @@ PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv);
 PyAPI_FUNC(int) Py_BytesMain(int argc, char **argv);
 
 /* In pathconfig.c */
-PyAPI_FUNC(wchar_t *) Py_GetProgramName(void);
-PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void);
-PyAPI_FUNC(wchar_t *) Py_GetProgramFullPath(void);
-PyAPI_FUNC(wchar_t *) Py_GetPrefix(void);
-PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void);
-PyAPI_FUNC(wchar_t *) Py_GetPath(void);
+Py_DEPRECATED(3.13) PyAPI_FUNC(wchar_t *) Py_GetProgramName(void);
+Py_DEPRECATED(3.13) PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void);
+Py_DEPRECATED(3.13) PyAPI_FUNC(wchar_t *) Py_GetProgramFullPath(void);
+Py_DEPRECATED(3.13) PyAPI_FUNC(wchar_t *) Py_GetPrefix(void);
+Py_DEPRECATED(3.13) PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void);
+Py_DEPRECATED(3.13) PyAPI_FUNC(wchar_t *) Py_GetPath(void);
 #ifdef MS_WINDOWS
 int _Py_CheckPython3(void);
 #endif
index 5fd21f5fa30a2b87798ac8807a241700e4c0a8c5..225e0602d191e1ae8d684131c06f4a46b18d9280 100644 (file)
@@ -17,7 +17,7 @@ PyAPI_FUNC(void) PySys_WriteStderr(const char *format, ...)
 PyAPI_FUNC(void) PySys_FormatStdout(const char *format, ...);
 PyAPI_FUNC(void) PySys_FormatStderr(const char *format, ...);
 
-PyAPI_FUNC(void) PySys_ResetWarnOptions(void);
+Py_DEPRECATED(3.13) PyAPI_FUNC(void) PySys_ResetWarnOptions(void);
 
 PyAPI_FUNC(PyObject *) PySys_GetXOptions(void);
 
diff --git a/Misc/NEWS.d/next/C API/2023-06-01-09-40-30.gh-issue-105145.WOOE-w.rst b/Misc/NEWS.d/next/C API/2023-06-01-09-40-30.gh-issue-105145.WOOE-w.rst
new file mode 100644 (file)
index 0000000..13dff76
--- /dev/null
@@ -0,0 +1,11 @@
+Deprecate old Python initialization functions:
+
+* :c:func:`PySys_ResetWarnOptions`
+* :c:func:`Py_GetExecPrefix`
+* :c:func:`Py_GetPath`
+* :c:func:`Py_GetPrefix`
+* :c:func:`Py_GetProgramFullPath`
+* :c:func:`Py_GetProgramName`
+* :c:func:`Py_GetPythonHome`
+
+Patch by Victor Stinner.
index 49c94447c7237cdc3a11965da376f7e4f9cb51c5..f06e624d4d50b0d8414905ecebbeaef92bf2dac0 100644 (file)
@@ -130,11 +130,10 @@ _get_tcl_lib_path(void)
     static int already_checked = 0;
 
     if (already_checked == 0) {
-        PyObject *prefix;
         struct stat stat_buf;
         int stat_return_value;
 
-        prefix = PyUnicode_FromWideChar(Py_GetPrefix(), -1);
+        PyObject *prefix = PySys_GetObject("prefix");  // borrowed reference
         if (prefix == NULL) {
             return NULL;
         }
@@ -3289,8 +3288,8 @@ PyInit__tkinter(void)
 
     /* This helps the dynamic loader; in Unicode aware Tcl versions
        it also helps Tcl find its encodings. */
-    uexe = PyUnicode_FromWideChar(Py_GetProgramName(), -1);
-    if (uexe) {
+    uexe = PySys_GetObject("executable");  // borrowed reference
+    if (uexe && PyUnicode_Check(uexe)) {   // sys.executable can be None
         cexe = PyUnicode_EncodeFSDefault(uexe);
         if (cexe) {
 #ifdef MS_WINDOWS
@@ -3329,7 +3328,6 @@ PyInit__tkinter(void)
 #endif /* MS_WINDOWS */
         }
         Py_XDECREF(cexe);
-        Py_DECREF(uexe);
     }
 
     if (PyErr_Occurred()) {