From c102f8dfffc22eb460510c3572184e29a164791d Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 27 Jan 2025 15:40:20 +0100 Subject: [PATCH 1/2] gh-129342: Explain how to replace Py_GetProgramName() in C --- Doc/c-api/init.rst | 27 ++++++++++++------ .../c-api-pending-removal-in-3.15.rst | 28 +++++++++++++------ 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst index dc44f3eaf87765..0f62e0b606b246 100644 --- a/Doc/c-api/init.rst +++ b/Doc/c-api/init.rst @@ -622,7 +622,8 @@ Process-wide parameters It now returns ``NULL`` if called before :c:func:`Py_Initialize`. .. deprecated-removed:: 3.13 3.15 - Get :data:`sys.executable` instead. + Use ``PySys_GetObject("executable")`` (:data:`sys.executable`) or + ``PyConfig_Get("executable")`` instead. .. c:function:: wchar_t* Py_GetPrefix() @@ -644,8 +645,11 @@ Process-wide parameters It now returns ``NULL`` if called before :c:func:`Py_Initialize`. .. deprecated-removed:: 3.13 3.15 - Get :data:`sys.base_prefix` instead, or :data:`sys.prefix` if - :ref:`virtual environments ` need to be handled. + Use ``PySys_GetObject("base_prefix")`` (:data:`sys.base_prefix`) or + ``PyConfig_Get("base_prefix")`` instead. Use + ``PySys_GetObject("prefix")`` (:data:`sys.prefix`) or + ``PyConfig_Get("prefix")`` if :ref:`virtual environments ` need + to be handled. .. c:function:: wchar_t* Py_GetExecPrefix() @@ -690,8 +694,11 @@ Process-wide parameters It now returns ``NULL`` if called before :c:func:`Py_Initialize`. .. deprecated-removed:: 3.13 3.15 - Get :data:`sys.base_exec_prefix` instead, or :data:`sys.exec_prefix` if - :ref:`virtual environments ` need to be handled. + Use ``PySys_GetObject("base_exec_prefix")`` + (:data:`sys.base_exec_prefix`) or ``PyConfig_Get("base_exec_prefix")`` + instead. Use ``PySys_GetObject("exec_prefix")`` (:data:`sys.exec_prefix`) + or ``PyConfig_Get("exec_prefix")`` if :ref:`virtual environments + ` need to be handled. .. c:function:: wchar_t* Py_GetProgramFullPath() @@ -712,7 +719,8 @@ Process-wide parameters It now returns ``NULL`` if called before :c:func:`Py_Initialize`. .. deprecated-removed:: 3.13 3.15 - Get :data:`sys.executable` instead. + Use ``PySys_GetObject("executable")`` (:data:`sys.executable`) or + ``PyConfig_Get("executable")`` instead. .. c:function:: wchar_t* Py_GetPath() @@ -740,7 +748,8 @@ Process-wide parameters It now returns ``NULL`` if called before :c:func:`Py_Initialize`. .. deprecated-removed:: 3.13 3.15 - Get :data:`sys.path` instead. + Use ``PySys_GetObject("path")`` (:data:`sys.path`) + or ``PyConfig_Get("module_search_paths")`` instead. .. c:function:: const char* Py_GetVersion() @@ -926,8 +935,8 @@ Process-wide parameters 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. + Use :c:func:`PyConfig_Get("home") ` + or the :envvar:`PYTHONHOME` environment variable instead. .. _threads: diff --git a/Doc/deprecations/c-api-pending-removal-in-3.15.rst b/Doc/deprecations/c-api-pending-removal-in-3.15.rst index ac31b3cc8cd451..aae206ff381889 100644 --- a/Doc/deprecations/c-api-pending-removal-in-3.15.rst +++ b/Doc/deprecations/c-api-pending-removal-in-3.15.rst @@ -10,22 +10,30 @@ Pending removal in Python 3.15 :c:func:`PyWeakref_GetRef` on Python 3.12 and older. * :c:type:`Py_UNICODE` type and the :c:macro:`!Py_UNICODE_WIDE` macro: Use :c:type:`wchar_t` instead. -* Python initialization functions: +* Python initialization functions, deprecated in Python 3.13: - * :c:func:`PySys_ResetWarnOptions`: - Clear :data:`sys.warnoptions` and :data:`!warnings.filters` instead. * :c:func:`Py_GetExecPrefix`: - Get :data:`sys.base_exec_prefix` and :data:`sys.exec_prefix` instead. + Use ``PySys_GetObject("base_exec_prefix")`` (:data:`sys.base_exec_prefix`) + or ``PyConfig_Get("base_exec_prefix")`` instead. Use + ``PySys_GetObject("exec_prefix")`` (:data:`sys.exec_prefix`) or + ``PyConfig_Get("exec_prefix")`` if :ref:`virtual environments ` + need to be handled. * :c:func:`Py_GetPath`: - Get :data:`sys.path` instead. + Use ``PySys_GetObject("path")`` (:data:`sys.path`) + or ``PyConfig_Get("module_search_paths")`` instead. * :c:func:`Py_GetPrefix`: - Get :data:`sys.base_prefix` and :data:`sys.prefix` instead. + Use ``PySys_GetObject("base_prefix")`` (:data:`sys.base_prefix`) or + ``PyConfig_Get("base_prefix")`` instead. Use ``PySys_GetObject("prefix")`` + (:data:`sys.prefix`) or ``PyConfig_Get("prefix")`` if :ref:`virtual + environments ` need to be handled. * :c:func:`Py_GetProgramFullPath`: - Get :data:`sys.executable` instead. + Use ``PySys_GetObject("executable")`` (:data:`sys.executable`) + or ``PyConfig_Get("executable")`` instead. * :c:func:`Py_GetProgramName`: - Get :data:`sys.executable` instead. + Use ``PySys_GetObject("executable")`` (:data:`sys.executable`) + or ``PyConfig_Get("executable")`` instead. * :c:func:`Py_GetPythonHome`: - Get :c:func:`PyConfig_Get("home") ` + Use :c:func:`PyConfig_Get("home") ` or the :envvar:`PYTHONHOME` environment variable instead. See also the :c:func:`PyConfig_Get` function. @@ -40,6 +48,8 @@ Pending removal in Python 3.15 Set :c:member:`PyConfig.program_name` instead. * :c:func:`!Py_SetPythonHome()`: Set :c:member:`PyConfig.home` instead. + * :c:func:`PySys_ResetWarnOptions`: + Clear :data:`sys.warnoptions` and :data:`!warnings.filters` instead. The :c:func:`Py_InitializeFromConfig` API should be used with :c:type:`PyConfig` instead. From e7de63ceb4405982abd373229b2589cf56868602 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 28 Jan 2025 12:51:28 +0100 Subject: [PATCH 2/2] Remove PySys_GetObject() --- Doc/c-api/init.rst | 37 ++++++++--------- .../c-api-pending-removal-in-3.15.rst | 40 ++++++++++--------- 2 files changed, 38 insertions(+), 39 deletions(-) diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst index 0f62e0b606b246..8e3be97dfeefd1 100644 --- a/Doc/c-api/init.rst +++ b/Doc/c-api/init.rst @@ -622,8 +622,8 @@ Process-wide parameters It now returns ``NULL`` if called before :c:func:`Py_Initialize`. .. deprecated-removed:: 3.13 3.15 - Use ``PySys_GetObject("executable")`` (:data:`sys.executable`) or - ``PyConfig_Get("executable")`` instead. + Use :c:func:`PyConfig_Get("executable") ` + (:data:`sys.executable`) instead. .. c:function:: wchar_t* Py_GetPrefix() @@ -645,11 +645,10 @@ Process-wide parameters It now returns ``NULL`` if called before :c:func:`Py_Initialize`. .. deprecated-removed:: 3.13 3.15 - Use ``PySys_GetObject("base_prefix")`` (:data:`sys.base_prefix`) or - ``PyConfig_Get("base_prefix")`` instead. Use - ``PySys_GetObject("prefix")`` (:data:`sys.prefix`) or - ``PyConfig_Get("prefix")`` if :ref:`virtual environments ` need - to be handled. + Use :c:func:`PyConfig_Get("base_prefix") ` + (:data:`sys.base_prefix`) instead. Use :c:func:`PyConfig_Get("prefix") + ` (:data:`sys.prefix`) if :ref:`virtual environments + ` need to be handled. .. c:function:: wchar_t* Py_GetExecPrefix() @@ -694,12 +693,11 @@ Process-wide parameters It now returns ``NULL`` if called before :c:func:`Py_Initialize`. .. deprecated-removed:: 3.13 3.15 - Use ``PySys_GetObject("base_exec_prefix")`` - (:data:`sys.base_exec_prefix`) or ``PyConfig_Get("base_exec_prefix")`` - instead. Use ``PySys_GetObject("exec_prefix")`` (:data:`sys.exec_prefix`) - or ``PyConfig_Get("exec_prefix")`` if :ref:`virtual environments - ` need to be handled. - + Use :c:func:`PyConfig_Get("base_exec_prefix") ` + (:data:`sys.base_exec_prefix`) instead. Use + :c:func:`PyConfig_Get("exec_prefix") ` + (:data:`sys.exec_prefix`) if :ref:`virtual environments ` need + to be handled. .. c:function:: wchar_t* Py_GetProgramFullPath() @@ -719,8 +717,8 @@ Process-wide parameters It now returns ``NULL`` if called before :c:func:`Py_Initialize`. .. deprecated-removed:: 3.13 3.15 - Use ``PySys_GetObject("executable")`` (:data:`sys.executable`) or - ``PyConfig_Get("executable")`` instead. + Use :c:func:`PyConfig_Get("executable") ` + (:data:`sys.executable`) instead. .. c:function:: wchar_t* Py_GetPath() @@ -748,9 +746,8 @@ Process-wide parameters It now returns ``NULL`` if called before :c:func:`Py_Initialize`. .. deprecated-removed:: 3.13 3.15 - Use ``PySys_GetObject("path")`` (:data:`sys.path`) - or ``PyConfig_Get("module_search_paths")`` instead. - + Use :c:func:`PyConfig_Get("module_search_paths") ` + (:data:`sys.path`) instead. .. c:function:: const char* Py_GetVersion() @@ -935,8 +932,8 @@ Process-wide parameters It now returns ``NULL`` if called before :c:func:`Py_Initialize`. .. deprecated-removed:: 3.13 3.15 - Use :c:func:`PyConfig_Get("home") ` - or the :envvar:`PYTHONHOME` environment variable instead. + Use :c:func:`PyConfig_Get("home") ` or the + :envvar:`PYTHONHOME` environment variable instead. .. _threads: diff --git a/Doc/deprecations/c-api-pending-removal-in-3.15.rst b/Doc/deprecations/c-api-pending-removal-in-3.15.rst index aae206ff381889..666a1622dd0b29 100644 --- a/Doc/deprecations/c-api-pending-removal-in-3.15.rst +++ b/Doc/deprecations/c-api-pending-removal-in-3.15.rst @@ -12,31 +12,33 @@ Pending removal in Python 3.15 Use :c:type:`wchar_t` instead. * Python initialization functions, deprecated in Python 3.13: - * :c:func:`Py_GetExecPrefix`: - Use ``PySys_GetObject("base_exec_prefix")`` (:data:`sys.base_exec_prefix`) - or ``PyConfig_Get("base_exec_prefix")`` instead. Use - ``PySys_GetObject("exec_prefix")`` (:data:`sys.exec_prefix`) or - ``PyConfig_Get("exec_prefix")`` if :ref:`virtual environments ` - need to be handled. * :c:func:`Py_GetPath`: - Use ``PySys_GetObject("path")`` (:data:`sys.path`) - or ``PyConfig_Get("module_search_paths")`` instead. + Use :c:func:`PyConfig_Get("module_search_paths") ` + (:data:`sys.path`) instead. * :c:func:`Py_GetPrefix`: - Use ``PySys_GetObject("base_prefix")`` (:data:`sys.base_prefix`) or - ``PyConfig_Get("base_prefix")`` instead. Use ``PySys_GetObject("prefix")`` - (:data:`sys.prefix`) or ``PyConfig_Get("prefix")`` if :ref:`virtual - environments ` need to be handled. + Use :c:func:`PyConfig_Get("base_prefix") ` + (:data:`sys.base_prefix`) instead. Use :c:func:`PyConfig_Get("prefix") + ` (:data:`sys.prefix`) if :ref:`virtual environments + ` need to be handled. + * :c:func:`Py_GetExecPrefix`: + Use :c:func:`PyConfig_Get("base_exec_prefix") ` + (:data:`sys.base_exec_prefix`) instead. Use + :c:func:`PyConfig_Get("exec_prefix") ` + (:data:`sys.exec_prefix`) if :ref:`virtual environments ` need to + be handled. * :c:func:`Py_GetProgramFullPath`: - Use ``PySys_GetObject("executable")`` (:data:`sys.executable`) - or ``PyConfig_Get("executable")`` instead. + Use :c:func:`PyConfig_Get("executable") ` + (:data:`sys.executable`) instead. * :c:func:`Py_GetProgramName`: - Use ``PySys_GetObject("executable")`` (:data:`sys.executable`) - or ``PyConfig_Get("executable")`` instead. + Use :c:func:`PyConfig_Get("executable") ` + (:data:`sys.executable`) instead. * :c:func:`Py_GetPythonHome`: - Use :c:func:`PyConfig_Get("home") ` - or the :envvar:`PYTHONHOME` environment variable instead. + Use :c:func:`PyConfig_Get("home") ` or the + :envvar:`PYTHONHOME` environment variable instead. - See also the :c:func:`PyConfig_Get` function. + The `pythoncapi-compat project + `__ can be used to get + :c:func:`PyConfig_Get` on Python 3.13 and older. * Functions to configure Python's initialization, deprecated in Python 3.11: