Skip to content

Commit 5044e85

Browse files
authored
gh-133644: Remove deprecated Python initialization getter functions (#133661)
Remove functions: * Py_GetExecPrefix() * Py_GetPath() * Py_GetPrefix() * Py_GetProgramFullPath() * Py_GetProgramName() * Py_GetPythonHome()
1 parent f52de8a commit 5044e85

18 files changed

+93
-238
lines changed

Doc/c-api/init.rst

Lines changed: 2 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ The following functions can be safely called before Python is initialized:
7777

7878
Despite their apparent similarity to some of the functions listed above,
7979
the following functions **should not be called** before the interpreter has
80-
been initialized: :c:func:`Py_EncodeLocale`, :c:func:`Py_GetPath`,
81-
:c:func:`Py_GetPrefix`, :c:func:`Py_GetExecPrefix`,
82-
:c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome`,
83-
:c:func:`Py_GetProgramName`, :c:func:`PyEval_InitThreads`, and
80+
been initialized: :c:func:`Py_EncodeLocale`, :c:func:`PyEval_InitThreads`, and
8481
:c:func:`Py_RunMain`.
8582

8683

@@ -145,9 +142,6 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
145142
:c:member:`PyConfig.pathconfig_warnings` should be used instead, see
146143
:ref:`Python Initialization Configuration <init-config>`.
147144

148-
Suppress error messages when calculating the module search path in
149-
:c:func:`Py_GetPath`.
150-
151145
Private flag used by ``_freeze_module`` and ``frozenmain`` programs.
152146

153147
.. deprecated-removed:: 3.12 3.15
@@ -586,7 +580,6 @@ Process-wide parameters
586580
.. index::
587581
single: Py_Initialize()
588582
single: main()
589-
single: Py_GetPath()
590583
591584
This API is kept for backward compatibility: setting
592585
:c:member:`PyConfig.program_name` should be used instead, see :ref:`Python
@@ -596,7 +589,7 @@ Process-wide parameters
596589
the first time, if it is called at all. It tells the interpreter the value
597590
of the ``argv[0]`` argument to the :c:func:`main` function of the program
598591
(converted to wide characters).
599-
This is used by :c:func:`Py_GetPath` and some other functions below to find
592+
This is used by some other functions below to find
600593
the Python run-time libraries relative to the interpreter executable. The
601594
default value is ``'python'``. The argument should point to a
602595
zero-terminated wide character string in static storage whose contents will not
@@ -609,146 +602,6 @@ Process-wide parameters
609602
.. deprecated-removed:: 3.11 3.15
610603
611604
612-
.. c:function:: wchar_t* Py_GetProgramName()
613-
614-
Return the program name set with :c:member:`PyConfig.program_name`, or the default.
615-
The returned string points into static storage; the caller should not modify its
616-
value.
617-
618-
This function should not be called before :c:func:`Py_Initialize`, otherwise
619-
it returns ``NULL``.
620-
621-
.. versionchanged:: 3.10
622-
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
623-
624-
.. deprecated-removed:: 3.13 3.15
625-
Use :c:func:`PyConfig_Get("executable") <PyConfig_Get>`
626-
(:data:`sys.executable`) instead.
627-
628-
629-
.. c:function:: wchar_t* Py_GetPrefix()
630-
631-
Return the *prefix* for installed platform-independent files. This is derived
632-
through a number of complicated rules from the program name set with
633-
:c:member:`PyConfig.program_name` and some environment variables; for example, if the
634-
program name is ``'/usr/local/bin/python'``, the prefix is ``'/usr/local'``. The
635-
returned string points into static storage; the caller should not modify its
636-
value. This corresponds to the :makevar:`prefix` variable in the top-level
637-
:file:`Makefile` and the :option:`--prefix` argument to the :program:`configure`
638-
script at build time. The value is available to Python code as ``sys.base_prefix``.
639-
It is only useful on Unix. See also the next function.
640-
641-
This function should not be called before :c:func:`Py_Initialize`, otherwise
642-
it returns ``NULL``.
643-
644-
.. versionchanged:: 3.10
645-
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
646-
647-
.. deprecated-removed:: 3.13 3.15
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.
652-
653-
654-
.. c:function:: wchar_t* Py_GetExecPrefix()
655-
656-
Return the *exec-prefix* for installed platform-*dependent* files. This is
657-
derived through a number of complicated rules from the program name set with
658-
:c:member:`PyConfig.program_name` and some environment variables; for example, if the
659-
program name is ``'/usr/local/bin/python'``, the exec-prefix is
660-
``'/usr/local'``. The returned string points into static storage; the caller
661-
should not modify its value. This corresponds to the :makevar:`exec_prefix`
662-
variable in the top-level :file:`Makefile` and the ``--exec-prefix``
663-
argument to the :program:`configure` script at build time. The value is
664-
available to Python code as ``sys.base_exec_prefix``. It is only useful on
665-
Unix.
666-
667-
Background: The exec-prefix differs from the prefix when platform dependent
668-
files (such as executables and shared libraries) are installed in a different
669-
directory tree. In a typical installation, platform dependent files may be
670-
installed in the :file:`/usr/local/plat` subtree while platform independent may
671-
be installed in :file:`/usr/local`.
672-
673-
Generally speaking, a platform is a combination of hardware and software
674-
families, e.g. Sparc machines running the Solaris 2.x operating system are
675-
considered the same platform, but Intel machines running Solaris 2.x are another
676-
platform, and Intel machines running Linux are yet another platform. Different
677-
major revisions of the same operating system generally also form different
678-
platforms. Non-Unix operating systems are a different story; the installation
679-
strategies on those systems are so different that the prefix and exec-prefix are
680-
meaningless, and set to the empty string. Note that compiled Python bytecode
681-
files are platform independent (but not independent from the Python version by
682-
which they were compiled!).
683-
684-
System administrators will know how to configure the :program:`mount` or
685-
:program:`automount` programs to share :file:`/usr/local` between platforms
686-
while having :file:`/usr/local/plat` be a different filesystem for each
687-
platform.
688-
689-
This function should not be called before :c:func:`Py_Initialize`, otherwise
690-
it returns ``NULL``.
691-
692-
.. versionchanged:: 3.10
693-
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
694-
695-
.. deprecated-removed:: 3.13 3.15
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.
701-
702-
.. c:function:: wchar_t* Py_GetProgramFullPath()
703-
704-
.. index::
705-
single: executable (in module sys)
706-
707-
Return the full program name of the Python executable; this is computed as a
708-
side-effect of deriving the default module search path from the program name
709-
(set by :c:member:`PyConfig.program_name`). The returned string points into
710-
static storage; the caller should not modify its value. The value is available
711-
to Python code as ``sys.executable``.
712-
713-
This function should not be called before :c:func:`Py_Initialize`, otherwise
714-
it returns ``NULL``.
715-
716-
.. versionchanged:: 3.10
717-
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
718-
719-
.. deprecated-removed:: 3.13 3.15
720-
Use :c:func:`PyConfig_Get("executable") <PyConfig_Get>`
721-
(:data:`sys.executable`) instead.
722-
723-
724-
.. c:function:: wchar_t* Py_GetPath()
725-
726-
.. index::
727-
triple: module; search; path
728-
single: path (in module sys)
729-
730-
Return the default module search path; this is computed from the program name
731-
(set by :c:member:`PyConfig.program_name`) and some environment variables.
732-
The returned string consists of a series of directory names separated by a
733-
platform dependent delimiter character. The delimiter character is ``':'``
734-
on Unix and macOS, ``';'`` on Windows. The returned string points into
735-
static storage; the caller should not modify its value. The list
736-
:data:`sys.path` is initialized with this value on interpreter startup; it
737-
can be (and usually is) modified later to change the search path for loading
738-
modules.
739-
740-
This function should not be called before :c:func:`Py_Initialize`, otherwise
741-
it returns ``NULL``.
742-
743-
.. XXX should give the exact rules
744-
745-
.. versionchanged:: 3.10
746-
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
747-
748-
.. deprecated-removed:: 3.13 3.15
749-
Use :c:func:`PyConfig_Get("module_search_paths") <PyConfig_Get>`
750-
(:data:`sys.path`) instead.
751-
752605
.. c:function:: const char* Py_GetVersion()
753606
754607
Return the version of this Python interpreter. This is a string that looks
@@ -919,23 +772,6 @@ Process-wide parameters
919772
.. deprecated-removed:: 3.11 3.15
920773
921774
922-
.. c:function:: wchar_t* Py_GetPythonHome()
923-
924-
Return the default "home", that is, the value set by
925-
:c:member:`PyConfig.home`, or the value of the :envvar:`PYTHONHOME`
926-
environment variable if it is set.
927-
928-
This function should not be called before :c:func:`Py_Initialize`, otherwise
929-
it returns ``NULL``.
930-
931-
.. versionchanged:: 3.10
932-
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
933-
934-
.. deprecated-removed:: 3.13 3.15
935-
Use :c:func:`PyConfig_Get("home") <PyConfig_Get>` or the
936-
:envvar:`PYTHONHOME` environment variable instead.
937-
938-
939775
.. _threads:
940776
941777
Thread State and the Global Interpreter Lock

Doc/c-api/intro.rst

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -779,20 +779,11 @@ found along :envvar:`PATH`.) The user can override this behavior by setting the
779779
environment variable :envvar:`PYTHONHOME`, or insert additional directories in
780780
front of the standard path by setting :envvar:`PYTHONPATH`.
781781

