Skip to content

Commit 88feaec

Browse files
authored
bpo-38234: Complete init config documentation (GH-16404)
1 parent 8bf39b6 commit 88feaec

File tree

1 file changed

+37
-23
lines changed

1 file changed

+37
-23
lines changed

Doc/c-api/init_config.rst

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ PyPreConfig
241241
locale to decide if it should be coerced.
242242
243243
.. c:member:: int coerce_c_locale_warn
244+
244245
If non-zero, emit a warning if the C locale is coerced.
245246
246247
.. c:member:: int dev_mode
@@ -300,7 +301,7 @@ For :ref:`Python Configuration <init-python-config>`
300301
(:c:func:`PyPreConfig_InitPythonConfig`), if Python is initialized with
301302
command line arguments, the command line arguments must also be passed to
302303
preinitialize Python, since they have an effect on the pre-configuration
303-
like encodings. For example, the :option:`-X` ``utf8`` command line option
304+
like encodings. For example, the :option:`-X utf8 <-X>` command line option
304305
enables the UTF-8 Mode.
305306
306307
``PyMem_SetAllocator()`` can be called after :c:func:`Py_PreInitialize` and
@@ -464,7 +465,7 @@ PyConfig
464465
465466
.. c:member:: int dev_mode
466467
467-
Development mode: see :option:`-X` ``dev``.
468+
Development mode: see :option:`-X dev <-X>`.
468469
469470
.. c:member:: int dump_refs
470471
@@ -482,7 +483,7 @@ PyConfig
482483
483484
.. c:member:: int faulthandler
484485
485-
If non-zero, call :func:`faulthandler.enable`.
486+
If non-zero, call :func:`faulthandler.enable` at startup.
486487
487488
.. c:member:: wchar_t* filesystem_encoding
488489
@@ -504,6 +505,9 @@ PyConfig
504505
505506
Python home directory.
506507
508+
Initialized from :envvar:`PYTHONHOME` environment variable value by
509+
default.
510+
507511
.. c:member:: int import_time
508512
509513
If non-zero, profile import time.
@@ -561,7 +565,7 @@ PyConfig
561565
562566
:data:`sys.path`. If :c:member:`~PyConfig.module_search_paths_set` is
563567
equal to 0, the :c:member:`~PyConfig.module_search_paths` is overridden
564-
by the function computing the :ref:`Path Configuration
568+
by the function calculating the :ref:`Path Configuration
565569
<init-path-config>`.
566570
567571
.. c:member:: int optimization_level
@@ -586,49 +590,56 @@ PyConfig
586590
587591
.. c:member:: int pathconfig_warnings
588592
589-
If equal to 0, suppress warnings when computing the path configuration
590-
(Unix only, Windows does not log any warning). Otherwise, warnings are
591-
written into ``stderr``.
593+
If equal to 0, suppress warnings when calculating the :ref:`Path
594+
Configuration <init-path-config>` (Unix only, Windows does not log any
595+
warning). Otherwise, warnings are written into ``stderr``.
592596
593597
.. c:member:: wchar_t* prefix
594598
595599
:data:`sys.prefix`.
596600
597601
.. c:member:: wchar_t* program_name
598602
599-
Program name.
603+
Program name. Used to initialize :c:member:`~PyConfig.executable`, and in
604+
early error messages.
600605
601606
.. c:member:: wchar_t* pycache_prefix
602607
603-
``.pyc`` cache prefix.
608+
:data:`sys.pycache_prefix`: ``.pyc`` cache prefix.
609+
610+
If NULL, :data:`sys.pycache_prefix` is set to ``None``.
604611
605612
.. c:member:: int quiet
606613
607614
Quiet mode. For example, don't display the copyright and version messages
608-
even in interactive mode.
615+
in interactive mode.
609616
610617
.. c:member:: wchar_t* run_command
611618
612-
``python3 -c COMMAND`` argument.
619+
``python3 -c COMMAND`` argument. Used by :c:func:`Py_RunMain`.
613620
614621
.. c:member:: wchar_t* run_filename
615622
616-
``python3 FILENAME`` argument.
623+
``python3 FILENAME`` argument. Used by :c:func:`Py_RunMain`.
617624
618625
.. c:member:: wchar_t* run_module
619626
620-
``python3 -m MODULE`` argument.
627+
``python3 -m MODULE`` argument. Used by :c:func:`Py_RunMain`.
621628
622629
.. c:member:: int show_alloc_count
623630
624631
Show allocation counts at exit?
625632
633+
Set to 1 by :option:`-X showalloccount <-X>` command line option.
634+
626635
Need a special Python build with ``COUNT_ALLOCS`` macro defined.
627636
628637
.. c:member:: int show_ref_count
629638
630639
Show total reference count at exit?
631640
641+
Set to 1 by :option:`-X showrefcount <-X>` command line option.
642+
632643
Need a debug build of Python (``Py_REF_DEBUG`` macro must be defined).
633644
634645
.. c:member:: int site_import
@@ -647,7 +658,7 @@ PyConfig
647658
648659
.. c:member:: int tracemalloc
649660
650-
If non-zero, call :func:`tracemalloc.start`.
661+
If non-zero, call :func:`tracemalloc.start` at startup.
651662
652663
.. c:member:: int use_environment
653664
@@ -669,6 +680,9 @@ PyConfig
669680
670681
If non-zero, write ``.pyc`` files.
671682
683+
:data:`sys.dont_write_bytecode` is initialized to the inverted value of
684+
:c:member:`~PyConfig.write_bytecode`.
685+
672686
.. c:member:: PyWideStringList xoptions
673687
674688
:data:`sys._xoptions`.
@@ -694,8 +708,8 @@ Function to initialize Python:
694708
The caller is responsible to handle exceptions (error or exit) using
695709
:c:func:`PyStatus_Exception` and :c:func:`Py_ExitStatusException`.
696710
697-
``PyImport_FrozenModules``, ``PyImport_AppendInittab()`` or
698-
``PyImport_ExtendInittab()`` is used: they must be set or called after Python
711+
If ``PyImport_FrozenModules``, ``PyImport_AppendInittab()`` or
712+
``PyImport_ExtendInittab()`` are used, they must be set or called after Python
699713
preinitialization and before the Python initialization.
700714
701715
Example setting the program name::
@@ -760,7 +774,7 @@ configuration, and then override some parameters::
760774
761775
/* Append our custom search path to sys.path */
762776
status = PyWideStringList_Append(&config.module_search_paths,
763-
L"/path/to/more/modules");
777+
L"/path/to/more/modules");
764778
if (PyStatus_Exception(status)) {
765779
goto done;
766780
}
@@ -791,9 +805,9 @@ isolate Python from the system. For example, to embed Python into an
791805
application.
792806
793807
This configuration ignores global configuration variables, environments
794-
variables and command line arguments (:c:member:`PyConfig.argv` is not parsed).
795-
The C standard streams (ex: ``stdout``) and the LC_CTYPE locale are left
796-
unchanged by default.
808+
variables, command line arguments (:c:member:`PyConfig.argv` is not parsed)
809+
and user site directory. The C standard streams (ex: ``stdout``) and the
810+
LC_CTYPE locale are left unchanged. Signal handlers are not installed.
797811
798812
Configuration files are still used with this configuration. Set the
799813
:ref:`Path Configuration <init-path-config>` ("output fields") to ignore these
@@ -970,7 +984,7 @@ initialization, the core feature of the :pep:`432`:
970984
* Builtin exceptions;
971985
* Builtin and frozen modules;
972986
* The :mod:`sys` module is only partially initialized
973-
(ex: :data:`sys.path` doesn't exist yet);
987+
(ex: :data:`sys.path` doesn't exist yet).
974988
975989
* "Main" initialization phase, Python is fully initialized:
976990
@@ -996,9 +1010,9 @@ No module is imported during the "Core" phase and the ``importlib`` module is
9961010
not configured: the :ref:`Path Configuration <init-path-config>` is only
9971011
applied during the "Main" phase. It may allow to customize Python in Python to
9981012
override or tune the :ref:`Path Configuration <init-path-config>`, maybe
999-
install a custom sys.meta_path importer or an import hook, etc.
1013+
install a custom :data:`sys.meta_path` importer or an import hook, etc.
10001014
1001-
It may become possible to compute the :ref:`Path Configuration
1015+
It may become possible to calculatin the :ref:`Path Configuration
10021016
<init-path-config>` in Python, after the Core phase and before the Main phase,
10031017
which is one of the :pep:`432` motivation.
10041018

0 commit comments

Comments
 (0)