Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove Py_GetPrefix
  • Loading branch information
picnixz committed May 8, 2025
commit 00ed990c58cadd18f6d449261f70abf90f023a36
27 changes: 1 addition & 26 deletions Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`.


Expand Down Expand Up @@ -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") <PyConfig_Get>`
(:data:`sys.base_prefix`) instead. Use :c:func:`PyConfig_Get("prefix")
<PyConfig_Get>` (:data:`sys.prefix`) if :ref:`virtual environments
<venv-def>` need to be handled.


.. c:function:: wchar_t* Py_GetProgramFullPath()

.. index::
Expand Down
5 changes: 2 additions & 3 deletions Doc/c-api/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -780,16 +780,15 @@ 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
: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_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)

Expand Down
2 changes: 0 additions & 2 deletions Doc/data/refcounts.dat
Original file line number Diff line number Diff line change
Expand Up @@ -3009,8 +3009,6 @@ Py_GetCopyright:const char*:::

Py_GetPlatform:const char*:::

Py_GetPrefix:wchar_t*:::

Py_GetProgramFullPath:wchar_t*:::

Py_GetVersion:const char*:::
Expand Down
1 change: 0 additions & 1 deletion Doc/data/stable_abi.dat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions Doc/deprecations/c-api-pending-removal-in-3.15.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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") <PyConfig_Get>`
(:data:`sys.base_prefix`) instead. Use :c:func:`PyConfig_Get("prefix")
<PyConfig_Get>` (:data:`sys.prefix`) if :ref:`virtual environments
<venv-def>` need to be handled.
* :c:func:`Py_GetProgramFullPath`:
Use :c:func:`PyConfig_Get("executable") <PyConfig_Get>`
(:data:`sys.executable`) instead.
Expand Down
2 changes: 1 addition & 1 deletion Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions Doc/whatsnew/3.15.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ Removed C APIs
* :c:func:`!Py_GetPath`:
use :c:func:`PyConfig_Get("module_search_paths") <PyConfig_Get>`
(:data:`sys.path`) instead.
* :c:func:`!Py_GetPrefix`:
use :c:func:`PyConfig_Get("base_prefix") <PyConfig_Get>`
(:data:`sys.base_prefix`) instead.
Use :c:func:`PyConfig_Get("prefix") <PyConfig_Get>`
(:data:`sys.prefix`) if :ref:`virtual environments <venv-def>`
need to be handled.
* :c:func:`!Py_GetProgramName`:
use :c:func:`PyConfig_Get("executable") <PyConfig_Get>`
(:data:`sys.executable`) instead.
1 change: 0 additions & 1 deletion Include/pylifecycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions Lib/test/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
#
Expand All @@ -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'])

Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_stable_abi_ctypes.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Misc/NEWS.d/3.10.0a3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Misc/NEWS.d/3.13.0a1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 0 additions & 2 deletions Misc/stable_abi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion PC/python3dll.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions Python/pathconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,6 @@ _Py_GetStdlibDir(void)
}


wchar_t *
Py_GetPrefix(void)
{
return _Py_path_config.prefix;
}


wchar_t *
Py_GetProgramFullPath(void)
{
Expand Down