Skip to content

Commit d518f15

Browse files
committed
Merge branch 'main' of https://github.com/python/cpython
2 parents 8166492 + e371ce1 commit d518f15

24 files changed

+400
-65
lines changed

Doc/c-api/init_config.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,10 +1807,10 @@ PyConfig
18071807
18081808
.. c:member:: wchar_t* run_presite
18091809
1810-
``package.module`` path to module that should be imported before
1811-
``site.py`` is run.
1810+
``module`` or ``module:func`` entry point that should be executed before
1811+
the :mod:`site` module is imported.
18121812
1813-
Set by the :option:`-X presite=package.module <-X>` command-line
1813+
Set by the :option:`-X presite=module:func <-X>` command-line
18141814
option and the :envvar:`PYTHON_PRESITE` environment variable.
18151815
The command-line option takes precedence.
18161816

Doc/using/cmdline.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,13 +654,17 @@ Miscellaneous options
654654

655655
.. versionadded:: 3.13
656656

657-
* :samp:`-X presite={package.module}` specifies a module that should be
658-
imported before the :mod:`site` module is executed and before the
657+
* :samp:`-X presite={module}` or :samp:`-X presite={module:func}` specifies
658+
an entry point that should be executed before the :mod:`site` module is
659+
executed and before the
659660
:mod:`__main__` module exists. Therefore, the imported module isn't
660661
:mod:`__main__`. This can be used to execute code early during Python
661662
initialization. Python needs to be :ref:`built in debug mode <debug-build>`
662663
for this option to exist. See also :envvar:`PYTHON_PRESITE`.
663664

665+
.. versionchanged:: next
666+
Accept also ``module:func`` entry point format.
667+
664668
.. versionadded:: 3.13
665669

666670
* :samp:`-X gil={0,1}` forces the GIL to be disabled or enabled,
@@ -1458,4 +1462,7 @@ Debug-mode variables
14581462

14591463
Needs Python configured with the :option:`--with-pydebug` build option.
14601464

1465+
.. versionchanged:: next
1466+
Accept also ``module:func`` entry point format.
1467+
14611468
.. versionadded:: 3.13

Lib/_pyrepl/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from .types import CharBuffer, CharWidths
1717
from .trace import trace
1818

19+
1920
ANSI_ESCAPE_SEQUENCE = re.compile(r"\x1b\[[ -@]*[A-~]")
2021
ZERO_WIDTH_BRACKET = re.compile(r"\x01.*?\x02")
2122
ZERO_WIDTH_TRANS = str.maketrans({"\x01": "", "\x02": ""})

Lib/configparser.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,15 +613,19 @@ class RawConfigParser(MutableMapping):
613613
\] # ]
614614
"""
615615
_OPT_TMPL = r"""
616-
(?P<option>.*?) # very permissive!
616+
(?P<option> # very permissive!
617+
(?:(?!{delim})\S)* # non-delimiter non-whitespace
618+
(?:\s+(?:(?!{delim})\S)+)*) # optionally more words
617619
\s*(?P<vi>{delim})\s* # any number of space/tab,
618620
# followed by any of the
619621
# allowed delimiters,
620622
# followed by any space/tab
621623
(?P<value>.*)$ # everything up to eol
622624
"""
623625
_OPT_NV_TMPL = r"""
624-
(?P<option>.*?) # very permissive!
626+
(?P<option> # very permissive!
627+
(?:(?!{delim})\S)* # non-delimiter non-whitespace
628+
(?:\s+(?:(?!{delim})\S)+)*) # optionally more words
625629
\s*(?: # any number of space/tab,
626630
(?P<vi>{delim})\s* # optionally followed by
627631
# any of the allowed

Lib/ctypes/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import os as _os
44
import sys as _sys
5-
import sysconfig as _sysconfig
65
import types as _types
76

7+
lazy import sysconfig as _sysconfig
8+
89
from _ctypes import Union, Structure, Array
910
from _ctypes import _Pointer
1011
from _ctypes import CFuncPtr as _CFuncPtr

Lib/ctypes/_layout.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
"""
66

77
import sys
8-
import warnings
98

109
from _ctypes import CField, buffer_info
1110
import ctypes
1211

12+
lazy import warnings
13+
1314
def round_down(n, multiple):
1415
assert n >= 0
1516
assert multiple > 0

Lib/ctypes/util.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import os
2-
import shutil
3-
import subprocess
42
import sys
53

4+
lazy import shutil
5+
lazy import subprocess
6+
67
# find_library(name) returns the pathname of a library, or None.
78
if os.name == "nt":
89

Lib/test/_test_embed_structseq.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,21 @@ def test_sys_funcs(self):
4747
self.check_structseq(type(obj))
4848

4949

50-
try:
51-
unittest.main(
52-
module=(
53-
'__main__'
54-
if __name__ == '__main__'
55-
# Avoiding a circular import:
56-
else sys.modules['test._test_embed_structseq']
50+
def main():
51+
try:
52+
unittest.main(
53+
module=(
54+
'__main__'
55+
if __name__ == '__main__'
56+
# Avoiding a circular import:
57+
else sys.modules['test._test_embed_structseq']
58+
)
5759
)
58-
)
59-
except SystemExit as exc:
60-
if exc.args[0] != 0:
61-
raise
62-
print("Tests passed")
60+
except SystemExit as exc:
61+
if exc.args[0] != 0:
62+
raise
63+
print("Tests passed")
64+
65+
66+
if __name__ == "__main__":
67+
main()

Lib/test/cov.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""A minimal hook for gathering line coverage of the standard library.
22
3-
Designed to be used with -Xpresite= which means:
4-
* it installs itself on import
5-
* it's not imported as `__main__` so can't use the ifmain idiom
3+
Designed to be used with -Xpresite=test.cov:enable which means:
4+
65
* it can't import anything besides `sys` to avoid tainting gathered coverage
76
* filenames are not normalized
87
@@ -45,4 +44,5 @@ def disable():
4544
mon.free_tool_id(mon.COVERAGE_ID)
4645

4746

48-
enable()
47+
if __name__ == "__main__":
48+
enable()

Lib/test/libregrtest/runtests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def create_python_cmd(self) -> list[str]:
159159
if '-u' not in python_opts:
160160
cmd.append('-u') # Unbuffered stdout and stderr
161161
if self.coverage:
162-
cmd.append("-Xpresite=test.cov")
162+
cmd.append("-Xpresite=test.cov:enable")
163163
return cmd
164164

165165
def bisect_cmd_args(self) -> list[str]:

0 commit comments

Comments
 (0)