Skip to content

Commit

Permalink
pythongh-105145: Deprecate Py_GetPath() function
Browse files Browse the repository at this point in the history
Deprecate old Python initialization functions:

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

_tkinter uses sys.executable instead of Py_GetProgramName().
  • Loading branch information
vstinner committed Jun 1, 2023
1 parent 424049c commit 5306a2b
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 10 deletions.
18 changes: 18 additions & 0 deletions Doc/c-api/init.rst
Expand Up @@ -430,6 +430,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 :c:member:`PyConfig.program_name` or :data:`sys.executable` instead.


.. c:function:: wchar_t* Py_GetPrefix()
Expand All @@ -449,6 +452,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 :c:member:`PyConfig.prefix` or :data:`sys.prefix` instead.


.. c:function:: wchar_t* Py_GetExecPrefix()
Expand Down Expand Up @@ -490,6 +496,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 :c:member:`PyConfig.exec_prefix` or :data:`sys.exec_prefix` instead.


.. c:function:: wchar_t* Py_GetProgramFullPath()
Expand All @@ -508,6 +517,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 :c:member:`PyConfig.executable` or :data:`sys.executable` instead.


.. c:function:: wchar_t* Py_GetPath()
Expand All @@ -533,6 +545,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 :c:member:`PyConfig.module_search_paths` or :data:`sys.path` instead.


.. c:function:: const char* Py_GetVersion()
Expand Down Expand Up @@ -616,6 +631,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 :c:member:`PyConfig.home` instead.
.. _threads:
Expand Down
3 changes: 3 additions & 0 deletions Doc/c-api/sys.rst
Expand Up @@ -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 :c:member:`PyConfig.warnoptions` or :data:`sys.warnoptions` instead.
.. c:function:: void PySys_WriteStdout(const char *format, ...)
Write the output string described by *format* to :data:`sys.stdout`. No
Expand Down
12 changes: 12 additions & 0 deletions Doc/whatsnew/3.13.rst
Expand Up @@ -357,6 +357,18 @@ 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`
* :c:func:`Py_GetExecPrefix`
* :c:func:`Py_GetPath`
* :c:func:`Py_GetPrefix`
* :c:func:`Py_GetProgramFullPath`
* :c:func:`Py_GetProgramName`
* :c:func:`Py_GetPythonHome`

(Contributed by Victor Stinner in :gh:`105145`.)

Removed
-------

Expand Down
12 changes: 6 additions & 6 deletions Include/pylifecycle.h
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Include/sysmodule.h
Expand Up @@ -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);

Expand Down
@@ -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.
5 changes: 2 additions & 3 deletions Modules/_tkinter.c
Expand Up @@ -3289,8 +3289,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
Expand Down Expand Up @@ -3329,7 +3329,6 @@ PyInit__tkinter(void)
#endif /* MS_WINDOWS */
}
Py_XDECREF(cexe);
Py_DECREF(uexe);
}

if (PyErr_Occurred()) {
Expand Down

0 comments on commit 5306a2b

Please sign in to comment.