782-
.. index::
783-
single: Py_GetPath (C function)
784-
single: Py_GetPrefix (C function)
785-
single: Py_GetExecPrefix (C function)
786-
single: Py_GetProgramFullPath (C function)
787-
788782
The embedding application can steer the search by setting
789783
:c:member:`PyConfig.program_name` *before* calling
790784
:c:func:`Py_InitializeFromConfig`. Note that
791785
:envvar:`PYTHONHOME` still overrides this and :envvar:`PYTHONPATH` is still
792-
inserted in front of the standard path. An application that requires total
793-
control has to provide its own implementation of :c:func:`Py_GetPath`,
794-
:c:func:`Py_GetPrefix`, :c:func:`Py_GetExecPrefix`, and
795-
:c:func:`Py_GetProgramFullPath` (all defined in :file:`Modules/getpath.c`).
786+
inserted in front of the standard path.
796787

797788
.. index:: single: Py_IsInitialized (C function)
798789

Doc/data/refcounts.dat

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3004,18 +3004,8 @@ Py_GetCompiler:const char*:::
30043004

30053005
Py_GetCopyright:const char*:::
30063006

3007-
Py_GetExecPrefix:wchar_t*:::
3008-
3009-
Py_GetPath:wchar_t*:::
3010-
30113007
Py_GetPlatform:const char*:::
30123008

