Skip to content

Commit 65f7dfe

Browse files
vstinnersrinivasreddy
authored andcommitted
pythongh-129342: Explain how to replace Py_GetProgramName() in C (python#129361)
1 parent e43fa23 commit 65f7dfe

File tree

2 files changed

+41
-23
lines changed

2 files changed

+41
-23
lines changed

Doc/c-api/init.rst

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,8 @@ Process-wide parameters
622622
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
623623
624624
.. deprecated-removed:: 3.13 3.15
625-
Get :data:`sys.executable` instead.
625+
Use :c:func:`PyConfig_Get("executable") <PyConfig_Get>`
626+
(:data:`sys.executable`) instead.
626627
627628
628629
.. c:function:: wchar_t* Py_GetPrefix()
@@ -644,8 +645,10 @@ Process-wide parameters
644645
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
645646
646647
.. deprecated-removed:: 3.13 3.15
647-
Get :data:`sys.base_prefix` instead, or :data:`sys.prefix` if
648-
:ref:`virtual environments <venv-def>` need to be handled.
648+
Use :c:func:`PyConfig_Get("base_prefix") <PyConfig_Get>`
649+
(:data:`sys.base_prefix`) instead. Use :c:func:`PyConfig_Get("prefix")
650+
<PyConfig_Get>` (:data:`sys.prefix`) if :ref:`virtual environments
651+
<venv-def>` need to be handled.
649652
650653
651654
.. c:function:: wchar_t* Py_GetExecPrefix()
@@ -690,9 +693,11 @@ Process-wide parameters
690693
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
691694

692695
.. deprecated-removed:: 3.13 3.15
693-
Get :data:`sys.base_exec_prefix` instead, or :data:`sys.exec_prefix` if
694-
:ref:`virtual environments <venv-def>` need to be handled.
695-
696+
Use :c:func:`PyConfig_Get("base_exec_prefix") <PyConfig_Get>`
697+
(:data:`sys.base_exec_prefix`) instead. Use
698+
:c:func:`PyConfig_Get("exec_prefix") <PyConfig_Get>`
699+
(:data:`sys.exec_prefix`) if :ref:`virtual environments <venv-def>` need
700+
to be handled.
696701

697702
.. c:function:: wchar_t* Py_GetProgramFullPath()
698703
@@ -712,7 +717,8 @@ Process-wide parameters
712717
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
713718

714719
.. deprecated-removed:: 3.13 3.15
715-
Get :data:`sys.executable` instead.
720+
Use :c:func:`PyConfig_Get("executable") <PyConfig_Get>`
721+
(:data:`sys.executable`) instead.
716722

717723

718724
.. c:function:: wchar_t* Py_GetPath()
@@ -740,8 +746,8 @@ Process-wide parameters
740746
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
741747

742748
.. deprecated-removed:: 3.13 3.15
743-
Get :data:`sys.path` instead.
744-
749+
Use :c:func:`PyConfig_Get("module_search_paths") <PyConfig_Get>`
750+
(:data:`sys.path`) instead.
745751

746752
.. c:function:: const char* Py_GetVersion()
747753
@@ -926,8 +932,8 @@ Process-wide parameters
926932
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
927933
928934
.. deprecated-removed:: 3.13 3.15
929-
Get :c:member:`PyConfig.home` or :envvar:`PYTHONHOME` environment
930-
variable instead.
935+
Use :c:func:`PyConfig_Get("home") <PyConfig_Get>` or the
936+
:envvar:`PYTHONHOME` environment variable instead.
931937
932938
933939
.. _threads:

Doc/deprecations/c-api-pending-removal-in-3.15.rst

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,35 @@ Pending removal in Python 3.15
1010
:c:func:`PyWeakref_GetRef` on Python 3.12 and older.
1111
* :c:type:`Py_UNICODE` type and the :c:macro:`!Py_UNICODE_WIDE` macro:
1212
Use :c:type:`wchar_t` instead.
13-
* Python initialization functions:
13+
* Python initialization functions, deprecated in Python 3.13:
1414

15-
* :c:func:`PySys_ResetWarnOptions`:
16-
Clear :data:`sys.warnoptions` and :data:`!warnings.filters` instead.
17-
* :c:func:`Py_GetExecPrefix`:
18-
Get :data:`sys.base_exec_prefix` and :data:`sys.exec_prefix` instead.
1915
* :c:func:`Py_GetPath`:
20-
Get :data:`sys.path` instead.
16+
Use :c:func:`PyConfig_Get("module_search_paths") <PyConfig_Get>`
17+
(:data:`sys.path`) instead.
2118
* :c:func:`Py_GetPrefix`:
22-
Get :data:`sys.base_prefix` and :data:`sys.prefix` instead.
19+
Use :c:func:`PyConfig_Get("base_prefix") <PyConfig_Get>`
20+
(:data:`sys.base_prefix`) instead. Use :c:func:`PyConfig_Get("prefix")
21+
<PyConfig_Get>` (:data:`sys.prefix`) if :ref:`virtual environments
22+
<venv-def>` need to be handled.
23+
* :c:func:`Py_GetExecPrefix`:
24+
Use :c:func:`PyConfig_Get("base_exec_prefix") <PyConfig_Get>`
25+
(:data:`sys.base_exec_prefix`) instead. Use
26+
:c:func:`PyConfig_Get("exec_prefix") <PyConfig_Get>`
27+
(:data:`sys.exec_prefix`) if :ref:`virtual environments <venv-def>` need to
28+
be handled.
2329
* :c:func:`Py_GetProgramFullPath`:
24-
Get :data:`sys.executable` instead.
30+
Use :c:func:`PyConfig_Get("executable") <PyConfig_Get>`
31+
(:data:`sys.executable`) instead.
2532
* :c:func:`Py_GetProgramName`:
26-
Get :data:`sys.executable` instead.
33+
Use :c:func:`PyConfig_Get("executable") <PyConfig_Get>`
34+
(:data:`sys.executable`) instead.
2735
* :c:func:`Py_GetPythonHome`:
28-
Get :c:func:`PyConfig_Get("home") <PyConfig_Get>`
29-
or the :envvar:`PYTHONHOME` environment variable instead.
36+
Use :c:func:`PyConfig_Get("home") <PyConfig_Get>` or the
37+
:envvar:`PYTHONHOME` environment variable instead.
3038

31-
See also the :c:func:`PyConfig_Get` function.
39+
The `pythoncapi-compat project
40+
<https://github.com/python/pythoncapi-compat/>`__ can be used to get
41+
:c:func:`PyConfig_Get` on Python 3.13 and older.
3242

3343
* Functions to configure Python's initialization, deprecated in Python 3.11:
3444

@@ -40,6 +50,8 @@ Pending removal in Python 3.15
4050
Set :c:member:`PyConfig.program_name` instead.
4151
* :c:func:`!Py_SetPythonHome()`:
4252
Set :c:member:`PyConfig.home` instead.
53+
* :c:func:`PySys_ResetWarnOptions`:
54+
Clear :data:`sys.warnoptions` and :data:`!warnings.filters` instead.
4355

4456
The :c:func:`Py_InitializeFromConfig` API should be used with
4557
:c:type:`PyConfig` instead.

0 commit comments

Comments
 (0)