From 05a7da45d472165c967f9501ba84c4013733e3e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 8 May 2025 12:56:49 +0200 Subject: [PATCH 01/17] remove `Py_GetProgramName` --- Doc/c-api/init.rst | 20 +------------------ Doc/data/refcounts.dat | 2 -- Doc/data/stable_abi.dat | 1 - .../c-api-pending-removal-in-3.15.rst | 3 --- Doc/whatsnew/3.10.rst | 2 +- Doc/whatsnew/3.13.rst | 2 +- Doc/whatsnew/3.15.rst | 4 ++++ Doc/whatsnew/3.8.rst | 2 +- Include/pylifecycle.h | 1 - Lib/test/test_embed.py | 3 --- Lib/test/test_stable_abi_ctypes.py | 1 - Misc/NEWS.d/3.10.0a3.rst | 2 +- Misc/NEWS.d/3.13.0a1.rst | 2 +- Misc/NEWS.d/3.9.0a1.rst | 2 +- Misc/stable_abi.toml | 2 -- PC/python3dll.c | 1 - Python/pathconfig.c | 8 -------- 17 files changed, 11 insertions(+), 47 deletions(-) diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst index 52f64a61006b74..ff4fbbcfa2351b 100644 --- a/Doc/c-api/init.rst +++ b/Doc/c-api/init.rst @@ -79,8 +79,7 @@ The following functions can be safely called before Python is initialized: the following functions **should not be called** before the interpreter has been initialized: :c:func:`Py_EncodeLocale`, :c:func:`Py_GetPath`, :c:func:`Py_GetPrefix`, :c:func:`Py_GetExecPrefix`, - :c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome`, - :c:func:`Py_GetProgramName`, :c:func:`PyEval_InitThreads`, and + :c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome`, :c:func:`PyEval_InitThreads`, and :c:func:`Py_RunMain`. @@ -609,23 +608,6 @@ Process-wide parameters .. deprecated-removed:: 3.11 3.15 -.. c:function:: wchar_t* Py_GetProgramName() - - Return the program name set with :c:member:`PyConfig.program_name`, or the default. - The returned string points into static storage; the caller should not modify its - value. - - This function should not be called before :c:func:`Py_Initialize`, otherwise - it returns ``NULL``. - - .. versionchanged:: 3.10 - It now returns ``NULL`` if called before :c:func:`Py_Initialize`. - - .. deprecated-removed:: 3.13 3.15 - Use :c:func:`PyConfig_Get("executable") ` - (:data:`sys.executable`) instead. - - .. c:function:: wchar_t* Py_GetPrefix() Return the *prefix* for installed platform-independent files. This is derived diff --git a/Doc/data/refcounts.dat b/Doc/data/refcounts.dat index ca99b9e6d37141..ee38d07d86724a 100644 --- a/Doc/data/refcounts.dat +++ b/Doc/data/refcounts.dat @@ -3017,8 +3017,6 @@ Py_GetPrefix:wchar_t*::: Py_GetProgramFullPath:wchar_t*::: -Py_GetProgramName:wchar_t*::: - Py_GetVersion:const char*::: Py_INCREF:void::: diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat index 3d68487d07baf2..69a2940b8dd9a9 100644 --- a/Doc/data/stable_abi.dat +++ b/Doc/data/stable_abi.dat @@ -867,7 +867,6 @@ func,Py_GetPath,3.2,, func,Py_GetPlatform,3.2,, func,Py_GetPrefix,3.2,, func,Py_GetProgramFullPath,3.2,, -func,Py_GetProgramName,3.2,, func,Py_GetPythonHome,3.2,, func,Py_GetRecursionLimit,3.2,, func,Py_GetVersion,3.2,, 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 a5cc8f1d5b3475..2e08f51221c2ca 100644 --- a/Doc/deprecations/c-api-pending-removal-in-3.15.rst +++ b/Doc/deprecations/c-api-pending-removal-in-3.15.rst @@ -39,9 +39,6 @@ Pending removal in Python 3.15 * :c:func:`Py_GetProgramFullPath`: Use :c:func:`PyConfig_Get("executable") ` (:data:`sys.executable`) instead. - * :c:func:`Py_GetProgramName`: - 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. diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index 3c815721a92f8c..d8b70ba3e20c93 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -2178,7 +2178,7 @@ Porting to Python 3.10 * :c:func:`Py_GetPath`, :c:func:`Py_GetPrefix`, :c:func:`Py_GetExecPrefix`, :c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome` and - :c:func:`Py_GetProgramName` functions now return ``NULL`` if called before + :c:func:`!Py_GetProgramName` functions now return ``NULL`` if called before :c:func:`Py_Initialize` (before Python is initialized). Use the new :ref:`init-config` API to get the :ref:`init-path-config`. (Contributed by Victor Stinner in :issue:`42260`.) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index e20e49325c01d5..83dab10999143e 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -2485,7 +2485,7 @@ Deprecated C APIs Get :data:`sys.prefix` instead. * :c:func:`Py_GetProgramFullPath`: Get :data:`sys.executable` instead. - * :c:func:`Py_GetProgramName`: + * :c:func:`!Py_GetProgramName`: Get :data:`sys.executable` instead. * :c:func:`Py_GetPythonHome`: Get :c:member:`PyConfig.home` diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 5e9922069aa42c..4d60b80ff24035 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -155,3 +155,7 @@ Deprecated C APIs Removed C APIs -------------- +* :c:func:`!Py_GetProgramName`: + use :c:func:`PyConfig_Get("executable") ` + (:data:`sys.executable`) instead. + diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst index 7aca35b2959cd2..7cf8999bd0d664 100644 --- a/Doc/whatsnew/3.8.rst +++ b/Doc/whatsnew/3.8.rst @@ -1630,7 +1630,7 @@ Build and C API Changes * :c:func:`!Py_SetPath` now sets :data:`sys.executable` to the program full path (:c:func:`Py_GetProgramFullPath`) rather than to the program name - (:c:func:`Py_GetProgramName`). + (:c:func:`!Py_GetProgramName`). (Contributed by Victor Stinner in :issue:`38234`.) diff --git a/Include/pylifecycle.h b/Include/pylifecycle.h index de1bcb1d2cb632..0dca02c1de13a8 100644 --- a/Include/pylifecycle.h +++ b/Include/pylifecycle.h @@ -35,7 +35,6 @@ PyAPI_FUNC(int) Py_BytesMain(int argc, char **argv); /* In pathconfig.c */ Py_DEPRECATED(3.11) PyAPI_FUNC(void) Py_SetProgramName(const wchar_t *); -Py_DEPRECATED(3.13) PyAPI_FUNC(wchar_t *) Py_GetProgramName(void); Py_DEPRECATED(3.11) PyAPI_FUNC(void) Py_SetPythonHome(const wchar_t *); Py_DEPRECATED(3.13) PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void); diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 95b2d80464c349..e05a26776d3722 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1712,7 +1712,6 @@ def test_global_pathconfig(self): # - Py_GetPath() # - Py_GetPrefix() # - Py_GetProgramFullPath() - # - Py_GetProgramName() # - Py_GetPythonHome() # # The global path configuration (_Py_path_config) must be a copy @@ -1728,7 +1727,6 @@ def get_func(name): Py_GetPath = get_func('Py_GetPath') Py_GetPrefix = get_func('Py_GetPrefix') Py_GetExecPrefix = get_func('Py_GetExecPrefix') - Py_GetProgramName = get_func('Py_GetProgramName') Py_GetProgramFullPath = get_func('Py_GetProgramFullPath') Py_GetPythonHome = get_func('Py_GetPythonHome') @@ -1738,7 +1736,6 @@ def get_func(name): config['module_search_paths']) self.assertEqual(Py_GetPrefix(), config['prefix']) self.assertEqual(Py_GetExecPrefix(), config['exec_prefix']) - self.assertEqual(Py_GetProgramName(), config['program_name']) self.assertEqual(Py_GetProgramFullPath(), config['executable']) self.assertEqual(Py_GetPythonHome(), config['home']) diff --git a/Lib/test/test_stable_abi_ctypes.py b/Lib/test/test_stable_abi_ctypes.py index 1e6f69d49e9335..2d2a6259e18f50 100644 --- a/Lib/test/test_stable_abi_ctypes.py +++ b/Lib/test/test_stable_abi_ctypes.py @@ -885,7 +885,6 @@ def test_windows_feature_macros(self): "Py_GetPlatform", "Py_GetPrefix", "Py_GetProgramFullPath", - "Py_GetProgramName", "Py_GetPythonHome", "Py_GetRecursionLimit", "Py_GetVersion", diff --git a/Misc/NEWS.d/3.10.0a3.rst b/Misc/NEWS.d/3.10.0a3.rst index 33c3e14b7a4bcf..a9e7ac562e3f9c 100644 --- a/Misc/NEWS.d/3.10.0a3.rst +++ b/Misc/NEWS.d/3.10.0a3.rst @@ -1397,7 +1397,7 @@ but now can get the condition by calling the new private :c:func:`Py_GetPath`, :c:func:`Py_GetPrefix`, :c:func:`Py_GetExecPrefix`, :c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome` and -:c:func:`Py_GetProgramName` functions now return ``NULL`` if called before +:c:func:`!Py_GetProgramName` functions now return ``NULL`` if called before :c:func:`Py_Initialize` (before Python is initialized). Use the new :ref:`Python Initialization Configuration API ` to get the :ref:`Python Path Configuration. `. Patch by Victor diff --git a/Misc/NEWS.d/3.13.0a1.rst b/Misc/NEWS.d/3.13.0a1.rst index 91e9fee7e37437..4571911fb7bda0 100644 --- a/Misc/NEWS.d/3.13.0a1.rst +++ b/Misc/NEWS.d/3.13.0a1.rst @@ -6597,7 +6597,7 @@ Deprecate old Python initialization functions: * :c:func:`Py_GetPath` * :c:func:`Py_GetPrefix` * :c:func:`Py_GetProgramFullPath` -* :c:func:`Py_GetProgramName` +* :c:func:`!Py_GetProgramName` * :c:func:`Py_GetPythonHome` Patch by Victor Stinner. diff --git a/Misc/NEWS.d/3.9.0a1.rst b/Misc/NEWS.d/3.9.0a1.rst index d75132b0aac040..ee993c722f8806 100644 --- a/Misc/NEWS.d/3.9.0a1.rst +++ b/Misc/NEWS.d/3.9.0a1.rst @@ -5537,7 +5537,7 @@ Tyler Kieft. :c:func:`!Py_SetPath` now sets :data:`sys.executable` to the program full path (:c:func:`Py_GetProgramFullPath`) rather than to the program name -(:c:func:`Py_GetProgramName`). +(:c:func:`!Py_GetProgramName`). .. diff --git a/Misc/stable_abi.toml b/Misc/stable_abi.toml index d3e1f0db057023..e91e86e61df246 100644 --- a/Misc/stable_abi.toml +++ b/Misc/stable_abi.toml @@ -1640,8 +1640,6 @@ added = '3.2' [function.Py_GetProgramFullPath] added = '3.2' -[function.Py_GetProgramName] - added = '3.2' [function.Py_GetPythonHome] added = '3.2' [function.Py_GetRecursionLimit] diff --git a/PC/python3dll.c b/PC/python3dll.c index f0c578e11c643b..40af9acebda386 100755 --- a/PC/python3dll.c +++ b/PC/python3dll.c @@ -63,7 +63,6 @@ EXPORT_FUNC(Py_GetPath) EXPORT_FUNC(Py_GetPlatform) EXPORT_FUNC(Py_GetPrefix) EXPORT_FUNC(Py_GetProgramFullPath) -EXPORT_FUNC(Py_GetProgramName) EXPORT_FUNC(Py_GetPythonHome) EXPORT_FUNC(Py_GetRecursionLimit) EXPORT_FUNC(Py_GetVersion) diff --git a/Python/pathconfig.c b/Python/pathconfig.c index 92360c1bb02420..28b595dec4fbf7 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -323,14 +323,6 @@ Py_GetPythonHome(void) } -wchar_t * -Py_GetProgramName(void) -{ - return _Py_path_config.program_name; -} - - - /* Compute module search path from argv[0] or the current working directory ("-m module" case) which will be prepended to sys.argv: sys.path[0]. From 4e74756796206349cee4ba4754c7de9e3d460cc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 8 May 2025 12:59:04 +0200 Subject: [PATCH 02/17] remove `Py_GetExecPrefix` --- Doc/c-api/init.rst | 51 +------------------ Doc/c-api/intro.rst | 3 +- Doc/data/refcounts.dat | 2 - Doc/data/stable_abi.dat | 1 - .../c-api-pending-removal-in-3.15.rst | 6 --- Doc/whatsnew/3.10.rst | 2 +- Doc/whatsnew/3.13.rst | 2 +- Doc/whatsnew/3.15.rst | 7 ++- Include/pylifecycle.h | 1 - Lib/test/test_embed.py | 3 -- Lib/test/test_stable_abi_ctypes.py | 1 - Misc/NEWS.d/3.10.0a3.rst | 2 +- Misc/NEWS.d/3.13.0a1.rst | 2 +- Misc/stable_abi.toml | 2 - PC/python3dll.c | 1 - Python/pathconfig.c | 7 --- 16 files changed, 12 insertions(+), 81 deletions(-) diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst index ff4fbbcfa2351b..c11a4591d71287 100644 --- a/Doc/c-api/init.rst +++ b/Doc/c-api/init.rst @@ -78,8 +78,7 @@ The following functions can be safely called before Python is initialized: Despite their apparent similarity to some of the functions listed above, the following functions **should not be called** before the interpreter has been initialized: :c:func:`Py_EncodeLocale`, :c:func:`Py_GetPath`, - :c:func:`Py_GetPrefix`, :c:func:`Py_GetExecPrefix`, - :c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome`, :c:func:`PyEval_InitThreads`, and + :c:func:`Py_GetPrefix`, :c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome`, :c:func:`PyEval_InitThreads`, and :c:func:`Py_RunMain`. @@ -633,54 +632,6 @@ Process-wide parameters ` need to be handled. -.. c:function:: wchar_t* Py_GetExecPrefix() - - Return the *exec-prefix* for installed platform-*dependent* files. This is - derived through a number of complicated rules from the program name set with - :c:member:`PyConfig.program_name` and some environment variables; for example, if the - program name is ``'/usr/local/bin/python'``, the exec-prefix is - ``'/usr/local'``. The returned string points into static storage; the caller - should not modify its value. This corresponds to the :makevar:`exec_prefix` - variable in the top-level :file:`Makefile` and the ``--exec-prefix`` - argument to the :program:`configure` script at build time. The value is - available to Python code as ``sys.base_exec_prefix``. It is only useful on - Unix. - - Background: The exec-prefix differs from the prefix when platform dependent - files (such as executables and shared libraries) are installed in a different - directory tree. In a typical installation, platform dependent files may be - installed in the :file:`/usr/local/plat` subtree while platform independent may - be installed in :file:`/usr/local`. - - Generally speaking, a platform is a combination of hardware and software - families, e.g. Sparc machines running the Solaris 2.x operating system are - considered the same platform, but Intel machines running Solaris 2.x are another - platform, and Intel machines running Linux are yet another platform. Different - major revisions of the same operating system generally also form different - platforms. Non-Unix operating systems are a different story; the installation - strategies on those systems are so different that the prefix and exec-prefix are - meaningless, and set to the empty string. Note that compiled Python bytecode - files are platform independent (but not independent from the Python version by - which they were compiled!). - - System administrators will know how to configure the :program:`mount` or - :program:`automount` programs to share :file:`/usr/local` between platforms - while having :file:`/usr/local/plat` be a different filesystem for each - platform. - - This function should not be called before :c:func:`Py_Initialize`, otherwise - it returns ``NULL``. - - .. versionchanged:: 3.10 - It now returns ``NULL`` if called before :c:func:`Py_Initialize`. - - .. deprecated-removed:: 3.13 3.15 - 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() .. index:: diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index c8c60eb9f48f45..9ff2196897bdcf 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -782,7 +782,6 @@ front of the standard path by setting :envvar:`PYTHONPATH`. .. index:: single: Py_GetPath (C function) single: Py_GetPrefix (C function) - single: Py_GetExecPrefix (C function) single: Py_GetProgramFullPath (C function) The embedding application can steer the search by setting @@ -791,7 +790,7 @@ The embedding application can steer the search by setting :envvar:`PYTHONHOME` still overrides this and :envvar:`PYTHONPATH` is still inserted in front of the standard path. An application that requires total control has to provide its own implementation of :c:func:`Py_GetPath`, -:c:func:`Py_GetPrefix`, :c:func:`Py_GetExecPrefix`, and +:c:func:`Py_GetPrefix`, and :c:func:`Py_GetProgramFullPath` (all defined in :file:`Modules/getpath.c`). .. index:: single: Py_IsInitialized (C function) diff --git a/Doc/data/refcounts.dat b/Doc/data/refcounts.dat index ee38d07d86724a..8db77d2545ccb5 100644 --- a/Doc/data/refcounts.dat +++ b/Doc/data/refcounts.dat @@ -3007,8 +3007,6 @@ Py_GetCompiler:const char*::: Py_GetCopyright:const char*::: -Py_GetExecPrefix:wchar_t*::: - Py_GetPath:wchar_t*::: Py_GetPlatform:const char*::: diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat index 69a2940b8dd9a9..fdf3ca3e3b15cc 100644 --- a/Doc/data/stable_abi.dat +++ b/Doc/data/stable_abi.dat @@ -862,7 +862,6 @@ func,Py_GetCompiler,3.2,, func,Py_GetConstant,3.13,, func,Py_GetConstantBorrowed,3.13,, func,Py_GetCopyright,3.2,, -func,Py_GetExecPrefix,3.2,, func,Py_GetPath,3.2,, func,Py_GetPlatform,3.2,, func,Py_GetPrefix,3.2,, 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 2e08f51221c2ca..2139ce84b7497a 100644 --- a/Doc/deprecations/c-api-pending-removal-in-3.15.rst +++ b/Doc/deprecations/c-api-pending-removal-in-3.15.rst @@ -30,12 +30,6 @@ Pending removal in Python 3.15 (: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 :c:func:`PyConfig_Get("executable") ` (:data:`sys.executable`) instead. diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index d8b70ba3e20c93..5707105fa86c87 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -2176,7 +2176,7 @@ Porting to Python 3.10 ``unicodedata.ucnhash_CAPI`` has been moved to the internal C API. (Contributed by Victor Stinner in :issue:`42157`.) -* :c:func:`Py_GetPath`, :c:func:`Py_GetPrefix`, :c:func:`Py_GetExecPrefix`, +* :c:func:`Py_GetPath`, :c:func:`Py_GetPrefix`, :c:func:`!Py_GetExecPrefix`, :c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome` and :c:func:`!Py_GetProgramName` functions now return ``NULL`` if called before :c:func:`Py_Initialize` (before Python is initialized). Use the new diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 83dab10999143e..c4f3da3c5a88b2 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -2477,7 +2477,7 @@ Deprecated C APIs * :c:func:`PySys_ResetWarnOptions`: Clear :data:`sys.warnoptions` and :data:`!warnings.filters` instead. - * :c:func:`Py_GetExecPrefix`: + * :c:func:`!Py_GetExecPrefix`: Get :data:`sys.exec_prefix` instead. * :c:func:`Py_GetPath`: Get :data:`sys.path` instead. diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 4d60b80ff24035..e4e2f79731f4e7 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -155,7 +155,12 @@ Deprecated C APIs Removed C APIs -------------- +* :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_GetProgramName`: use :c:func:`PyConfig_Get("executable") ` (:data:`sys.executable`) instead. - diff --git a/Include/pylifecycle.h b/Include/pylifecycle.h index 0dca02c1de13a8..d84995d93f664f 100644 --- a/Include/pylifecycle.h +++ b/Include/pylifecycle.h @@ -41,7 +41,6 @@ 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); diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index e05a26776d3722..2e23b236a4103e 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1708,7 +1708,6 @@ def test_getpath_abspath_win32(self): def test_global_pathconfig(self): # Test C API functions getting the path configuration: # - # - Py_GetExecPrefix() # - Py_GetPath() # - Py_GetPrefix() # - Py_GetProgramFullPath() @@ -1726,7 +1725,6 @@ def get_func(name): Py_GetPath = get_func('Py_GetPath') Py_GetPrefix = get_func('Py_GetPrefix') - Py_GetExecPrefix = get_func('Py_GetExecPrefix') Py_GetProgramFullPath = get_func('Py_GetProgramFullPath') Py_GetPythonHome = get_func('Py_GetPythonHome') @@ -1735,7 +1733,6 @@ def get_func(name): self.assertEqual(tuple(Py_GetPath().split(os.path.pathsep)), config['module_search_paths']) self.assertEqual(Py_GetPrefix(), config['prefix']) - self.assertEqual(Py_GetExecPrefix(), config['exec_prefix']) self.assertEqual(Py_GetProgramFullPath(), config['executable']) self.assertEqual(Py_GetPythonHome(), config['home']) diff --git a/Lib/test/test_stable_abi_ctypes.py b/Lib/test/test_stable_abi_ctypes.py index 2d2a6259e18f50..54a6191dfac757 100644 --- a/Lib/test/test_stable_abi_ctypes.py +++ b/Lib/test/test_stable_abi_ctypes.py @@ -880,7 +880,6 @@ def test_windows_feature_macros(self): "Py_GetConstant", "Py_GetConstantBorrowed", "Py_GetCopyright", - "Py_GetExecPrefix", "Py_GetPath", "Py_GetPlatform", "Py_GetPrefix", diff --git a/Misc/NEWS.d/3.10.0a3.rst b/Misc/NEWS.d/3.10.0a3.rst index a9e7ac562e3f9c..9aa9bcfa57827c 100644 --- a/Misc/NEWS.d/3.10.0a3.rst +++ b/Misc/NEWS.d/3.10.0a3.rst @@ -1395,7 +1395,7 @@ but now can get the condition by calling the new private .. nonce: -Br3Co .. section: C API -:c:func:`Py_GetPath`, :c:func:`Py_GetPrefix`, :c:func:`Py_GetExecPrefix`, +:c:func:`Py_GetPath`, :c:func:`Py_GetPrefix`, :c:func:`!Py_GetExecPrefix`, :c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome` and :c:func:`!Py_GetProgramName` functions now return ``NULL`` if called before :c:func:`Py_Initialize` (before Python is initialized). Use the new diff --git a/Misc/NEWS.d/3.13.0a1.rst b/Misc/NEWS.d/3.13.0a1.rst index 4571911fb7bda0..7017cb2ea98b21 100644 --- a/Misc/NEWS.d/3.13.0a1.rst +++ b/Misc/NEWS.d/3.13.0a1.rst @@ -6593,7 +6593,7 @@ functions, deprecated in Python 3.9. Patch by Victor Stinner. Deprecate old Python initialization functions: * :c:func:`PySys_ResetWarnOptions` -* :c:func:`Py_GetExecPrefix` +* :c:func:`!Py_GetExecPrefix` * :c:func:`Py_GetPath` * :c:func:`Py_GetPrefix` * :c:func:`Py_GetProgramFullPath` diff --git a/Misc/stable_abi.toml b/Misc/stable_abi.toml index e91e86e61df246..b8c6057153707a 100644 --- a/Misc/stable_abi.toml +++ b/Misc/stable_abi.toml @@ -1630,8 +1630,6 @@ added = '3.2' [function.Py_GetCopyright] added = '3.2' -[function.Py_GetExecPrefix] - added = '3.2' [function.Py_GetPath] added = '3.2' [function.Py_GetPlatform] diff --git a/PC/python3dll.c b/PC/python3dll.c index 40af9acebda386..dfc983bb3d851b 100755 --- a/PC/python3dll.c +++ b/PC/python3dll.c @@ -58,7 +58,6 @@ EXPORT_FUNC(Py_GetCompiler) EXPORT_FUNC(Py_GetConstant) EXPORT_FUNC(Py_GetConstantBorrowed) EXPORT_FUNC(Py_GetCopyright) -EXPORT_FUNC(Py_GetExecPrefix) EXPORT_FUNC(Py_GetPath) EXPORT_FUNC(Py_GetPlatform) EXPORT_FUNC(Py_GetPrefix) diff --git a/Python/pathconfig.c b/Python/pathconfig.c index 28b595dec4fbf7..ccab53ed33cff2 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -302,13 +302,6 @@ Py_GetPrefix(void) } -wchar_t * -Py_GetExecPrefix(void) -{ - return _Py_path_config.exec_prefix; -} - - wchar_t * Py_GetProgramFullPath(void) { From 5304e49955d475689b86248119eed17570ec5755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 8 May 2025 13:04:15 +0200 Subject: [PATCH 03/17] remove `Py_GetPath` --- Doc/c-api/init.rst | 37 +------------------ Doc/c-api/intro.rst | 4 +- Doc/data/refcounts.dat | 2 - Doc/data/stable_abi.dat | 1 - .../c-api-pending-removal-in-3.15.rst | 3 -- Doc/whatsnew/3.10.rst | 2 +- Doc/whatsnew/3.13.rst | 2 +- Doc/whatsnew/3.15.rst | 3 ++ Include/pylifecycle.h | 1 - Lib/test/test_embed.py | 4 -- Lib/test/test_inspect/test_inspect.py | 6 ++- Lib/test/test_repl.py | 4 +- Lib/test/test_stable_abi_ctypes.py | 1 - Misc/NEWS.d/3.10.0a3.rst | 2 +- Misc/NEWS.d/3.13.0a1.rst | 2 +- Misc/stable_abi.toml | 2 - PC/python3dll.c | 1 - Python/pathconfig.c | 12 ------ 18 files changed, 16 insertions(+), 73 deletions(-) diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst index c11a4591d71287..410cc03201aadf 100644 --- a/Doc/c-api/init.rst +++ b/Doc/c-api/init.rst @@ -77,8 +77,7 @@ The following functions can be safely called before Python is initialized: Despite their apparent similarity to some of the functions listed above, the following functions **should not be called** before the interpreter has - been initialized: :c:func:`Py_EncodeLocale`, :c:func:`Py_GetPath`, - :c:func:`Py_GetPrefix`, :c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome`, :c:func:`PyEval_InitThreads`, and + been initialized: :c:func:`Py_EncodeLocale`, :c:func:`Py_GetPrefix`, :c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome`, :c:func:`PyEval_InitThreads`, and :c:func:`Py_RunMain`. @@ -143,9 +142,6 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2. :c:member:`PyConfig.pathconfig_warnings` should be used instead, see :ref:`Python Initialization Configuration `. - Suppress error messages when calculating the module search path in - :c:func:`Py_GetPath`. - Private flag used by ``_freeze_module`` and ``frozenmain`` programs. .. deprecated-removed:: 3.12 3.15 @@ -584,7 +580,6 @@ Process-wide parameters .. index:: single: Py_Initialize() single: main() - single: Py_GetPath() This API is kept for backward compatibility: setting :c:member:`PyConfig.program_name` should be used instead, see :ref:`Python @@ -594,7 +589,7 @@ Process-wide parameters the first time, if it is called at all. It tells the interpreter the value of the ``argv[0]`` argument to the :c:func:`main` function of the program (converted to wide characters). - This is used by :c:func:`Py_GetPath` and some other functions below to find + This is used by some other functions below to find the Python run-time libraries relative to the interpreter executable. The default value is ``'python'``. The argument should point to a zero-terminated wide character string in static storage whose contents will not @@ -654,34 +649,6 @@ Process-wide parameters (:data:`sys.executable`) instead. -.. c:function:: wchar_t* Py_GetPath() - - .. index:: - triple: module; search; path - single: path (in module sys) - - Return the default module search path; this is computed from the program name - (set by :c:member:`PyConfig.program_name`) and some environment variables. - The returned string consists of a series of directory names separated by a - platform dependent delimiter character. The delimiter character is ``':'`` - on Unix and macOS, ``';'`` on Windows. The returned string points into - static storage; the caller should not modify its value. The list - :data:`sys.path` is initialized with this value on interpreter startup; it - can be (and usually is) modified later to change the search path for loading - modules. - - This function should not be called before :c:func:`Py_Initialize`, otherwise - it returns ``NULL``. - - .. XXX should give the exact rules - - .. versionchanged:: 3.10 - It now returns ``NULL`` if called before :c:func:`Py_Initialize`. - - .. deprecated-removed:: 3.13 3.15 - Use :c:func:`PyConfig_Get("module_search_paths") ` - (:data:`sys.path`) instead. - .. c:function:: const char* Py_GetVersion() Return the version of this Python interpreter. This is a string that looks diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index 9ff2196897bdcf..f5656d068dab9b 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -780,7 +780,6 @@ environment variable :envvar:`PYTHONHOME`, or insert additional directories in front of the standard path by setting :envvar:`PYTHONPATH`. .. index:: - single: Py_GetPath (C function) single: Py_GetPrefix (C function) single: Py_GetProgramFullPath (C function) @@ -789,8 +788,7 @@ The embedding application can steer the search by setting :c:func:`Py_InitializeFromConfig`. Note that :envvar:`PYTHONHOME` still overrides this and :envvar:`PYTHONPATH` is still inserted in front of the standard path. An application that requires total -control has to provide its own implementation of :c:func:`Py_GetPath`, -:c:func:`Py_GetPrefix`, and +control has to provide its own implementation of :c:func:`Py_GetPrefix`, and :c:func:`Py_GetProgramFullPath` (all defined in :file:`Modules/getpath.c`). .. index:: single: Py_IsInitialized (C function) diff --git a/Doc/data/refcounts.dat b/Doc/data/refcounts.dat index 8db77d2545ccb5..61eca7675ce264 100644 --- a/Doc/data/refcounts.dat +++ b/Doc/data/refcounts.dat @@ -3007,8 +3007,6 @@ Py_GetCompiler:const char*::: Py_GetCopyright:const char*::: -Py_GetPath:wchar_t*::: - Py_GetPlatform:const char*::: Py_GetPrefix:wchar_t*::: diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat index fdf3ca3e3b15cc..200c46698487f6 100644 --- a/Doc/data/stable_abi.dat +++ b/Doc/data/stable_abi.dat @@ -862,7 +862,6 @@ func,Py_GetCompiler,3.2,, func,Py_GetConstant,3.13,, func,Py_GetConstantBorrowed,3.13,, func,Py_GetCopyright,3.2,, -func,Py_GetPath,3.2,, func,Py_GetPlatform,3.2,, func,Py_GetPrefix,3.2,, func,Py_GetProgramFullPath,3.2,, 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 2139ce84b7497a..f13fe20367dfd1 100644 --- a/Doc/deprecations/c-api-pending-removal-in-3.15.rst +++ b/Doc/deprecations/c-api-pending-removal-in-3.15.rst @@ -22,9 +22,6 @@ Pending removal in Python 3.15 may return a type other than :class:`bytes`, such as :class:`str`. * Python initialization functions, deprecated in Python 3.13: - * :c:func:`Py_GetPath`: - Use :c:func:`PyConfig_Get("module_search_paths") ` - (:data:`sys.path`) instead. * :c:func:`Py_GetPrefix`: Use :c:func:`PyConfig_Get("base_prefix") ` (:data:`sys.base_prefix`) instead. Use :c:func:`PyConfig_Get("prefix") diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index 5707105fa86c87..4bbf6509c2b77b 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -2176,7 +2176,7 @@ Porting to Python 3.10 ``unicodedata.ucnhash_CAPI`` has been moved to the internal C API. (Contributed by Victor Stinner in :issue:`42157`.) -* :c:func:`Py_GetPath`, :c:func:`Py_GetPrefix`, :c:func:`!Py_GetExecPrefix`, +* :c:func:`!Py_GetPath`, :c:func:`Py_GetPrefix`, :c:func:`!Py_GetExecPrefix`, :c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome` and :c:func:`!Py_GetProgramName` functions now return ``NULL`` if called before :c:func:`Py_Initialize` (before Python is initialized). Use the new diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index c4f3da3c5a88b2..0debcffbac15db 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -2479,7 +2479,7 @@ Deprecated C APIs Clear :data:`sys.warnoptions` and :data:`!warnings.filters` instead. * :c:func:`!Py_GetExecPrefix`: Get :data:`sys.exec_prefix` instead. - * :c:func:`Py_GetPath`: + * :c:func:`!Py_GetPath`: Get :data:`sys.path` instead. * :c:func:`Py_GetPrefix`: Get :data:`sys.prefix` instead. diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index e4e2f79731f4e7..bafae7f94f43ba 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -161,6 +161,9 @@ Removed C APIs Use :c:func:`PyConfig_Get("exec_prefix") ` (:data:`sys.exec_prefix`) if :ref:`virtual environments ` need to be handled. +* :c:func:`!Py_GetPath`: + use :c:func:`PyConfig_Get("module_search_paths") ` + (:data:`sys.path`) instead. * :c:func:`!Py_GetProgramName`: use :c:func:`PyConfig_Get("executable") ` (:data:`sys.executable`) instead. diff --git a/Include/pylifecycle.h b/Include/pylifecycle.h index d84995d93f664f..89a5850725bffc 100644 --- a/Include/pylifecycle.h +++ b/Include/pylifecycle.h @@ -41,7 +41,6 @@ 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_GetPath(void); #ifdef MS_WINDOWS int _Py_CheckPython3(void); #endif diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 2e23b236a4103e..77b36ecc7129ca 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1708,7 +1708,6 @@ def test_getpath_abspath_win32(self): def test_global_pathconfig(self): # Test C API functions getting the path configuration: # - # - Py_GetPath() # - Py_GetPrefix() # - Py_GetProgramFullPath() # - Py_GetPythonHome() @@ -1723,15 +1722,12 @@ def get_func(name): func.restype = ctypes.c_wchar_p return func - Py_GetPath = get_func('Py_GetPath') Py_GetPrefix = get_func('Py_GetPrefix') Py_GetProgramFullPath = get_func('Py_GetProgramFullPath') Py_GetPythonHome = get_func('Py_GetPythonHome') config = _testinternalcapi.get_configs()['config'] - self.assertEqual(tuple(Py_GetPath().split(os.path.pathsep)), - config['module_search_paths']) self.assertEqual(Py_GetPrefix(), config['prefix']) self.assertEqual(Py_GetProgramFullPath(), config['executable']) self.assertEqual(Py_GetPythonHome(), config['home']) diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py index c9b37fcd8f6327..bc1129827079d4 100644 --- a/Lib/test/test_inspect/test_inspect.py +++ b/Lib/test/test_inspect/test_inspect.py @@ -6146,12 +6146,14 @@ def spawn_repl(self, *args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, ** object. """ + # TODO(picnixz): refactor this as it's used by test_repl.py + # To run the REPL without using a terminal, spawn python with the command # line option '-i' and the process name set to ''. # The directory of argv[0] must match the directory of the Python # executable for the Popen() call to python to succeed as the directory - # path may be used by Py_GetPath() to build the default module search - # path. + # path may be used by PyConfig_Get("module_search_paths") to build the + # default module search path. stdin_fname = os.path.join(os.path.dirname(sys.executable), "") cmd_line = [stdin_fname, '-E', '-i'] cmd_line.extend(args) diff --git a/Lib/test/test_repl.py b/Lib/test/test_repl.py index 228b326699e75f..27f16f1ba96566 100644 --- a/Lib/test/test_repl.py +++ b/Lib/test/test_repl.py @@ -38,8 +38,8 @@ def spawn_repl(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kw): # line option '-i' and the process name set to ''. # The directory of argv[0] must match the directory of the Python # executable for the Popen() call to python to succeed as the directory - # path may be used by Py_GetPath() to build the default module search - # path. + # path may be used by PyConfig_Get("module_search_paths") to build the + # default module search path. stdin_fname = os.path.join(os.path.dirname(sys.executable), "") cmd_line = [stdin_fname, '-I', '-i'] cmd_line.extend(args) diff --git a/Lib/test/test_stable_abi_ctypes.py b/Lib/test/test_stable_abi_ctypes.py index 54a6191dfac757..ef685086871e4c 100644 --- a/Lib/test/test_stable_abi_ctypes.py +++ b/Lib/test/test_stable_abi_ctypes.py @@ -880,7 +880,6 @@ def test_windows_feature_macros(self): "Py_GetConstant", "Py_GetConstantBorrowed", "Py_GetCopyright", - "Py_GetPath", "Py_GetPlatform", "Py_GetPrefix", "Py_GetProgramFullPath", diff --git a/Misc/NEWS.d/3.10.0a3.rst b/Misc/NEWS.d/3.10.0a3.rst index 9aa9bcfa57827c..e589138cf01959 100644 --- a/Misc/NEWS.d/3.10.0a3.rst +++ b/Misc/NEWS.d/3.10.0a3.rst @@ -1395,7 +1395,7 @@ but now can get the condition by calling the new private .. nonce: -Br3Co .. section: C API -:c:func:`Py_GetPath`, :c:func:`Py_GetPrefix`, :c:func:`!Py_GetExecPrefix`, +:c:func:`!Py_GetPath`, :c:func:`Py_GetPrefix`, :c:func:`!Py_GetExecPrefix`, :c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome` and :c:func:`!Py_GetProgramName` functions now return ``NULL`` if called before :c:func:`Py_Initialize` (before Python is initialized). Use the new diff --git a/Misc/NEWS.d/3.13.0a1.rst b/Misc/NEWS.d/3.13.0a1.rst index 7017cb2ea98b21..18fbe53afc638a 100644 --- a/Misc/NEWS.d/3.13.0a1.rst +++ b/Misc/NEWS.d/3.13.0a1.rst @@ -6594,7 +6594,7 @@ Deprecate old Python initialization functions: * :c:func:`PySys_ResetWarnOptions` * :c:func:`!Py_GetExecPrefix` -* :c:func:`Py_GetPath` +* :c:func:`!Py_GetPath` * :c:func:`Py_GetPrefix` * :c:func:`Py_GetProgramFullPath` * :c:func:`!Py_GetProgramName` diff --git a/Misc/stable_abi.toml b/Misc/stable_abi.toml index b8c6057153707a..2791ca12a085d0 100644 --- a/Misc/stable_abi.toml +++ b/Misc/stable_abi.toml @@ -1630,8 +1630,6 @@ added = '3.2' [function.Py_GetCopyright] added = '3.2' -[function.Py_GetPath] - added = '3.2' [function.Py_GetPlatform] added = '3.2' [function.Py_GetPrefix] diff --git a/PC/python3dll.c b/PC/python3dll.c index dfc983bb3d851b..cf9cd6fb288a39 100755 --- a/PC/python3dll.c +++ b/PC/python3dll.c @@ -58,7 +58,6 @@ EXPORT_FUNC(Py_GetCompiler) EXPORT_FUNC(Py_GetConstant) EXPORT_FUNC(Py_GetConstantBorrowed) EXPORT_FUNC(Py_GetCopyright) -EXPORT_FUNC(Py_GetPath) EXPORT_FUNC(Py_GetPlatform) EXPORT_FUNC(Py_GetPrefix) EXPORT_FUNC(Py_GetProgramFullPath) diff --git a/Python/pathconfig.c b/Python/pathconfig.c index ccab53ed33cff2..bf8578eb4447c1 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -272,18 +272,6 @@ Py_SetProgramName(const wchar_t *program_name) } -wchar_t * -Py_GetPath(void) -{ - /* If the user has provided a path, return that */ - if (_Py_path_config.module_search_path) { - return _Py_path_config.module_search_path; - } - /* If we have already done calculations, return the calculated path */ - return _Py_path_config.calculated_module_search_path; -} - - wchar_t * _Py_GetStdlibDir(void) { From 00ed990c58cadd18f6d449261f70abf90f023a36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 8 May 2025 13:07:33 +0200 Subject: [PATCH 04/17] remove `Py_GetPrefix` --- Doc/c-api/init.rst | 27 +------------------ Doc/c-api/intro.rst | 5 ++-- Doc/data/refcounts.dat | 2 -- Doc/data/stable_abi.dat | 1 - .../c-api-pending-removal-in-3.15.rst | 5 ---- Doc/whatsnew/3.10.rst | 2 +- Doc/whatsnew/3.13.rst | 2 +- Doc/whatsnew/3.15.rst | 6 +++++ Include/pylifecycle.h | 1 - Lib/test/test_embed.py | 3 --- Lib/test/test_stable_abi_ctypes.py | 1 - Misc/NEWS.d/3.10.0a3.rst | 2 +- Misc/NEWS.d/3.13.0a1.rst | 2 +- Misc/stable_abi.toml | 2 -- PC/python3dll.c | 1 - Python/pathconfig.c | 7 ----- 16 files changed, 13 insertions(+), 56 deletions(-) diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst index 410cc03201aadf..63a6d8f86dc5dd 100644 --- a/Doc/c-api/init.rst +++ b/Doc/c-api/init.rst @@ -77,7 +77,7 @@ The following functions can be safely called before Python is initialized: Despite their apparent similarity to some of the functions listed above, the following functions **should not be called** before the interpreter has - been initialized: :c:func:`Py_EncodeLocale`, :c:func:`Py_GetPrefix`, :c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome`, :c:func:`PyEval_InitThreads`, and + been initialized: :c:func:`Py_EncodeLocale`, :c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome`, :c:func:`PyEval_InitThreads`, and :c:func:`Py_RunMain`. @@ -602,31 +602,6 @@ Process-wide parameters .. deprecated-removed:: 3.11 3.15 -.. c:function:: wchar_t* Py_GetPrefix() - - Return the *prefix* for installed platform-independent files. This is derived - through a number of complicated rules from the program name set with - :c:member:`PyConfig.program_name` and some environment variables; for example, if the - program name is ``'/usr/local/bin/python'``, the prefix is ``'/usr/local'``. The - returned string points into static storage; the caller should not modify its - value. This corresponds to the :makevar:`prefix` variable in the top-level - :file:`Makefile` and the :option:`--prefix` argument to the :program:`configure` - script at build time. The value is available to Python code as ``sys.base_prefix``. - It is only useful on Unix. See also the next function. - - This function should not be called before :c:func:`Py_Initialize`, otherwise - it returns ``NULL``. - - .. versionchanged:: 3.10 - It now returns ``NULL`` if called before :c:func:`Py_Initialize`. - - .. deprecated-removed:: 3.13 3.15 - 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_GetProgramFullPath() .. index:: diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index f5656d068dab9b..9aba92bb91f222 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -780,7 +780,6 @@ environment variable :envvar:`PYTHONHOME`, or insert additional directories in front of the standard path by setting :envvar:`PYTHONPATH`. .. index:: - single: Py_GetPrefix (C function) single: Py_GetProgramFullPath (C function) The embedding application can steer the search by setting @@ -788,8 +787,8 @@ The embedding application can steer the search by setting :c:func:`Py_InitializeFromConfig`. Note that :envvar:`PYTHONHOME` still overrides this and :envvar:`PYTHONPATH` is still inserted in front of the standard path. An application that requires total -control has to provide its own implementation of :c:func:`Py_GetPrefix`, and -:c:func:`Py_GetProgramFullPath` (all defined in :file:`Modules/getpath.c`). +control has to provide its own implementation of :c:func:`Py_GetProgramFullPath` +(defined in :file:`Modules/getpath.c`). .. index:: single: Py_IsInitialized (C function) diff --git a/Doc/data/refcounts.dat b/Doc/data/refcounts.dat index 61eca7675ce264..a6502c30745ee4 100644 --- a/Doc/data/refcounts.dat +++ b/Doc/data/refcounts.dat @@ -3009,8 +3009,6 @@ Py_GetCopyright:const char*::: Py_GetPlatform:const char*::: -Py_GetPrefix:wchar_t*::: - Py_GetProgramFullPath:wchar_t*::: Py_GetVersion:const char*::: diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat index 200c46698487f6..bfaceb2d892379 100644 --- a/Doc/data/stable_abi.dat +++ b/Doc/data/stable_abi.dat @@ -863,7 +863,6 @@ func,Py_GetConstant,3.13,, func,Py_GetConstantBorrowed,3.13,, func,Py_GetCopyright,3.2,, func,Py_GetPlatform,3.2,, -func,Py_GetPrefix,3.2,, func,Py_GetProgramFullPath,3.2,, func,Py_GetPythonHome,3.2,, func,Py_GetRecursionLimit,3.2,, 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 f13fe20367dfd1..48bd57a8c34d9a 100644 --- a/Doc/deprecations/c-api-pending-removal-in-3.15.rst +++ b/Doc/deprecations/c-api-pending-removal-in-3.15.rst @@ -22,11 +22,6 @@ Pending removal in Python 3.15 may return a type other than :class:`bytes`, such as :class:`str`. * Python initialization functions, deprecated in Python 3.13: - * :c:func:`Py_GetPrefix`: - 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_GetProgramFullPath`: Use :c:func:`PyConfig_Get("executable") ` (:data:`sys.executable`) instead. diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index 4bbf6509c2b77b..a8207b08e9c57b 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -2176,7 +2176,7 @@ Porting to Python 3.10 ``unicodedata.ucnhash_CAPI`` has been moved to the internal C API. (Contributed by Victor Stinner in :issue:`42157`.) -* :c:func:`!Py_GetPath`, :c:func:`Py_GetPrefix`, :c:func:`!Py_GetExecPrefix`, +* :c:func:`!Py_GetPath`, :c:func:`!Py_GetPrefix`, :c:func:`!Py_GetExecPrefix`, :c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome` and :c:func:`!Py_GetProgramName` functions now return ``NULL`` if called before :c:func:`Py_Initialize` (before Python is initialized). Use the new diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 0debcffbac15db..282fd2b5dd4c13 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -2481,7 +2481,7 @@ Deprecated C APIs Get :data:`sys.exec_prefix` instead. * :c:func:`!Py_GetPath`: Get :data:`sys.path` instead. - * :c:func:`Py_GetPrefix`: + * :c:func:`!Py_GetPrefix`: Get :data:`sys.prefix` instead. * :c:func:`Py_GetProgramFullPath`: Get :data:`sys.executable` instead. diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index bafae7f94f43ba..922c2d69a295eb 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -164,6 +164,12 @@ Removed C APIs * :c:func:`!Py_GetPath`: use :c:func:`PyConfig_Get("module_search_paths") ` (:data:`sys.path`) instead. +* :c:func:`!Py_GetPrefix`: + 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_GetProgramName`: use :c:func:`PyConfig_Get("executable") ` (:data:`sys.executable`) instead. diff --git a/Include/pylifecycle.h b/Include/pylifecycle.h index 89a5850725bffc..89b9f21a3ea0f0 100644 --- a/Include/pylifecycle.h +++ b/Include/pylifecycle.h @@ -40,7 +40,6 @@ Py_DEPRECATED(3.11) PyAPI_FUNC(void) Py_SetPythonHome(const wchar_t *); 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); #ifdef MS_WINDOWS int _Py_CheckPython3(void); #endif diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 77b36ecc7129ca..7e198ef1684f0c 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1708,7 +1708,6 @@ def test_getpath_abspath_win32(self): def test_global_pathconfig(self): # Test C API functions getting the path configuration: # - # - Py_GetPrefix() # - Py_GetProgramFullPath() # - Py_GetPythonHome() # @@ -1722,13 +1721,11 @@ def get_func(name): func.restype = ctypes.c_wchar_p return func - Py_GetPrefix = get_func('Py_GetPrefix') Py_GetProgramFullPath = get_func('Py_GetProgramFullPath') Py_GetPythonHome = get_func('Py_GetPythonHome') config = _testinternalcapi.get_configs()['config'] - self.assertEqual(Py_GetPrefix(), config['prefix']) self.assertEqual(Py_GetProgramFullPath(), config['executable']) self.assertEqual(Py_GetPythonHome(), config['home']) diff --git a/Lib/test/test_stable_abi_ctypes.py b/Lib/test/test_stable_abi_ctypes.py index ef685086871e4c..32f66f28bae4de 100644 --- a/Lib/test/test_stable_abi_ctypes.py +++ b/Lib/test/test_stable_abi_ctypes.py @@ -881,7 +881,6 @@ def test_windows_feature_macros(self): "Py_GetConstantBorrowed", "Py_GetCopyright", "Py_GetPlatform", - "Py_GetPrefix", "Py_GetProgramFullPath", "Py_GetPythonHome", "Py_GetRecursionLimit", diff --git a/Misc/NEWS.d/3.10.0a3.rst b/Misc/NEWS.d/3.10.0a3.rst index e589138cf01959..929f12d8c6cc77 100644 --- a/Misc/NEWS.d/3.10.0a3.rst +++ b/Misc/NEWS.d/3.10.0a3.rst @@ -1395,7 +1395,7 @@ but now can get the condition by calling the new private .. nonce: -Br3Co .. section: C API -:c:func:`!Py_GetPath`, :c:func:`Py_GetPrefix`, :c:func:`!Py_GetExecPrefix`, +:c:func:`!Py_GetPath`, :c:func:`!Py_GetPrefix`, :c:func:`!Py_GetExecPrefix`, :c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome` and :c:func:`!Py_GetProgramName` functions now return ``NULL`` if called before :c:func:`Py_Initialize` (before Python is initialized). Use the new diff --git a/Misc/NEWS.d/3.13.0a1.rst b/Misc/NEWS.d/3.13.0a1.rst index 18fbe53afc638a..c92df1426398d4 100644 --- a/Misc/NEWS.d/3.13.0a1.rst +++ b/Misc/NEWS.d/3.13.0a1.rst @@ -6595,7 +6595,7 @@ Deprecate old Python initialization functions: * :c:func:`PySys_ResetWarnOptions` * :c:func:`!Py_GetExecPrefix` * :c:func:`!Py_GetPath` -* :c:func:`Py_GetPrefix` +* :c:func:`!Py_GetPrefix` * :c:func:`Py_GetProgramFullPath` * :c:func:`!Py_GetProgramName` * :c:func:`Py_GetPythonHome` diff --git a/Misc/stable_abi.toml b/Misc/stable_abi.toml index 2791ca12a085d0..235b606f47bb87 100644 --- a/Misc/stable_abi.toml +++ b/Misc/stable_abi.toml @@ -1632,8 +1632,6 @@ added = '3.2' [function.Py_GetPlatform] added = '3.2' -[function.Py_GetPrefix] - added = '3.2' [function.Py_GetProgramFullPath] added = '3.2' [function.Py_GetPythonHome] diff --git a/PC/python3dll.c b/PC/python3dll.c index cf9cd6fb288a39..0c370d914daca2 100755 --- a/PC/python3dll.c +++ b/PC/python3dll.c @@ -59,7 +59,6 @@ EXPORT_FUNC(Py_GetConstant) EXPORT_FUNC(Py_GetConstantBorrowed) EXPORT_FUNC(Py_GetCopyright) EXPORT_FUNC(Py_GetPlatform) -EXPORT_FUNC(Py_GetPrefix) EXPORT_FUNC(Py_GetProgramFullPath) EXPORT_FUNC(Py_GetPythonHome) EXPORT_FUNC(Py_GetRecursionLimit) diff --git a/Python/pathconfig.c b/Python/pathconfig.c index bf8578eb4447c1..865266da8b21ed 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -283,13 +283,6 @@ _Py_GetStdlibDir(void) } -wchar_t * -Py_GetPrefix(void) -{ - return _Py_path_config.prefix; -} - - wchar_t * Py_GetProgramFullPath(void) { From 2a578404624465ed4b17e5b8ca3c62afeabe79d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 8 May 2025 13:10:26 +0200 Subject: [PATCH 05/17] remove `Py_GetProgramFullPath` --- Doc/c-api/init.rst | 24 +------------------ Doc/c-api/intro.rst | 7 +----- Doc/data/refcounts.dat | 2 -- Doc/data/stable_abi.dat | 1 - .../c-api-pending-removal-in-3.15.rst | 3 --- Doc/whatsnew/3.10.rst | 2 +- Doc/whatsnew/3.13.rst | 2 +- Doc/whatsnew/3.15.rst | 3 +++ Doc/whatsnew/3.8.rst | 2 +- Include/pylifecycle.h | 1 - Lib/test/test_embed.py | 3 --- Misc/NEWS.d/3.10.0a3.rst | 2 +- Misc/NEWS.d/3.13.0a1.rst | 2 +- Misc/NEWS.d/3.9.0a1.rst | 2 +- Misc/stable_abi.toml | 2 -- PC/python3dll.c | 1 - Python/pathconfig.c | 7 ------ 17 files changed, 11 insertions(+), 55 deletions(-) diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst index 63a6d8f86dc5dd..954f552870344b 100644 --- a/Doc/c-api/init.rst +++ b/Doc/c-api/init.rst @@ -77,7 +77,7 @@ The following functions can be safely called before Python is initialized: Despite their apparent similarity to some of the functions listed above, the following functions **should not be called** before the interpreter has - been initialized: :c:func:`Py_EncodeLocale`, :c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome`, :c:func:`PyEval_InitThreads`, and + been initialized: :c:func:`Py_EncodeLocale`, :c:func:`Py_GetPythonHome`, :c:func:`PyEval_InitThreads`, and :c:func:`Py_RunMain`. @@ -602,28 +602,6 @@ Process-wide parameters .. deprecated-removed:: 3.11 3.15 -.. c:function:: wchar_t* Py_GetProgramFullPath() - - .. index:: - single: executable (in module sys) - - Return the full program name of the Python executable; this is computed as a - side-effect of deriving the default module search path from the program name - (set by :c:member:`PyConfig.program_name`). The returned string points into - static storage; the caller should not modify its value. The value is available - to Python code as ``sys.executable``. - - This function should not be called before :c:func:`Py_Initialize`, otherwise - it returns ``NULL``. - - .. versionchanged:: 3.10 - It now returns ``NULL`` if called before :c:func:`Py_Initialize`. - - .. deprecated-removed:: 3.13 3.15 - Use :c:func:`PyConfig_Get("executable") ` - (:data:`sys.executable`) instead. - - .. c:function:: const char* Py_GetVersion() Return the version of this Python interpreter. This is a string that looks diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index 9aba92bb91f222..9c2d1ace195234 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -779,16 +779,11 @@ found along :envvar:`PATH`.) The user can override this behavior by setting the environment variable :envvar:`PYTHONHOME`, or insert additional directories in front of the standard path by setting :envvar:`PYTHONPATH`. -.. index:: - single: Py_GetProgramFullPath (C function) - The embedding application can steer the search by setting :c:member:`PyConfig.program_name` *before* calling :c:func:`Py_InitializeFromConfig`. Note that :envvar:`PYTHONHOME` still overrides this and :envvar:`PYTHONPATH` is still -inserted in front of the standard path. An application that requires total -control has to provide its own implementation of :c:func:`Py_GetProgramFullPath` -(defined in :file:`Modules/getpath.c`). +inserted in front of the standard path. .. index:: single: Py_IsInitialized (C function) diff --git a/Doc/data/refcounts.dat b/Doc/data/refcounts.dat index a6502c30745ee4..6e2edfcd7687ce 100644 --- a/Doc/data/refcounts.dat +++ b/Doc/data/refcounts.dat @@ -3009,8 +3009,6 @@ Py_GetCopyright:const char*::: Py_GetPlatform:const char*::: -Py_GetProgramFullPath:wchar_t*::: - Py_GetVersion:const char*::: Py_INCREF:void::: diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat index bfaceb2d892379..424fb1a3b25939 100644 --- a/Doc/data/stable_abi.dat +++ b/Doc/data/stable_abi.dat @@ -863,7 +863,6 @@ func,Py_GetConstant,3.13,, func,Py_GetConstantBorrowed,3.13,, func,Py_GetCopyright,3.2,, func,Py_GetPlatform,3.2,, -func,Py_GetProgramFullPath,3.2,, func,Py_GetPythonHome,3.2,, func,Py_GetRecursionLimit,3.2,, func,Py_GetVersion,3.2,, 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 48bd57a8c34d9a..e53083dc4b39e8 100644 --- a/Doc/deprecations/c-api-pending-removal-in-3.15.rst +++ b/Doc/deprecations/c-api-pending-removal-in-3.15.rst @@ -22,9 +22,6 @@ Pending removal in Python 3.15 may return a type other than :class:`bytes`, such as :class:`str`. * Python initialization functions, deprecated in Python 3.13: - * :c:func:`Py_GetProgramFullPath`: - 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. diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index a8207b08e9c57b..48ded41081ce45 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -2177,7 +2177,7 @@ Porting to Python 3.10 (Contributed by Victor Stinner in :issue:`42157`.) * :c:func:`!Py_GetPath`, :c:func:`!Py_GetPrefix`, :c:func:`!Py_GetExecPrefix`, - :c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome` and + :c:func:`!Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome` and :c:func:`!Py_GetProgramName` functions now return ``NULL`` if called before :c:func:`Py_Initialize` (before Python is initialized). Use the new :ref:`init-config` API to get the :ref:`init-path-config`. diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 282fd2b5dd4c13..c2f9a010d45bd4 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -2483,7 +2483,7 @@ Deprecated C APIs Get :data:`sys.path` instead. * :c:func:`!Py_GetPrefix`: Get :data:`sys.prefix` instead. - * :c:func:`Py_GetProgramFullPath`: + * :c:func:`!Py_GetProgramFullPath`: Get :data:`sys.executable` instead. * :c:func:`!Py_GetProgramName`: Get :data:`sys.executable` instead. diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 922c2d69a295eb..7e6f155b014532 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -170,6 +170,9 @@ Removed C APIs Use :c:func:`PyConfig_Get("prefix") ` (:data:`sys.prefix`) if :ref:`virtual environments ` need to be handled. +* :c:func:`!Py_GetProgramFullPath`: + use :c:func:`PyConfig_Get("executable") ` + (:data:`sys.executable`) instead. * :c:func:`!Py_GetProgramName`: use :c:func:`PyConfig_Get("executable") ` (:data:`sys.executable`) instead. diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst index 7cf8999bd0d664..bc2eb1d0e263f0 100644 --- a/Doc/whatsnew/3.8.rst +++ b/Doc/whatsnew/3.8.rst @@ -1629,7 +1629,7 @@ Build and C API Changes (Contributed by Pablo Galindo in :issue:`37221`.) * :c:func:`!Py_SetPath` now sets :data:`sys.executable` to the program full - path (:c:func:`Py_GetProgramFullPath`) rather than to the program name + path (:c:func:`!Py_GetProgramFullPath`) rather than to the program name (:c:func:`!Py_GetProgramName`). (Contributed by Victor Stinner in :issue:`38234`.) diff --git a/Include/pylifecycle.h b/Include/pylifecycle.h index 89b9f21a3ea0f0..1c28e802a159bd 100644 --- a/Include/pylifecycle.h +++ b/Include/pylifecycle.h @@ -39,7 +39,6 @@ Py_DEPRECATED(3.11) PyAPI_FUNC(void) Py_SetProgramName(const wchar_t *); Py_DEPRECATED(3.11) PyAPI_FUNC(void) Py_SetPythonHome(const wchar_t *); Py_DEPRECATED(3.13) PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void); -Py_DEPRECATED(3.13) PyAPI_FUNC(wchar_t *) Py_GetProgramFullPath(void); #ifdef MS_WINDOWS int _Py_CheckPython3(void); #endif diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 7e198ef1684f0c..1f4d7193c9e089 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1708,7 +1708,6 @@ def test_getpath_abspath_win32(self): def test_global_pathconfig(self): # Test C API functions getting the path configuration: # - # - Py_GetProgramFullPath() # - Py_GetPythonHome() # # The global path configuration (_Py_path_config) must be a copy @@ -1721,12 +1720,10 @@ def get_func(name): func.restype = ctypes.c_wchar_p return func - Py_GetProgramFullPath = get_func('Py_GetProgramFullPath') Py_GetPythonHome = get_func('Py_GetPythonHome') config = _testinternalcapi.get_configs()['config'] - self.assertEqual(Py_GetProgramFullPath(), config['executable']) self.assertEqual(Py_GetPythonHome(), config['home']) def test_init_warnoptions(self): diff --git a/Misc/NEWS.d/3.10.0a3.rst b/Misc/NEWS.d/3.10.0a3.rst index 929f12d8c6cc77..94255dd91cc51c 100644 --- a/Misc/NEWS.d/3.10.0a3.rst +++ b/Misc/NEWS.d/3.10.0a3.rst @@ -1396,7 +1396,7 @@ but now can get the condition by calling the new private .. section: C API :c:func:`!Py_GetPath`, :c:func:`!Py_GetPrefix`, :c:func:`!Py_GetExecPrefix`, -:c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome` and +:c:func:`!Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome` and :c:func:`!Py_GetProgramName` functions now return ``NULL`` if called before :c:func:`Py_Initialize` (before Python is initialized). Use the new :ref:`Python Initialization Configuration API ` to get the diff --git a/Misc/NEWS.d/3.13.0a1.rst b/Misc/NEWS.d/3.13.0a1.rst index c92df1426398d4..e8a9c2980a0368 100644 --- a/Misc/NEWS.d/3.13.0a1.rst +++ b/Misc/NEWS.d/3.13.0a1.rst @@ -6596,7 +6596,7 @@ Deprecate old Python initialization functions: * :c:func:`!Py_GetExecPrefix` * :c:func:`!Py_GetPath` * :c:func:`!Py_GetPrefix` -* :c:func:`Py_GetProgramFullPath` +* :c:func:`!Py_GetProgramFullPath` * :c:func:`!Py_GetProgramName` * :c:func:`Py_GetPythonHome` diff --git a/Misc/NEWS.d/3.9.0a1.rst b/Misc/NEWS.d/3.9.0a1.rst index ee993c722f8806..cc24bae5881df1 100644 --- a/Misc/NEWS.d/3.9.0a1.rst +++ b/Misc/NEWS.d/3.9.0a1.rst @@ -5536,7 +5536,7 @@ Tyler Kieft. .. section: C API :c:func:`!Py_SetPath` now sets :data:`sys.executable` to the program full -path (:c:func:`Py_GetProgramFullPath`) rather than to the program name +path (:c:func:`!Py_GetProgramFullPath`) rather than to the program name (:c:func:`!Py_GetProgramName`). .. diff --git a/Misc/stable_abi.toml b/Misc/stable_abi.toml index 235b606f47bb87..5cfd1d6263e909 100644 --- a/Misc/stable_abi.toml +++ b/Misc/stable_abi.toml @@ -1632,8 +1632,6 @@ added = '3.2' [function.Py_GetPlatform] added = '3.2' -[function.Py_GetProgramFullPath] - added = '3.2' [function.Py_GetPythonHome] added = '3.2' [function.Py_GetRecursionLimit] diff --git a/PC/python3dll.c b/PC/python3dll.c index 0c370d914daca2..86d822b2aefde0 100755 --- a/PC/python3dll.c +++ b/PC/python3dll.c @@ -59,7 +59,6 @@ EXPORT_FUNC(Py_GetConstant) EXPORT_FUNC(Py_GetConstantBorrowed) EXPORT_FUNC(Py_GetCopyright) EXPORT_FUNC(Py_GetPlatform) -EXPORT_FUNC(Py_GetProgramFullPath) EXPORT_FUNC(Py_GetPythonHome) EXPORT_FUNC(Py_GetRecursionLimit) EXPORT_FUNC(Py_GetVersion) diff --git a/Python/pathconfig.c b/Python/pathconfig.c index 865266da8b21ed..05f7c5ced64b6e 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -283,13 +283,6 @@ _Py_GetStdlibDir(void) } -wchar_t * -Py_GetProgramFullPath(void) -{ - return _Py_path_config.program_full_path; -} - - wchar_t* Py_GetPythonHome(void) { From d71f3e67dd76e7c1979fe4e6d83074107d9ee110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 8 May 2025 13:12:45 +0200 Subject: [PATCH 06/17] remove `Py_GetPythonHome` --- Doc/c-api/init.rst | 19 +------------------ Doc/data/stable_abi.dat | 1 - .../c-api-pending-removal-in-3.15.rst | 4 ---- Doc/whatsnew/3.10.rst | 2 +- Doc/whatsnew/3.13.rst | 2 +- Doc/whatsnew/3.15.rst | 4 ++++ Include/pylifecycle.h | 1 - Lib/test/test_embed.py | 6 ------ Lib/test/test_stable_abi_ctypes.py | 1 - Misc/NEWS.d/3.10.0a3.rst | 2 +- Misc/NEWS.d/3.13.0a1.rst | 2 +- Misc/stable_abi.toml | 2 -- PC/python3dll.c | 1 - Python/pathconfig.c | 7 ------- 14 files changed, 9 insertions(+), 45 deletions(-) diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst index 954f552870344b..8ea73fa2f630c8 100644 --- a/Doc/c-api/init.rst +++ b/Doc/c-api/init.rst @@ -77,7 +77,7 @@ The following functions can be safely called before Python is initialized: Despite their apparent similarity to some of the functions listed above, the following functions **should not be called** before the interpreter has - been initialized: :c:func:`Py_EncodeLocale`, :c:func:`Py_GetPythonHome`, :c:func:`PyEval_InitThreads`, and + been initialized: :c:func:`Py_EncodeLocale`, :c:func:`PyEval_InitThreads`, and :c:func:`Py_RunMain`. @@ -772,23 +772,6 @@ Process-wide parameters .. deprecated-removed:: 3.11 3.15 -.. c:function:: wchar_t* Py_GetPythonHome() - - Return the default "home", that is, the value set by - :c:member:`PyConfig.home`, or the value of the :envvar:`PYTHONHOME` - environment variable if it is set. - - This function should not be called before :c:func:`Py_Initialize`, otherwise - it returns ``NULL``. - - .. versionchanged:: 3.10 - 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. - - .. _threads: Thread State and the Global Interpreter Lock diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat index 424fb1a3b25939..892c96404c17ad 100644 --- a/Doc/data/stable_abi.dat +++ b/Doc/data/stable_abi.dat @@ -863,7 +863,6 @@ func,Py_GetConstant,3.13,, func,Py_GetConstantBorrowed,3.13,, func,Py_GetCopyright,3.2,, func,Py_GetPlatform,3.2,, -func,Py_GetPythonHome,3.2,, func,Py_GetRecursionLimit,3.2,, func,Py_GetVersion,3.2,, data,Py_HasFileSystemDefaultEncoding,3.2,, 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 e53083dc4b39e8..ef4883fe7306ee 100644 --- a/Doc/deprecations/c-api-pending-removal-in-3.15.rst +++ b/Doc/deprecations/c-api-pending-removal-in-3.15.rst @@ -22,10 +22,6 @@ Pending removal in Python 3.15 may return a type other than :class:`bytes`, such as :class:`str`. * Python initialization functions, deprecated in Python 3.13: - * :c:func:`Py_GetPythonHome`: - Use :c:func:`PyConfig_Get("home") ` or the - :envvar:`PYTHONHOME` environment variable instead. - The `pythoncapi-compat project `__ can be used to get :c:func:`PyConfig_Get` on Python 3.13 and older. diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index 48ded41081ce45..f5e38950756afe 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -2177,7 +2177,7 @@ Porting to Python 3.10 (Contributed by Victor Stinner in :issue:`42157`.) * :c:func:`!Py_GetPath`, :c:func:`!Py_GetPrefix`, :c:func:`!Py_GetExecPrefix`, - :c:func:`!Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome` and + :c:func:`!Py_GetProgramFullPath`, :c:func:`!Py_GetPythonHome` and :c:func:`!Py_GetProgramName` functions now return ``NULL`` if called before :c:func:`Py_Initialize` (before Python is initialized). Use the new :ref:`init-config` API to get the :ref:`init-path-config`. diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index c2f9a010d45bd4..73d176db876577 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -2487,7 +2487,7 @@ Deprecated C APIs Get :data:`sys.executable` instead. * :c:func:`!Py_GetProgramName`: Get :data:`sys.executable` instead. - * :c:func:`Py_GetPythonHome`: + * :c:func:`!Py_GetPythonHome`: Get :c:member:`PyConfig.home` or the :envvar:`PYTHONHOME` environment variable instead. diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 7e6f155b014532..0675298f560e35 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -176,3 +176,7 @@ Removed C APIs * :c:func:`!Py_GetProgramName`: 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. + diff --git a/Include/pylifecycle.h b/Include/pylifecycle.h index 1c28e802a159bd..69a2a252fde5d7 100644 --- a/Include/pylifecycle.h +++ b/Include/pylifecycle.h @@ -37,7 +37,6 @@ PyAPI_FUNC(int) Py_BytesMain(int argc, char **argv); Py_DEPRECATED(3.11) PyAPI_FUNC(void) Py_SetProgramName(const wchar_t *); Py_DEPRECATED(3.11) PyAPI_FUNC(void) Py_SetPythonHome(const wchar_t *); -Py_DEPRECATED(3.13) PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void); #ifdef MS_WINDOWS int _Py_CheckPython3(void); diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 1f4d7193c9e089..ab79e82494ed80 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1708,8 +1708,6 @@ def test_getpath_abspath_win32(self): def test_global_pathconfig(self): # Test C API functions getting the path configuration: # - # - Py_GetPythonHome() - # # The global path configuration (_Py_path_config) must be a copy # of the path configuration of PyInterpreter.config (PyConfig). ctypes = import_helper.import_module('ctypes') @@ -1720,12 +1718,8 @@ def get_func(name): func.restype = ctypes.c_wchar_p return func - Py_GetPythonHome = get_func('Py_GetPythonHome') - config = _testinternalcapi.get_configs()['config'] - self.assertEqual(Py_GetPythonHome(), config['home']) - def test_init_warnoptions(self): # lowest to highest priority warnoptions = [ diff --git a/Lib/test/test_stable_abi_ctypes.py b/Lib/test/test_stable_abi_ctypes.py index 32f66f28bae4de..ed6a45aa9720fa 100644 --- a/Lib/test/test_stable_abi_ctypes.py +++ b/Lib/test/test_stable_abi_ctypes.py @@ -882,7 +882,6 @@ def test_windows_feature_macros(self): "Py_GetCopyright", "Py_GetPlatform", "Py_GetProgramFullPath", - "Py_GetPythonHome", "Py_GetRecursionLimit", "Py_GetVersion", "Py_HasFileSystemDefaultEncoding", diff --git a/Misc/NEWS.d/3.10.0a3.rst b/Misc/NEWS.d/3.10.0a3.rst index 94255dd91cc51c..3f3fb7ec599e57 100644 --- a/Misc/NEWS.d/3.10.0a3.rst +++ b/Misc/NEWS.d/3.10.0a3.rst @@ -1396,7 +1396,7 @@ but now can get the condition by calling the new private .. section: C API :c:func:`!Py_GetPath`, :c:func:`!Py_GetPrefix`, :c:func:`!Py_GetExecPrefix`, -:c:func:`!Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome` and +:c:func:`!Py_GetProgramFullPath`, :c:func:`!Py_GetPythonHome` and :c:func:`!Py_GetProgramName` functions now return ``NULL`` if called before :c:func:`Py_Initialize` (before Python is initialized). Use the new :ref:`Python Initialization Configuration API ` to get the diff --git a/Misc/NEWS.d/3.13.0a1.rst b/Misc/NEWS.d/3.13.0a1.rst index e8a9c2980a0368..4a48623279f8b4 100644 --- a/Misc/NEWS.d/3.13.0a1.rst +++ b/Misc/NEWS.d/3.13.0a1.rst @@ -6598,7 +6598,7 @@ Deprecate old Python initialization functions: * :c:func:`!Py_GetPrefix` * :c:func:`!Py_GetProgramFullPath` * :c:func:`!Py_GetProgramName` -* :c:func:`Py_GetPythonHome` +* :c:func:`!Py_GetPythonHome` Patch by Victor Stinner. diff --git a/Misc/stable_abi.toml b/Misc/stable_abi.toml index 5cfd1d6263e909..3a1fa84479ec8e 100644 --- a/Misc/stable_abi.toml +++ b/Misc/stable_abi.toml @@ -1632,8 +1632,6 @@ added = '3.2' [function.Py_GetPlatform] added = '3.2' -[function.Py_GetPythonHome] - added = '3.2' [function.Py_GetRecursionLimit] added = '3.2' [function.Py_GetVersion] diff --git a/PC/python3dll.c b/PC/python3dll.c index 86d822b2aefde0..b9409df7dc1324 100755 --- a/PC/python3dll.c +++ b/PC/python3dll.c @@ -59,7 +59,6 @@ EXPORT_FUNC(Py_GetConstant) EXPORT_FUNC(Py_GetConstantBorrowed) EXPORT_FUNC(Py_GetCopyright) EXPORT_FUNC(Py_GetPlatform) -EXPORT_FUNC(Py_GetPythonHome) EXPORT_FUNC(Py_GetRecursionLimit) EXPORT_FUNC(Py_GetVersion) EXPORT_FUNC(Py_IncRef) diff --git a/Python/pathconfig.c b/Python/pathconfig.c index 05f7c5ced64b6e..3a173ed7a5e26e 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -283,13 +283,6 @@ _Py_GetStdlibDir(void) } -wchar_t* -Py_GetPythonHome(void) -{ - return _Py_path_config.home; -} - - /* Compute module search path from argv[0] or the current working directory ("-m module" case) which will be prepended to sys.argv: sys.path[0]. From 60520386374efa864cc30c6fdcc9b068f284e0a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 8 May 2025 13:14:00 +0200 Subject: [PATCH 07/17] remove dead paragraphs --- .../c-api-pending-removal-in-3.15.rst | 5 ----- Lib/test/test_embed.py | 15 --------------- 2 files changed, 20 deletions(-) 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 ef4883fe7306ee..2b727b478f5615 100644 --- a/Doc/deprecations/c-api-pending-removal-in-3.15.rst +++ b/Doc/deprecations/c-api-pending-removal-in-3.15.rst @@ -20,11 +20,6 @@ Pending removal in Python 3.15 * :c:func:`!PyUnicode_AsEncodedUnicode`: Use :c:func:`PyCodec_Encode` instead; Note that some codecs (for example, "base64") may return a type other than :class:`bytes`, such as :class:`str`. -* Python initialization functions, deprecated in Python 3.13: - - 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: diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index ab79e82494ed80..f449e3cd627d0c 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1705,21 +1705,6 @@ def test_getpath_abspath_win32(self): for (_, expected), result in zip(CASES, results): self.assertEqual(result, expected) - def test_global_pathconfig(self): - # Test C API functions getting the path configuration: - # - # The global path configuration (_Py_path_config) must be a copy - # of the path configuration of PyInterpreter.config (PyConfig). - ctypes = import_helper.import_module('ctypes') - - def get_func(name): - func = getattr(ctypes.pythonapi, name) - func.argtypes = () - func.restype = ctypes.c_wchar_p - return func - - config = _testinternalcapi.get_configs()['config'] - def test_init_warnoptions(self): # lowest to highest priority warnoptions = [ From 96368b0dc2f49edbca7a07618a470436836dbb50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 8 May 2025 13:14:48 +0200 Subject: [PATCH 08/17] blurb --- .../next/C_API/2025-05-08-13-14-45.gh-issue-133644.J8_KZ2.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/C_API/2025-05-08-13-14-45.gh-issue-133644.J8_KZ2.rst diff --git a/Misc/NEWS.d/next/C_API/2025-05-08-13-14-45.gh-issue-133644.J8_KZ2.rst b/Misc/NEWS.d/next/C_API/2025-05-08-13-14-45.gh-issue-133644.J8_KZ2.rst new file mode 100644 index 00000000000000..9fd2cfd7faf7a3 --- /dev/null +++ b/Misc/NEWS.d/next/C_API/2025-05-08-13-14-45.gh-issue-133644.J8_KZ2.rst @@ -0,0 +1,2 @@ +Remove deprecated getter functions ``Py_Get*`` slated for removal in 3.15. +Patch by Bénédikt Tran. From 00f6ac4036e25c11625eab539b777d4dae6583fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 8 May 2025 13:18:42 +0200 Subject: [PATCH 09/17] improve wording --- Doc/whatsnew/3.15.rst | 50 ++++++++++--------- ...-05-08-13-14-45.gh-issue-133644.J8_KZ2.rst | 2 +- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 0675298f560e35..cfb1c9f34d4485 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -155,28 +155,30 @@ Deprecated C APIs Removed C APIs -------------- -* :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_GetPath`: - use :c:func:`PyConfig_Get("module_search_paths") ` - (:data:`sys.path`) instead. -* :c:func:`!Py_GetPrefix`: - 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_GetProgramFullPath`: - use :c:func:`PyConfig_Get("executable") ` - (:data:`sys.executable`) instead. -* :c:func:`!Py_GetProgramName`: - 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. +* Python initialization functions: + + * :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_GetPath`: + use :c:func:`PyConfig_Get("module_search_paths") ` + (:data:`sys.path`) instead. + * :c:func:`!Py_GetPrefix`: + 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_GetProgramFullPath`: + use :c:func:`PyConfig_Get("executable") ` + (:data:`sys.executable`) instead. + * :c:func:`!Py_GetProgramName`: + 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. diff --git a/Misc/NEWS.d/next/C_API/2025-05-08-13-14-45.gh-issue-133644.J8_KZ2.rst b/Misc/NEWS.d/next/C_API/2025-05-08-13-14-45.gh-issue-133644.J8_KZ2.rst index 9fd2cfd7faf7a3..a9275e81112058 100644 --- a/Misc/NEWS.d/next/C_API/2025-05-08-13-14-45.gh-issue-133644.J8_KZ2.rst +++ b/Misc/NEWS.d/next/C_API/2025-05-08-13-14-45.gh-issue-133644.J8_KZ2.rst @@ -1,2 +1,2 @@ -Remove deprecated getter functions ``Py_Get*`` slated for removal in 3.15. +Remove deprecated Python initialization getter functions ``Py_Get*``. Patch by Bénédikt Tran. From 23ef37044bad4637c83280f3ed03dae77167272d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 8 May 2025 13:25:50 +0200 Subject: [PATCH 10/17] make regen-limited-abi --- Lib/test/test_stable_abi_ctypes.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/test/test_stable_abi_ctypes.py b/Lib/test/test_stable_abi_ctypes.py index ed6a45aa9720fa..f0650a0d8c4ecf 100644 --- a/Lib/test/test_stable_abi_ctypes.py +++ b/Lib/test/test_stable_abi_ctypes.py @@ -881,7 +881,6 @@ def test_windows_feature_macros(self): "Py_GetConstantBorrowed", "Py_GetCopyright", "Py_GetPlatform", - "Py_GetProgramFullPath", "Py_GetRecursionLimit", "Py_GetVersion", "Py_HasFileSystemDefaultEncoding", From 18f71465eebe02c9a639bf1a44459d0376127aa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 8 May 2025 13:43:36 +0200 Subject: [PATCH 11/17] restore file --- .../c-api-pending-removal-in-3.15.rst | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) 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 2b727b478f5615..3b93946e464d45 100644 --- a/Doc/deprecations/c-api-pending-removal-in-3.15.rst +++ b/Doc/deprecations/c-api-pending-removal-in-3.15.rst @@ -20,6 +20,35 @@ Pending removal in Python 3.15 * :c:func:`!PyUnicode_AsEncodedUnicode`: Use :c:func:`PyCodec_Encode` instead; Note that some codecs (for example, "base64") may return a type other than :class:`bytes`, such as :class:`str`. +* Python initialization functions, deprecated in Python 3.13: + + * :c:func:`!Py_GetPath`: + Use :c:func:`PyConfig_Get("module_search_paths") ` + (:data:`sys.path`) instead. + * :c:func:`!Py_GetPrefix`: + 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 :c:func:`PyConfig_Get("executable") ` + (:data:`sys.executable`) instead. + * :c:func:`!Py_GetProgramName`: + 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. + + 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: From 38f0571608b1e85b20c6ebbc94ca9a451000b4c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 8 May 2025 13:48:12 +0200 Subject: [PATCH 12/17] restore stable ABI symbols --- Doc/data/stable_abi.dat | 6 ++++ Include/pylifecycle.h | 1 - Lib/test/test_stable_abi_ctypes.py | 6 ++++ Misc/stable_abi.toml | 12 +++++++ PC/python3dll.c | 6 ++++ Python/pathconfig.c | 55 +++++++++++++++++++++++++++++- 6 files changed, 84 insertions(+), 2 deletions(-) diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat index 892c96404c17ad..3d68487d07baf2 100644 --- a/Doc/data/stable_abi.dat +++ b/Doc/data/stable_abi.dat @@ -862,7 +862,13 @@ func,Py_GetCompiler,3.2,, func,Py_GetConstant,3.13,, func,Py_GetConstantBorrowed,3.13,, func,Py_GetCopyright,3.2,, +func,Py_GetExecPrefix,3.2,, +func,Py_GetPath,3.2,, func,Py_GetPlatform,3.2,, +func,Py_GetPrefix,3.2,, +func,Py_GetProgramFullPath,3.2,, +func,Py_GetProgramName,3.2,, +func,Py_GetPythonHome,3.2,, func,Py_GetRecursionLimit,3.2,, func,Py_GetVersion,3.2,, data,Py_HasFileSystemDefaultEncoding,3.2,, diff --git a/Include/pylifecycle.h b/Include/pylifecycle.h index 69a2a252fde5d7..4b3474035cec19 100644 --- a/Include/pylifecycle.h +++ b/Include/pylifecycle.h @@ -35,7 +35,6 @@ PyAPI_FUNC(int) Py_BytesMain(int argc, char **argv); /* In pathconfig.c */ Py_DEPRECATED(3.11) PyAPI_FUNC(void) Py_SetProgramName(const wchar_t *); - Py_DEPRECATED(3.11) PyAPI_FUNC(void) Py_SetPythonHome(const wchar_t *); #ifdef MS_WINDOWS diff --git a/Lib/test/test_stable_abi_ctypes.py b/Lib/test/test_stable_abi_ctypes.py index f0650a0d8c4ecf..1e6f69d49e9335 100644 --- a/Lib/test/test_stable_abi_ctypes.py +++ b/Lib/test/test_stable_abi_ctypes.py @@ -880,7 +880,13 @@ def test_windows_feature_macros(self): "Py_GetConstant", "Py_GetConstantBorrowed", "Py_GetCopyright", + "Py_GetExecPrefix", + "Py_GetPath", "Py_GetPlatform", + "Py_GetPrefix", + "Py_GetProgramFullPath", + "Py_GetProgramName", + "Py_GetPythonHome", "Py_GetRecursionLimit", "Py_GetVersion", "Py_HasFileSystemDefaultEncoding", diff --git a/Misc/stable_abi.toml b/Misc/stable_abi.toml index 3a1fa84479ec8e..d3e1f0db057023 100644 --- a/Misc/stable_abi.toml +++ b/Misc/stable_abi.toml @@ -1630,8 +1630,20 @@ added = '3.2' [function.Py_GetCopyright] added = '3.2' +[function.Py_GetExecPrefix] + added = '3.2' +[function.Py_GetPath] + added = '3.2' [function.Py_GetPlatform] added = '3.2' +[function.Py_GetPrefix] + added = '3.2' +[function.Py_GetProgramFullPath] + added = '3.2' +[function.Py_GetProgramName] + added = '3.2' +[function.Py_GetPythonHome] + added = '3.2' [function.Py_GetRecursionLimit] added = '3.2' [function.Py_GetVersion] diff --git a/PC/python3dll.c b/PC/python3dll.c index b9409df7dc1324..f0c578e11c643b 100755 --- a/PC/python3dll.c +++ b/PC/python3dll.c @@ -58,7 +58,13 @@ EXPORT_FUNC(Py_GetCompiler) EXPORT_FUNC(Py_GetConstant) EXPORT_FUNC(Py_GetConstantBorrowed) EXPORT_FUNC(Py_GetCopyright) +EXPORT_FUNC(Py_GetExecPrefix) +EXPORT_FUNC(Py_GetPath) EXPORT_FUNC(Py_GetPlatform) +EXPORT_FUNC(Py_GetPrefix) +EXPORT_FUNC(Py_GetProgramFullPath) +EXPORT_FUNC(Py_GetProgramName) +EXPORT_FUNC(Py_GetPythonHome) EXPORT_FUNC(Py_GetRecursionLimit) EXPORT_FUNC(Py_GetVersion) EXPORT_FUNC(Py_IncRef) diff --git a/Python/pathconfig.c b/Python/pathconfig.c index 3a173ed7a5e26e..a12c2f99adc6fe 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -272,7 +272,20 @@ Py_SetProgramName(const wchar_t *program_name) } -wchar_t * +/* removed in 3.15, but kept for stable ABI compatibility */ +PyAPI_FUNC(wchar_t *) +Py_GetPath(void) +{ + /* If the user has provided a path, return that */ + if (_Py_path_config.module_search_path) { + return _Py_path_config.module_search_path; + } + /* If we have already done calculations, return the calculated path */ + return _Py_path_config.calculated_module_search_path; +} + + +PyAPI_FUNC(wchar_t *) _Py_GetStdlibDir(void) { wchar_t *stdlib_dir = _Py_path_config.stdlib_dir; @@ -282,6 +295,46 @@ _Py_GetStdlibDir(void) return NULL; } +/* removed in 3.15, but kept for stable ABI compatibility */ +PyAPI_FUNC(wchar_t *) +Py_GetPrefix(void) +{ + return _Py_path_config.prefix; +} + + +/* removed in 3.15, but kept for stable ABI compatibility */ +PyAPI_FUNC(wchar_t *) +Py_GetExecPrefix(void) +{ + return _Py_path_config.exec_prefix; +} + + +/* removed in 3.15, but kept for stable ABI compatibility */ +PyAPI_FUNC(wchar_t *) +Py_GetProgramFullPath(void) +{ + return _Py_path_config.program_full_path; +} + + +/* removed in 3.15, but kept for stable ABI compatibility */ +PyAPI_FUNC(wchar_t *) +Py_GetPythonHome(void) +{ + return _Py_path_config.home; +} + + +/* removed in 3.15, but kept for stable ABI compatibility */ +PyAPI_FUNC(wchar_t *) +Py_GetProgramName(void) +{ + return _Py_path_config.program_name; +} + + /* Compute module search path from argv[0] or the current working directory ("-m module" case) which will be prepended to sys.argv: From 58ab9bd52f944f8e5558de155345ecb46c977776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 8 May 2025 14:18:29 +0200 Subject: [PATCH 13/17] restore stable ABI symbols --- Doc/data/stable_abi.dat | 6 ------ Misc/stable_abi.toml | 6 ++++++ Python/pathconfig.c | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat index 3d68487d07baf2..892c96404c17ad 100644 --- a/Doc/data/stable_abi.dat +++ b/Doc/data/stable_abi.dat @@ -862,13 +862,7 @@ func,Py_GetCompiler,3.2,, func,Py_GetConstant,3.13,, func,Py_GetConstantBorrowed,3.13,, func,Py_GetCopyright,3.2,, -func,Py_GetExecPrefix,3.2,, -func,Py_GetPath,3.2,, func,Py_GetPlatform,3.2,, -func,Py_GetPrefix,3.2,, -func,Py_GetProgramFullPath,3.2,, -func,Py_GetProgramName,3.2,, -func,Py_GetPythonHome,3.2,, func,Py_GetRecursionLimit,3.2,, func,Py_GetVersion,3.2,, data,Py_HasFileSystemDefaultEncoding,3.2,, diff --git a/Misc/stable_abi.toml b/Misc/stable_abi.toml index d3e1f0db057023..e6b4e168a54d97 100644 --- a/Misc/stable_abi.toml +++ b/Misc/stable_abi.toml @@ -1632,18 +1632,24 @@ added = '3.2' [function.Py_GetExecPrefix] added = '3.2' + abi_only = true [function.Py_GetPath] added = '3.2' + abi_only = true [function.Py_GetPlatform] added = '3.2' [function.Py_GetPrefix] added = '3.2' + abi_only = true [function.Py_GetProgramFullPath] added = '3.2' + abi_only = true [function.Py_GetProgramName] added = '3.2' + abi_only = true [function.Py_GetPythonHome] added = '3.2' + abi_only = true [function.Py_GetRecursionLimit] added = '3.2' [function.Py_GetVersion] diff --git a/Python/pathconfig.c b/Python/pathconfig.c index a12c2f99adc6fe..d034562c43f23c 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -295,6 +295,7 @@ _Py_GetStdlibDir(void) return NULL; } + /* removed in 3.15, but kept for stable ABI compatibility */ PyAPI_FUNC(wchar_t *) Py_GetPrefix(void) From bed1018116f3a50eee07418cd444583dbb722bb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 8 May 2025 14:19:47 +0200 Subject: [PATCH 14/17] restore tests --- Lib/test/test_embed.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index f449e3cd627d0c..95b2d80464c349 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1705,6 +1705,43 @@ def test_getpath_abspath_win32(self): for (_, expected), result in zip(CASES, results): self.assertEqual(result, expected) + def test_global_pathconfig(self): + # Test C API functions getting the path configuration: + # + # - Py_GetExecPrefix() + # - Py_GetPath() + # - Py_GetPrefix() + # - Py_GetProgramFullPath() + # - Py_GetProgramName() + # - Py_GetPythonHome() + # + # The global path configuration (_Py_path_config) must be a copy + # of the path configuration of PyInterpreter.config (PyConfig). + ctypes = import_helper.import_module('ctypes') + + def get_func(name): + func = getattr(ctypes.pythonapi, name) + func.argtypes = () + func.restype = ctypes.c_wchar_p + return func + + Py_GetPath = get_func('Py_GetPath') + Py_GetPrefix = get_func('Py_GetPrefix') + Py_GetExecPrefix = get_func('Py_GetExecPrefix') + Py_GetProgramName = get_func('Py_GetProgramName') + Py_GetProgramFullPath = get_func('Py_GetProgramFullPath') + Py_GetPythonHome = get_func('Py_GetPythonHome') + + config = _testinternalcapi.get_configs()['config'] + + self.assertEqual(tuple(Py_GetPath().split(os.path.pathsep)), + config['module_search_paths']) + self.assertEqual(Py_GetPrefix(), config['prefix']) + self.assertEqual(Py_GetExecPrefix(), config['exec_prefix']) + self.assertEqual(Py_GetProgramName(), config['program_name']) + self.assertEqual(Py_GetProgramFullPath(), config['executable']) + self.assertEqual(Py_GetPythonHome(), config['home']) + def test_init_warnoptions(self): # lowest to highest priority warnoptions = [ From 4d221c8d1772589f213e3ed66895ad64096713e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Fri, 9 May 2025 11:39:27 +0200 Subject: [PATCH 15/17] update porting notes --- Doc/whatsnew/3.15.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index cfb1c9f34d4485..c606a2b810561e 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -155,6 +155,10 @@ Deprecated C APIs Removed C APIs -------------- +The following functions are removed in favor of :c:func:`PyConfig_Get`. +The |pythoncapi_compat_project| can be used to get :c:func:`!PyConfig_Get` +on Python 3.13 and older. + * Python initialization functions: * :c:func:`!Py_GetExecPrefix`: @@ -182,3 +186,6 @@ Removed C APIs use :c:func:`PyConfig_Get("home") ` or the :envvar:`PYTHONHOME` environment variable instead. +.. |pythoncapi_compat_project| replace:: |pythoncapi_compat_project_link|_. +.. |pythoncapi_compat_project_link| replace:: pythoncapi-compat project +.. _pythoncapi_compat_project_link: https://github.com/python/pythoncapi-compat From e8672977a68153e4697df1b7d92cd0d96580f659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Fri, 9 May 2025 11:40:51 +0200 Subject: [PATCH 16/17] fixup docs --- Doc/whatsnew/3.15.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index c606a2b810561e..30c4f6a581ed26 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -171,14 +171,14 @@ on Python 3.13 and older. use :c:func:`PyConfig_Get("module_search_paths") ` (:data:`sys.path`) instead. * :c:func:`!Py_GetPrefix`: - 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. + 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_GetProgramFullPath`: - use :c:func:`PyConfig_Get("executable") ` - (:data:`sys.executable`) instead. + use :c:func:`PyConfig_Get("executable") ` + (:data:`sys.executable`) instead. * :c:func:`!Py_GetProgramName`: use :c:func:`PyConfig_Get("executable") ` (:data:`sys.executable`) instead. From 8528feeb2243cd8bea0f8d8cec420678170c49d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Fri, 9 May 2025 12:36:56 +0200 Subject: [PATCH 17/17] fixup period --- Doc/whatsnew/3.15.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 643693b32880e0..f92e383cce570f 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -201,6 +201,6 @@ on Python 3.13 and older. use :c:func:`PyConfig_Get("home") ` or the :envvar:`PYTHONHOME` environment variable instead. -.. |pythoncapi_compat_project| replace:: |pythoncapi_compat_project_link|_. +.. |pythoncapi_compat_project| replace:: |pythoncapi_compat_project_link|_ .. |pythoncapi_compat_project_link| replace:: pythoncapi-compat project .. _pythoncapi_compat_project_link: https://github.com/python/pythoncapi-compat