3013-
Py_GetPrefix:wchar_t*:::
3014-
3015-
Py_GetProgramFullPath:wchar_t*:::
3016-
3017-
Py_GetProgramName:wchar_t*:::
3018-
30193009
Py_GetVersion:const char*:::
30203010

30213011
Py_INCREF:void:::

Doc/data/stable_abi.dat

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,27 @@ Pending removal in Python 3.15
2222
may return a type other than :class:`bytes`, such as :class:`str`.
2323
* Python initialization functions, deprecated in Python 3.13:
2424

25-
* :c:func:`Py_GetPath`:
25+
* :c:func:`!Py_GetPath`:
2626
Use :c:func:`PyConfig_Get("module_search_paths") <PyConfig_Get>`
2727
(:data:`sys.path`) instead.
28-
* :c:func:`Py_GetPrefix`:
28+
* :c:func:`!Py_GetPrefix`:
2929
Use :c:func:`PyConfig_Get("base_prefix") <PyConfig_Get>`
3030
(:data:`sys.base_prefix`) instead. Use :c:func:`PyConfig_Get("prefix")
3131
<PyConfig_Get>` (:data:`sys.prefix`) if :ref:`virtual environments
3232
<venv-def>` need to be handled.
33-
* :c:func:`Py_GetExecPrefix`:
33+
* :c:func:`!Py_GetExecPrefix`:
3434
Use :c:func:`PyConfig_Get("base_exec_prefix") <PyConfig_Get>`
3535
(:data:`sys.base_exec_prefix`) instead. Use
3636
:c:func:`PyConfig_Get("exec_prefix") <PyConfig_Get>`
3737
(:data:`sys.exec_prefix`) if :ref:`virtual environments <venv-def>` need to
3838
be handled.
39-
* :c:func:`Py_GetProgramFullPath`:
39+
* :c:func:`!Py_GetProgramFullPath`:
4040
Use :c:func:`PyConfig_Get("executable") <PyConfig_Get>`
4141
(:data:`sys.executable`) instead.
42-
* :c:func:`Py_GetProgramName`:
42+
* :c:func:`!Py_GetProgramName`:
4343
Use :c:func:`PyConfig_Get("executable") <PyConfig_Get>`
4444
(:data:`sys.executable`) instead.
45-
* :c:func:`Py_GetPythonHome`:
45+
* :c:func:`!Py_GetPythonHome`:
4646
Use :c:func:`PyConfig_Get("home") <PyConfig_Get>` or the
4747
:envvar:`PYTHONHOME` environment variable instead.
4848

