Skip to content

Commit 7e4e284

Browse files
authored
PEP 587: Fix a few minor issues (#1087)
* Fix _init_main=0 example: set config._init_main to 0! * Document special builds needed by some speficic options like show_alloc_count. * Specify that preconfiguration only requires command line arguments for the "Python Configuration" (not for "Isolated Configuration").
1 parent fcdd72d commit 7e4e284

File tree

1 file changed

+37
-22
lines changed

1 file changed

+37
-22
lines changed

pep-0587.rst

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,13 @@ and adopted as private APIs for us in the native CPython CLI.
101101
Python Initialization C API
102102
===========================
103103

104-
This PEP proposes to add the following new structures, functions and
105-
macros.
104+
This PEP proposes to add the following new structures and functions.
106105

107106
New structures:
108107

109108
* ``PyConfig``
110-
* ``PyStatus``
111109
* ``PyPreConfig``
110+
* ``PyStatus``
112111
* ``PyWideStringList``
113112

114113
New functions:
@@ -258,12 +257,12 @@ Example using the preinitialization to enable the UTF-8 Mode::
258257
/* ... use Python API here ... */
259258
Py_Finalize();
260259

261-
Function to initialize a pre-configuration:
260+
Function to initialize a preconfiguration:
262261

263262
* ``void PyPreConfig_InitIsolatedConfig(PyPreConfig *preconfig)``
264263
* ``void PyPreConfig_InitPythonConfig(PyPreConfig *preconfig)``
265264

266-
Functions to preinitialization Python:
265+
Functions to preinitialize Python:
267266

268267
* ``PyStatus Py_PreInitialize(const PyPreConfig *preconfig)``
269268
* ``PyStatus Py_PreInitializeFromBytesArgs(const PyPreConfig *preconfig, int argc, char * const *argv)``
@@ -272,7 +271,8 @@ Functions to preinitialization Python:
272271
The caller is responsible to handle exceptions (error or exit) using
273272
``PyStatus_Exception()`` and ``Py_ExitStatusException()``.
274273

275-
If Python is initialized with command line arguments, the command line
274+
For `Python Configuration`_ (``PyPreConfig_InitPythonConfig()``),
275+
if Python is initialized with command line arguments, the command line
276276
arguments must also be passed to preinitialize Python, since they have
277277
an effect on the pre-configuration like encodings. For example, the
278278
``-X utf8`` command line option enables the UTF-8 Mode.
@@ -363,7 +363,7 @@ Example setting the program name::
363363

364364
/* Set the program name. Implicitly preinitialize Python. */
365365
status = PyConfig_SetString(&config, &config.program_name,
366-
L"/path/to/my_program");
366+
L"/path/to/my_program");
367367
if (PyStatus_Exception(status)) {
368368
goto fail;
369369
}
@@ -451,13 +451,16 @@ exceptions (error or exit) using ``PyStatus_Exception()`` and
451451
equal or greater to 2, raise a ``BytesWarning`` exception.
452452
* ``check_hash_pycs_mode`` (``wchar_t*``):
453453
``--check-hash-based-pycs`` command line option value (see PEP 552).
454+
Valid values: ``always``, ``never`` and ``default``. The default value
455+
is ``default``.
454456
* ``configure_c_stdio`` (``int``):
455457
If non-zero, configure C standard streams (``stdio``, ``stdout``,
456458
``stdout``). For example, set their mode to ``O_BINARY`` on Windows.
457459
* ``dev_mode`` (``int``):
458460
Development mode
459461
* ``dump_refs`` (``int``):
460-
If non-zero, dump all objects which are still alive at exit
462+
If non-zero, dump all objects which are still alive at exit.
463+
Require a special Python build with ``Py_REF_DEBUG`` macro defined.
461464
* ``exec_prefix`` (``wchar_t*``):
462465
``sys.exec_prefix``.
463466
* ``executable`` (``wchar_t*``):
@@ -495,17 +498,24 @@ exceptions (error or exit) using ``PyStatus_Exception()`` and
495498
If non-zero, use ``io.FileIO`` instead of ``WindowsConsoleIO`` for
496499
``sys.stdin``, ``sys.stdout`` and ``sys.stderr``.
497500
* ``malloc_stats`` (``int``):
498-
If non-zero, dump memory allocation statistics at exit.
501+
If non-zero, dump statistics on ``pymalloc`` memory allocator at exit.
502+
The option is ignored if Python is built using ``--without-pymalloc``.
499503
* ``pythonpath_env`` (``wchar_t*``):
500-
Module search paths as a string separated by DELIM (usually ``:``).
504+
Module search paths as a string separated by DELIM (usually ``:``
505+
character).
501506
Initialized from ``PYTHONPATH`` environment variable value by default.
502507
* ``module_search_paths_set`` (``int``),
503508
``module_search_paths`` (``PyWideStringList``):
504509
``sys.path``. If ``module_search_paths_set`` is equal to 0, the
505-
``module_search_paths`` is replaced by the function computing the
506-
`Path Configuration`.
510+
``module_search_paths`` is overridden by the function computing the
511+
`Path Configuration`_.
507512
* ``optimization_level`` (``int``):
508-
Compilation optimization level.
513+
Compilation optimization level:
514+
515+
* 0: Peephole optimizer (and ``__debug__`` is set to ``True``)
516+
* 1: Remove assertions, set ``__debug__`` to ``False``
517+
* 2: Strip docstrings
518+
509519
* ``parse_argv`` (``int``):
510520
If non-zero, parse ``argv`` the same way the regular Python command
511521
line arguments, and strip Python arguments from ``argv``: see `Command
@@ -527,15 +537,18 @@ exceptions (error or exit) using ``PyStatus_Exception()`` and
527537
Quiet mode. For example, don't display the copyright and version
528538
messages even in interactive mode.
529539
* ``run_command`` (``wchar_t*``):
530-
``-c COMMAND`` argument.
540+
``python3 -c COMMAND`` argument.
531541
* ``run_filename`` (``wchar_t*``):
532-
``python3 SCRIPT`` argument.
542+
``python3 FILENAME`` argument.
533543
* ``run_module`` (``wchar_t*``):
534544
``python3 -m MODULE`` argument.
535545
* ``show_alloc_count`` (``int``):
536546
Show allocation counts at exit?
547+
Need a special Python build with ``COUNT_ALLOCS`` macro defined.
537548
* ``show_ref_count`` (``int``):
538549
Show total reference count at exit?
550+
Need a debug build of Python (``Py_REF_DEBUG`` macro should be
551+
defined).
539552
* ``site_import`` (``int``):
540553
Import the ``site`` module at startup?
541554
* ``skip_source_first_line`` (``int``):
@@ -617,7 +630,7 @@ configuration, and then override some parameters::
617630

618631
/* Override executable computed by PyConfig_Read() */
619632
status = PyConfig_SetString(&config, &config.executable,
620-
L"/path/to/my_executable");
633+
L"/path/to/my_executable");
621634
if (PyStatus_Exception(status)) {
622635
goto done;
623636
}
@@ -736,8 +749,8 @@ equal to 0, ``module_search_paths`` is overriden and
736749

737750
It is possible to completely ignore the function computing the default
738751
path configuration by setting explicitly all path configuration output
739-
fields listed above. A string is considered as set even if it's an empty
740-
string. ``module_search_paths`` is considered as set if
752+
fields listed above. A string is considered as set even if it is non-empty.
753+
``module_search_paths`` is considered as set if
741754
``module_search_paths_set`` is set to 1. In this case, path
742755
configuration input fields are ignored as well.
743756

@@ -829,7 +842,7 @@ Private provisional API:
829842

830843
No module is imported during the "Core" phase and the ``importlib``
831844
module is not configured: the `Path Configuration`_ is only applied
832-
during the "Main" phase. It allows to customize Python in Python to
845+
during the "Main" phase. It may allow to customize Python in Python to
833846
override or tune the `Path Configuration`_, maybe install a custom
834847
sys.meta_path importer or an import hook, etc.
835848

@@ -840,7 +853,7 @@ after the Core phase and before the Main phase, which is one of the PEP
840853
The "Core" phase is not properly defined: what should be and what should
841854
not be available at this phase is not specified yet. The API is marked
842855
as private and provisional: the API can be modified or even be removed
843-
anytime until a proper public API is design.
856+
anytime until a proper public API is designed.
844857

845858
Example running Python code between "Core" and "Main" initialization
846859
phases::
@@ -856,7 +869,9 @@ phases::
856869
Py_ExitStatusException(status);
857870
}
858871

859-
/* ... set 'config' configuration ... */
872+
config._init_main = 0;
873+
874+
/* ... customize 'config' configuration ... */
860875

861876
status = Py_InitializeFromConfig(&config);
862877
PyConfig_Clear(&config);
@@ -1065,7 +1080,7 @@ Option ``PyConfig`` field
10651080
``-b`` ``bytes_warning++``
10661081
``-B`` ``write_bytecode = 0``
10671082
``-c COMMAND`` ``run_command = COMMAND``
1068-
``--check-hash-based-pycs=MODE`` ``_check_hash_pycs_mode = MODE``
1083+
``--check-hash-based-pycs=MODE`` ``check_hash_pycs_mode = MODE``
10691084
``-d`` ``parser_debug++``
10701085
``-E`` ``use_environment = 0``
10711086
``-i`` ``inspect++`` and ``interactive++``

0 commit comments

Comments
 (0)