diff options
author | Łukasz Langa <lukasz@langa.pl> | 2023-10-14 21:32:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-14 21:32:57 (GMT) |
commit | 84b7e9e3fa67fb9b92088d17839d8235f1cec62e (patch) | |
tree | 662ceaa5e4c9c4fd12695756ef3d0d199f85701d /Doc | |
parent | ab08ff7882b6181fb785eed7410dbf8030aded70 (diff) | |
download | cpython-84b7e9e3fa67fb9b92088d17839d8235f1cec62e.zip cpython-84b7e9e3fa67fb9b92088d17839d8235f1cec62e.tar.gz cpython-84b7e9e3fa67fb9b92088d17839d8235f1cec62e.tar.bz2 |
gh-110722: Add PYTHON_PRESITE to import a module before site.py is run (#110769)
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/c-api/init_config.rst | 21 | ||||
-rw-r--r-- | Doc/using/cmdline.rst | 37 | ||||
-rw-r--r-- | Doc/whatsnew/3.13.rst | 10 |
3 files changed, 61 insertions, 7 deletions
diff --git a/Doc/c-api/init_config.rst b/Doc/c-api/init_config.rst index 0240e25..1d4e0fb 100644 --- a/Doc/c-api/init_config.rst +++ b/Doc/c-api/init_config.rst @@ -716,7 +716,7 @@ PyConfig Set to ``1`` by the :envvar:`PYTHONDUMPREFS` environment variable. - Need a special build of Python with the ``Py_TRACE_REFS`` macro defined: + Needs a special build of Python with the ``Py_TRACE_REFS`` macro defined: see the :option:`configure --with-trace-refs option <--with-trace-refs>`. Default: ``0``. @@ -1048,7 +1048,7 @@ PyConfig Incremented by the :option:`-d` command line option. Set to the :envvar:`PYTHONDEBUG` environment variable value. - Need a :ref:`debug build of Python <debug-build>` (the ``Py_DEBUG`` macro + Needs a :ref:`debug build of Python <debug-build>` (the ``Py_DEBUG`` macro must be defined). Default: ``0``. @@ -1100,6 +1100,7 @@ PyConfig Set by the :option:`-X pycache_prefix=PATH <-X>` command line option and the :envvar:`PYTHONPYCACHEPREFIX` environment variable. + The command-line option takes precedence. If ``NULL``, :data:`sys.pycache_prefix` is set to ``None``. @@ -1143,13 +1144,27 @@ PyConfig Default: ``NULL``. + .. c:member:: wchar_t* run_presite + + ``package.module`` path to module that should be imported before + ``site.py`` is run. + + Set by the :option:`-X presite=package.module <-X>` command-line + option and the :envvar:`PYTHON_PRESITE` environment variable. + The command-line option takes precedence. + + Needs a :ref:`debug build of Python <debug-build>` (the ``Py_DEBUG`` macro + must be defined). + + Default: ``NULL``. + .. c:member:: int show_ref_count Show total reference count at exit (excluding immortal objects)? Set to ``1`` by :option:`-X showrefcount <-X>` command line option. - Need a :ref:`debug build of Python <debug-build>` (the ``Py_REF_DEBUG`` + Needs a :ref:`debug build of Python <debug-build>` (the ``Py_REF_DEBUG`` macro must be defined). Default: ``0``. diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst index b133d2c..4fdfa09 100644 --- a/Doc/using/cmdline.rst +++ b/Doc/using/cmdline.rst @@ -552,6 +552,12 @@ Miscellaneous options This option may be useful for users who need to limit CPU resources of a container system. See also :envvar:`PYTHON_CPU_COUNT`. If *n* is ``default``, nothing is overridden. + * :samp:`-X presite={package.module}` specifies a module that should be + imported before the :mod:`site` module is executed and before the + :mod:`__main__` module exists. Therefore, the imported module isn't + :mod:`__main__`. This can be used to execute code early during Python + initialization. Python needs to be :ref:`built in debug mode <debug-build>` + for this option to exist. See also :envvar:`PYTHON_PRESITE`. It also allows passing arbitrary values and retrieving them through the :data:`sys._xoptions` dictionary. @@ -602,6 +608,9 @@ Miscellaneous options .. versionadded:: 3.13 The ``-X cpu_count`` option. + .. versionadded:: 3.13 + The ``-X presite`` option. + Options you shouldn't use ~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1091,13 +1100,33 @@ Debug-mode variables If set, Python will dump objects and reference counts still alive after shutting down the interpreter. - Need Python configured with the :option:`--with-trace-refs` build option. + Needs Python configured with the :option:`--with-trace-refs` build option. -.. envvar:: PYTHONDUMPREFSFILE=FILENAME +.. envvar:: PYTHONDUMPREFSFILE If set, Python will dump objects and reference counts still alive - after shutting down the interpreter into a file called *FILENAME*. + after shutting down the interpreter into a file under the path given + as the value to this environment variable. - Need Python configured with the :option:`--with-trace-refs` build option. + Needs Python configured with the :option:`--with-trace-refs` build option. .. versionadded:: 3.11 + +.. envvar:: PYTHON_PRESITE + + If this variable is set to a module, that module will be imported + early in the interpreter lifecycle, before the :mod:`site` module is + executed, and before the :mod:`__main__` module is created. + Therefore, the imported module is not treated as :mod:`__main__`. + + This can be used to execute code early during Python initialization. + + To import a submodule, use ``package.module`` as the value, like in + an import statement. + + See also the :option:`-X presite <-X>` command-line option, + which takes precedence over this variable. + + Needs Python configured with the :option:`--with-pydebug` build option. + + .. versionadded:: 3.13 diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index f43ebc4..08e7bea 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -1356,3 +1356,13 @@ removed, although there is currently no date scheduled for their removal. * Remove undocumented ``PY_TIMEOUT_MAX`` constant from the limited C API. (Contributed by Victor Stinner in :gh:`110014`.) + + +Regression Test Changes +======================= + +* Python built with :file:`configure` :option:`--with-pydebug` now + supports a :option:`-X presite=package.module <-X>` command-line + option. If used, it specifies a module that should be imported early + in the lifecycle of the interpreter, before ``site.py`` is executed. + (Contributed by Łukasz Langa in :gh:`110769`.) |