Skip to content

Commit cbd9b30

Browse files
authored
Update compileall from 3.13.5 (#5914)
1 parent 5985ec8 commit cbd9b30

File tree

4 files changed

+1244
-10
lines changed

4 files changed

+1244
-10
lines changed

Lib/compileall.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,15 @@ def compile_dir(dir, maxlevels=None, ddir=None, force=False,
9797
files = _walk_dir(dir, quiet=quiet, maxlevels=maxlevels)
9898
success = True
9999
if workers != 1 and ProcessPoolExecutor is not None:
100+
import multiprocessing
101+
if multiprocessing.get_start_method() == 'fork':
102+
mp_context = multiprocessing.get_context('forkserver')
103+
else:
104+
mp_context = None
100105
# If workers == 0, let ProcessPoolExecutor choose
101106
workers = workers or None
102-
with ProcessPoolExecutor(max_workers=workers) as executor:
107+
with ProcessPoolExecutor(max_workers=workers,
108+
mp_context=mp_context) as executor:
103109
results = executor.map(partial(compile_file,
104110
ddir=ddir, force=force,
105111
rx=rx, quiet=quiet,
@@ -110,7 +116,8 @@ def compile_dir(dir, maxlevels=None, ddir=None, force=False,
110116
prependdir=prependdir,
111117
limit_sl_dest=limit_sl_dest,
112118
hardlink_dupes=hardlink_dupes),
113-
files)
119+
files,
120+
chunksize=4)
114121
success = min(results, default=True)
115122
else:
116123
for file in files:
@@ -166,13 +173,13 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0,
166173
if stripdir is not None:
167174
fullname_parts = fullname.split(os.path.sep)
168175
stripdir_parts = stripdir.split(os.path.sep)
169-
ddir_parts = list(fullname_parts)
170-
171-
for spart, opart in zip(stripdir_parts, fullname_parts):
172-
if spart == opart:
173-
ddir_parts.remove(spart)
174176

175-
dfile = os.path.join(*ddir_parts)
177+
if stripdir_parts != fullname_parts[:len(stripdir_parts)]:
178+
if quiet < 2:
179+
print("The stripdir path {!r} is not a valid prefix for "
180+
"source path {!r}; ignoring".format(stripdir, fullname))
181+
else:
182+
dfile = os.path.join(*fullname_parts[len(stripdir_parts):])
176183

177184
if prependdir is not None:
178185
if dfile is None:

Lib/test/support/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2601,6 +2601,30 @@ def adjust_int_max_str_digits(max_digits):
26012601
'skipped on s390x')
26022602
HAVE_ASAN_FORK_BUG = check_sanitizer(address=True)
26032603

2604+
# From Cpython 3.13.5
2605+
@contextlib.contextmanager
2606+
def no_color():
2607+
import _colorize
2608+
from .os_helper import EnvironmentVarGuard
2609+
2610+
with (
2611+
swap_attr(_colorize, "can_colorize", lambda file=None: False),
2612+
EnvironmentVarGuard() as env,
2613+
):
2614+
env.unset("FORCE_COLOR", "NO_COLOR", "PYTHON_COLORS")
2615+
env.set("NO_COLOR", "1")
2616+
yield
2617+
2618+
# From Cpython 3.13.5
2619+
def force_not_colorized(func):
2620+
"""Force the terminal not to be colorized."""
2621+
@functools.wraps(func)
2622+
def wrapper(*args, **kwargs):
2623+
with no_color():
2624+
return func(*args, **kwargs)
2625+
return wrapper
2626+
2627+
26042628
# From python 3.12.8
26052629
class BrokenIter:
26062630
def __init__(self, init_raises=False, next_raises=False, iter_raises=False):

Lib/test/support/os_helper.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import unittest
1111
import warnings
1212

13+
# From CPython 3.13.5
14+
from test import support
15+
1316

1417
# Filename used for testing
1518
TESTFN_ASCII = '@test'
@@ -196,6 +199,26 @@ def skip_unless_symlink(test):
196199
return test if ok else unittest.skip(msg)(test)
197200

198201

202+
# From CPython 3.13.5
203+
_can_hardlink = None
204+
205+
# From CPython 3.13.5
206+
def can_hardlink():
207+
global _can_hardlink
208+
if _can_hardlink is None:
209+
# Android blocks hard links using SELinux
210+
# (https://stackoverflow.com/q/32365690).
211+
_can_hardlink = hasattr(os, "link") and not support.is_android
212+
return _can_hardlink
213+
214+
215+
# From CPython 3.13.5
216+
def skip_unless_hardlink(test):
217+
ok = can_hardlink()
218+
msg = "requires hardlink support"
219+
return test if ok else unittest.skip(msg)(test)
220+
221+
199222
_can_xattr = None
200223

201224

@@ -699,8 +722,11 @@ def __len__(self):
699722
def set(self, envvar, value):
700723
self[envvar] = value
701724

702-
def unset(self, envvar):
703-
del self[envvar]
725+
# From CPython 3.13.5
726+
def unset(self, envvar, /, *envvars):
727+
"""Unset one or more environment variables."""
728+
for ev in (envvar, *envvars):
729+
del self[ev]
704730

705731
def copy(self):
706732
# We do what os.environ.copy() does.

0 commit comments

Comments
 (0)