@@ -29,12 +29,6 @@ The following functions can be safely called before Python is initialized:
2929 * :c:func: `PyMem_SetAllocator `
3030 * :c:func: `PyMem_SetupDebugHooks `
3131 * :c:func: `PyObject_SetArenaAllocator `
32- * :c:func: `Py_SetPath `
33- * :c:func: `Py_SetProgramName `
34- * :c:func: `Py_SetPythonHome `
35- * :c:func: `Py_SetStandardStreamEncoding `
36- * :c:func: `PySys_AddWarnOption `
37- * :c:func: `PySys_AddXOption `
3832 * :c:func: `PySys_ResetWarnOptions `
3933
4034* Informative functions:
@@ -332,16 +326,13 @@ Initializing and finalizing the interpreter
332326.. c :function :: void Py_Initialize ()
333327
334328 .. index::
335- single: Py_SetProgramName()
336329 single: PyEval_InitThreads()
337330 single: modules (in module sys)
338331 single: path (in module sys)
339332 pair: module; builtins
340333 pair: module; __main__
341334 pair: module; sys
342335 triple: module; search; path
343- single: PySys_SetArgv()
344- single: PySys_SetArgvEx()
345336 single: Py_FinalizeEx()
346337
347338 Initialize the Python interpreter. In an application embedding Python,
@@ -352,7 +343,9 @@ Initializing and finalizing the interpreter
352343 the table of loaded modules (``sys.modules ``), and creates the fundamental
353344 modules :mod: `builtins `, :mod: `__main__ ` and :mod: `sys `. It also initializes
354345 the module search path (``sys.path ``). It does not set ``sys.argv ``; use
355- :c:func: `PySys_SetArgvEx ` for that. This is a no-op when called for a second time
346+ the new :c:type: `PyConfig ` API of the :ref: `Python Initialization
347+ Configuration <init-config>` for that. This is a no-op when called for a
348+ second time
356349 (without calling :c:func: `Py_FinalizeEx ` first). There is no return value; it is a
357350 fatal error if the initialization fails.
358351
@@ -425,76 +418,9 @@ Process-wide parameters
425418=======================
426419
427420
428- .. c:function:: int Py_SetStandardStreamEncoding(const char *encoding, const char *errors)
429-
430- .. index ::
431- single: Py_Initialize()
432- single: main()
433- triple: stdin; stdout; sdterr
434-
435- This API is kept for backward compatibility: setting
436- :c:member: `PyConfig.stdio_encoding ` and :c:member: `PyConfig.stdio_errors `
437- should be used instead, see :ref: `Python Initialization Configuration
438- <init-config>`.
439-
440- This function should be called before :c:func: `Py_Initialize `, if it is
441- called at all. It specifies which encoding and error handling to use
442- with standard IO, with the same meanings as in :func: `str.encode `.
443-
444- It overrides :envvar: `PYTHONIOENCODING ` values, and allows embedding code
445- to control IO encoding when the environment variable does not work.
446-
447- *encoding * and/or *errors * may be ``NULL `` to use
448- :envvar: `PYTHONIOENCODING ` and/or default values (depending on other
449- settings).
450-
451- Note that :data:`sys.stderr` always uses the "backslashreplace" error
452- handler, regardless of this (or any other) setting.
453-
454- If :c:func:`Py_FinalizeEx` is called, this function will need to be called
455- again in order to affect subsequent calls to :c:func:`Py_Initialize`.
456-
457- Returns ``0`` if successful, a nonzero value on error (e.g. calling after the
458- interpreter has already been initialized).
459-
460- .. versionadded:: 3.4
461-
462- .. deprecated:: 3.11
463-
464-
465- .. c:function:: void Py_SetProgramName(const wchar_t *name)
466-
467- .. index ::
468- single: Py_Initialize()
469- single: main()
470- single: Py_GetPath()
471-
472- This API is kept for backward compatibility: setting
473- :c:member: `PyConfig.program_name ` should be used instead, see :ref: `Python
474- Initialization Configuration <init-config>`.
475-
476- This function should be called before :c:func: `Py_Initialize ` is called for
477- the first time, if it is called at all. It tells the interpreter the value
478- of the ``argv[0] `` argument to the :c:func: `main ` function of the program
479- (converted to wide characters).
480- This is used by :c:func:`Py_GetPath` and some other functions below to find
481- the Python run-time libraries relative to the interpreter executable. The
482- default value is ``'python'``. The argument should point to a
483- zero-terminated wide character string in static storage whose contents will not
484- change for the duration of the program's execution. No code in the Python
485- interpreter will change the contents of this storage.
486-
487- Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
488- :c:expr:`wchar_*` string.
489-
490- .. deprecated:: 3.11
491-
492-
493421.. c:function:: wchar* Py_GetProgramName()
494422
495- .. index:: single: Py_SetProgramName()
496-
497- Return the program name set with :c:func:`Py_SetProgramName`, or the default.
423+ Return the program name set with :c:member:`PyConfig.program_name`, or the default.
498424 The returned string points into static storage; the caller should not modify its
499425 value.
500426
@@ -509,7 +435,7 @@ Process-wide parameters
509435
510436 Return the *prefix* for installed platform-independent files. This is derived
511437 through a number of complicated rules from the program name set with
512- :c:func:`Py_SetProgramName ` and some environment variables; for example, if the
438+ :c:member:`PyConfig.program_name ` and some environment variables; for example, if the
513439 program name is ``'/usr/local/bin/python' ``, the prefix is ``'/usr/local' ``. The
514440 returned string points into static storage; the caller should not modify its
515441 value. This corresponds to the :makevar: `prefix ` variable in the top-level
@@ -528,7 +454,7 @@ Process-wide parameters
528454
529455 Return the *exec-prefix* for installed platform-*dependent* files. This is
530456 derived through a number of complicated rules from the program name set with
531- :c:func:`Py_SetProgramName ` and some environment variables; for example, if the
457+ :c:member:`PyConfig.program_name ` and some environment variables; for example, if the
532458 program name is ``'/usr/local/bin/python' ``, the exec-prefix is
533459 ``'/usr/local' ``. The returned string points into static storage; the caller
534460 should not modify its value. This corresponds to the :makevar: `exec_prefix `
@@ -568,12 +494,11 @@ Process-wide parameters
568494.. c :function :: wchar_t * Py_GetProgramFullPath ()
569495
570496 .. index::
571- single: Py_SetProgramName()
572497 single: executable (in module sys)
573498
574499 Return the full program name of the Python executable; this is computed as a
575500 side-effect of deriving the default module search path from the program name
576- (set by :c:func: ` Py_SetProgramName ` above ). The returned string points into
501+ (set by :c:member: ` PyConfig.program_name ` ). The returned string points into
577502 static storage; the caller should not modify its value. The value is available
578503 to Python code as ``sys.executable ``.
579504
@@ -589,10 +514,9 @@ Process-wide parameters
589514 .. index::
590515 triple: module; search; path
591516 single: path (in module sys)
592- single: Py_SetPath()
593517
594518 Return the default module search path; this is computed from the program name
595- (set by :c:func: ` Py_SetProgramName ` above ) and some environment variables.
519+ (set by :c:member: ` PyConfig.program_name ` ) and some environment variables.
596520 The returned string consists of a series of directory names separated by a
597521 platform dependent delimiter character. The delimiter character is ``':' ``
598522 on Unix and macOS, ``';' `` on Windows. The returned string points into
@@ -610,44 +534,6 @@ Process-wide parameters
610534 It now returns ``NULL `` if called before :c:func: `Py_Initialize `.
611535
612536
613- .. c :function :: void Py_SetPath (const wchar_t *)
614-
615- .. index ::
616- triple: module; search; path
617- single: path (in module sys)
618- single: Py_GetPath()
619-
620- This API is kept for backward compatibility: setting
621- :c:member:`PyConfig.module_search_paths` and
622- :c:member:`PyConfig.module_search_paths_set` should be used instead, see
623- :ref:`Python Initialization Configuration <init-config>`.
624-
625- Set the default module search path. If this function is called before
626- :c:func:`Py_Initialize`, then :c:func:`Py_GetPath` won't attempt to compute a
627- default search path but uses the one provided instead. This is useful if
628- Python is embedded by an application that has full knowledge of the location
629- of all modules. The path components should be separated by the platform
630- dependent delimiter character, which is ``':'`` on Unix and macOS, ``';' ``
631- on Windows.
632-
633- This also causes :data:`sys.executable` to be set to the program
634- full path (see :c:func:`Py_GetProgramFullPath`) and for :data:`sys.prefix` and
635- :data:`sys.exec_prefix` to be empty. It is up to the caller to modify these
636- if required after calling :c:func:`Py_Initialize`.
637-
638- Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
639- :c:expr:`wchar_*` string.
640-
641- The path argument is copied internally, so the caller may free it after the
642- call completes.
643-
644- .. versionchanged:: 3.8
645- The program full path is now used for :data:`sys.executable`, instead
646- of the program name.
647-
648- .. deprecated:: 3.11
649-
650-
651537.. c :function :: const char * Py_GetVersion ()
652538
653539 Return the version of this Python interpreter. This is a string that looks
@@ -718,110 +604,10 @@ Process-wide parameters
718604 ``sys.version``.
719605
720606
721- .. c:function:: void PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath)
722-
723- .. index::
724- single: main()
725- single: Py_FatalError()
726- single: argv (in module sys)
727-
728- This API is kept for backward compatibility: setting
729- :c:member:`PyConfig.argv`, :c:member:`PyConfig.parse_argv` and
730- :c:member:`PyConfig.safe_path` should be used instead, see :ref:`Python
731- Initialization Configuration <init-config>`.
732-
733- Set :data:`sys.argv` based on *argc* and *argv*. These parameters are
734- similar to those passed to the program' s :c:func:`main` function with the
735- difference that the first entry should refer to the script file to be
736- executed rather than the executable hosting the Python interpreter. If there
737- isn't a script that will be run, the first entry in *argv * can be an empty
738- string. If this function fails to initialize :data: `sys.argv `, a fatal
739- condition is signalled using :c:func: `Py_FatalError `.
740-
741- If *updatepath * is zero, this is all the function does. If *updatepath *
742- is non-zero, the function also modifies :data: `sys.path ` according to the
743- following algorithm:
744-
745- - If the name of an existing script is passed in ``argv[0] ``, the absolute
746- path of the directory where the script is located is prepended to
747- :data: `sys.path `.
748- - Otherwise (that is, if *argc * is ``0 `` or ``argv[0] `` doesn't point
749- to an existing file name), an empty string is prepended to
750- :data: `sys.path `, which is the same as prepending the current working
751- directory (``"." ``).
752-
753- Use :c:func: `Py_DecodeLocale ` to decode a bytes string to get a
754- :c:expr: `wchar_* ` string.
755-
756- See also :c:member: `PyConfig.orig_argv ` and :c:member: `PyConfig.argv `
757- members of the :ref: `Python Initialization Configuration <init-config >`.
758-
759- .. note ::
760- It is recommended that applications embedding the Python interpreter
761- for purposes other than executing a single script pass ``0 `` as *updatepath *,
762- and update :data: `sys.path ` themselves if desired.
763- See `CVE-2008-5983 <https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-5983 >`_.
764-
765- On versions before 3.1.3, you can achieve the same effect by manually
766- popping the first :data: `sys.path ` element after having called
767- :c:func: `PySys_SetArgv `, for example using::
768-
769- PyRun_SimpleString("import sys; sys.path.pop(0)\n");
770-
771- .. versionadded :: 3.1.3
772-
773- .. XXX impl. doesn't seem consistent in allowing ``0``/``NULL`` for the params;
774- check w/ Guido.
775-
776- .. deprecated :: 3.11
777-
778-
779- .. c :function :: void PySys_SetArgv (int argc, wchar_t **argv)
780-
781- This API is kept for backward compatibility: setting
782- :c:member: `PyConfig.argv ` and :c:member: `PyConfig.parse_argv ` should be used
783- instead, see :ref: `Python Initialization Configuration <init-config >`.
784-
785- This function works like :c:func: `PySys_SetArgvEx ` with *updatepath * set
786- to ``1 `` unless the :program: `python ` interpreter was started with the
787- :option: `-I `.
788-
789- Use :c:func: `Py_DecodeLocale ` to decode a bytes string to get a
790- :c:expr: `wchar_* ` string.
791-
792- See also :c:member: `PyConfig.orig_argv ` and :c:member: `PyConfig.argv `
793- members of the :ref: `Python Initialization Configuration <init-config >`.
794-
795- .. versionchanged :: 3.4 The *updatepath* value depends on :option:`-I`.
796-
797- .. deprecated :: 3.11
798-
799-
800- .. c :function :: void Py_SetPythonHome (const wchar_t *home)
801-
802- This API is kept for backward compatibility: setting
803- :c:member: `PyConfig.home ` should be used instead, see :ref: `Python
804- Initialization Configuration <init-config>`.
805-
806- Set the default "home" directory, that is, the location of the standard
807- Python libraries. See :envvar: `PYTHONHOME ` for the meaning of the
808- argument string.
809-
810- The argument should point to a zero-terminated character string in static
811- storage whose contents will not change for the duration of the program's
812- execution. No code in the Python interpreter will change the contents of
813- this storage.
814-
815- Use :c:func: `Py_DecodeLocale ` to decode a bytes string to get a
816- :c:expr: `wchar_* ` string.
817-
818- .. deprecated :: 3.11
819-
820-
821607.. c:function:: wchar_t* Py_GetPythonHome()
822608
823- Return the default "home", that is, the value set by a previous call to
824- :c:func:`Py_SetPythonHome `, or the value of the :envvar:`PYTHONHOME`
609+ Return the default " home" , that is, the value set by
610+ :c:member:`PyConfig.home `, or the value of the :envvar:`PYTHONHOME`
825611 environment variable if it is set.
826612
827613 This function should not be called before :c:func:`Py_Initialize`, otherwise
0 commit comments