Doc/whatsnew/3.10.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,9 +2176,9 @@ Porting to Python 3.10
21762176
``unicodedata.ucnhash_CAPI`` has been moved to the internal C API.
21772177
(Contributed by Victor Stinner in :issue:`42157`.)
21782178
2179-
* :c:func:`Py_GetPath`, :c:func:`Py_GetPrefix`, :c:func:`Py_GetExecPrefix`,
2180-
:c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome` and
2181-
:c:func:`Py_GetProgramName` functions now return ``NULL`` if called before
2179+
* :c:func:`!Py_GetPath`, :c:func:`!Py_GetPrefix`, :c:func:`!Py_GetExecPrefix`,
2180+
:c:func:`!Py_GetProgramFullPath`, :c:func:`!Py_GetPythonHome` and
2181+
:c:func:`!Py_GetProgramName` functions now return ``NULL`` if called before
21822182
:c:func:`Py_Initialize` (before Python is initialized). Use the new
21832183
:ref:`init-config` API to get the :ref:`init-path-config`.
21842184
(Contributed by Victor Stinner in :issue:`42260`.)

Doc/whatsnew/3.13.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,17 +2477,17 @@ Deprecated C APIs
24772477

24782478
* :c:func:`PySys_ResetWarnOptions`:
24792479
Clear :data:`sys.warnoptions` and :data:`!warnings.filters` instead.
2480-
* :c:func:`Py_GetExecPrefix`:
2480+
* :c:func:`!Py_GetExecPrefix`:
24812481
Get :data:`sys.exec_prefix` instead.
2482-
* :c:func:`Py_GetPath`:
2482+
* :c:func:`!Py_GetPath`:
24832483
Get :data:`sys.path` instead.
2484-
* :c:func:`Py_GetPrefix`:
2484+
* :c:func:`!Py_GetPrefix`:
24852485
Get :data:`sys.prefix` instead.
2486-
* :c:func:`Py_GetProgramFullPath`:
2486+
* :c:func:`!Py_GetProgramFullPath`:
24872487
Get :data:`sys.executable` instead.
2488-
* :c:func:`Py_GetProgramName`:
2488+
* :c:func:`!Py_GetProgramName`:
24892489
Get :data:`sys.executable` instead.
2490-
* :c:func:`Py_GetPythonHome`:
2490+
* :c:func:`!Py_GetPythonHome`:
24912491
Get :c:member:`PyConfig.home`
24922492
or the :envvar:`PYTHONHOME` environment variable instead.
24932493

Doc/whatsnew/3.15.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,38 @@ Removed C APIs
169169

170170
* :c:func:`!PyImport_ImportModuleNoBlock`: deprecated alias
171171
of :c:func:`PyImport_ImportModule`.
172+
173+
The following functions are removed in favor of :c:func:`PyConfig_Get`.
174+
The |pythoncapi_compat_project| can be used to get :c:func:`!PyConfig_Get`
175+
on Python 3.13 and older.
176+
177+
* Python initialization functions:
178+
179+
* :c:func:`!Py_GetExecPrefix`:
180+
use :c:func:`PyConfig_Get("base_exec_prefix") <PyConfig_Get>`
181+
(:data:`sys.base_exec_prefix`) instead.
182+
Use :c:func:`PyConfig_Get("exec_prefix") <PyConfig_Get>`
183+
(:data:`sys.exec_prefix`) if :ref:`virtual environments <venv-def>`
184+
need to be handled.
185+
* :c:func:`!Py_GetPath`:
186+
use :c:func:`PyConfig_Get("module_search_paths") <PyConfig_Get>`
187+
(:data:`sys.path`) instead.
188+
* :c:func:`!Py_GetPrefix`:
189+
use :c:func:`PyConfig_Get("base_prefix") <PyConfig_Get>`
190+
(:data:`sys.base_prefix`) instead.
191+
Use :c:func:`PyConfig_Get("prefix") <PyConfig_Get>`
192+
(:data:`sys.prefix`) if :ref:`virtual environments <venv-def>`
193+
need to be handled.
194+
* :c:func:`!Py_GetProgramFullPath`:
195+
use :c:func:`PyConfig_Get("executable") <PyConfig_Get>`
196+
(:data:`sys.executable`) instead.
197+
* :c:func:`!Py_GetProgramName`:
198+
use :c:func:`PyConfig_Get("executable") <PyConfig_Get>`
199+
(:data:`sys.executable`) instead.
200+
* :c:func:`!Py_GetPythonHome`:
201+
use :c:func:`PyConfig_Get("home") <PyConfig_Get>` or the
202+
:envvar:`PYTHONHOME` environment variable instead.
203+
204+
.. |pythoncapi_compat_project| replace:: |pythoncapi_compat_project_link|_
205+
.. |pythoncapi_compat_project_link| replace:: pythoncapi-compat project
206+
.. _pythoncapi_compat_project_link: https://github.com/python/pythoncapi-compat

Doc/whatsnew/3.8.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,8 +1629,8 @@ Build and C API Changes
16291629
(Contributed by Pablo Galindo in :issue:`37221`.)
16301630

16311631
* :c:func:`!Py_SetPath` now sets :data:`sys.executable` to the program full
1632-
path (:c:func:`Py_GetProgramFullPath`) rather than to the program name
1633-
(:c:func:`Py_GetProgramName`).
1632+
path (:c:func:`!Py_GetProgramFullPath`) rather than to the program name
1633+
(:c:func:`!Py_GetProgramName`).
16341634
(Contributed by Victor Stinner in :issue:`38234`.)
16351635

16361636

0 commit comments

Comments
 (0)