Skip to content

Commit bb01cf0

Browse files
authored
Merge branch 'main' into Optimize-_MATCH_CLASS
2 parents d1f507a + 6acaf65 commit bb01cf0

26 files changed

+674
-551
lines changed

.github/workflows/reusable-wasi.yml

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ jobs:
1313
timeout-minutes: 60
1414
env:
1515
WASMTIME_VERSION: 38.0.3
16-
WASI_SDK_VERSION: 30
17-
WASI_SDK_PATH: /opt/wasi-sdk
1816
CROSS_BUILD_PYTHON: cross-build/build
1917
CROSS_BUILD_WASI: cross-build/wasm32-wasip1
2018
steps:
@@ -26,18 +24,23 @@ jobs:
2624
uses: bytecodealliance/actions/wasmtime/setup@v1
2725
with:
2826
version: ${{ env.WASMTIME_VERSION }}
29-
- name: "Restore WASI SDK"
30-
id: cache-wasi-sdk
31-
uses: actions/cache@v5
32-
with:
33-
path: ${{ env.WASI_SDK_PATH }}
34-
key: ${{ runner.os }}-wasi-sdk-${{ env.WASI_SDK_VERSION }}
35-
- name: "Install WASI SDK" # Hard-coded to x64.
36-
if: steps.cache-wasi-sdk.outputs.cache-hit != 'true'
27+
- name: "Read WASI SDK version"
28+
id: wasi-sdk-version
3729
run: |
38-
mkdir "${WASI_SDK_PATH}" && \
39-
curl -s -S --location "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VERSION}/wasi-sdk-${WASI_SDK_VERSION}.0-arm64-linux.tar.gz" | \
40-
tar --strip-components 1 --directory "${WASI_SDK_PATH}" --extract --gunzip
30+
import tomllib
31+
from pathlib import Path
32+
import os
33+
config = tomllib.loads(Path("Platforms/WASI/config.toml").read_text())
34+
version = config["targets"]["wasi-sdk"]
35+
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
36+
f.write(f"version={version}\n")
37+
shell: python
38+
- name: "Install WASI SDK"
39+
id: install-wasi-sdk
40+
uses: bytecodealliance/setup-wasi-sdk-action@b2de090b44eb70013ee96b393727d473b35e1728
41+
with:
42+
version: ${{ steps.wasi-sdk-version.outputs.version }}
43+
add-to-path: false
4144
- name: "Install Python"
4245
uses: actions/setup-python@v6
4346
with:
@@ -51,6 +54,8 @@ jobs:
5154
- name: "Configure host"
5255
# `--with-pydebug` inferred from configure-build-python
5356
run: python3 Platforms/WASI configure-host -- --config-cache
57+
env:
58+
WASI_SDK_PATH: ${{ steps.install-wasi-sdk.outputs.wasi-sdk-path }}
5459
- name: "Make host"
5560
run: python3 Platforms/WASI make-host
5661
- name: "Display build info"

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ repos:
1414
name: Run Ruff (lint) on Lib/test/
1515
args: [--exit-non-zero-on-fix]
1616
files: ^Lib/test/
17+
- id: ruff-check
18+
name: Run Ruff (lint) on Platforms/WASI/
19+
args: [--exit-non-zero-on-fix, --config=Platforms/WASI/.ruff.toml]
20+
files: ^Platforms/WASI/
1721
- id: ruff-check
1822
name: Run Ruff (lint) on Tools/build/
1923
args: [--exit-non-zero-on-fix, --config=Tools/build/.ruff.toml]
@@ -42,6 +46,10 @@ repos:
4246
name: Run Ruff (format) on Doc/
4347
args: [--exit-non-zero-on-fix]
4448
files: ^Doc/
49+
- id: ruff-format
50+
name: Run Ruff (format) on Platforms/WASI/
51+
args: [--exit-non-zero-on-fix, --config=Platforms/WASI/.ruff.toml]
52+
files: ^Platforms/WASI/
4553
- id: ruff-format
4654
name: Run Ruff (format) on Tools/build/check_warnings.py
4755
args: [--exit-non-zero-on-fix, --config=Tools/build/.ruff.toml]

Include/internal/pycore_dict.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ extern void _PyDict_Clear_LockHeld(PyObject *op);
160160
PyAPI_FUNC(void) _PyDict_EnsureSharedOnRead(PyDictObject *mp);
161161
#endif
162162

163+
extern PyObject* _PyDict_CopyAsDict(PyObject *op);
164+
163165
#define DKIX_EMPTY (-1)
164166
#define DKIX_DUMMY (-2) /* Used internally */
165167
#define DKIX_ERROR (-3)

Include/internal/pycore_interp_structs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ struct _py_func_state {
496496

497497
/* For now we hard-code this to a value for which we are confident
498498
all the static builtin types will fit (for all builds). */
499-
#define _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES 201
499+
#define _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES 202
500500
#define _Py_MAX_MANAGED_STATIC_EXT_TYPES 10
501501
#define _Py_MAX_MANAGED_STATIC_TYPES \
502502
(_Py_MAX_MANAGED_STATIC_BUILTIN_TYPES + _Py_MAX_MANAGED_STATIC_EXT_TYPES)

Include/internal/pycore_typeobject.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ PyAPI_FUNC(PyObject *) _PyType_LookupSubclasses(PyTypeObject *);
9696
PyAPI_FUNC(PyObject *) _PyType_InitSubclasses(PyTypeObject *);
9797

9898
extern PyObject * _PyType_GetBases(PyTypeObject *type);
99-
extern PyObject * _PyType_GetMRO(PyTypeObject *type);
10099
extern PyObject* _PyType_GetSubclasses(PyTypeObject *);
101100
extern int _PyType_HasSubclasses(PyTypeObject *);
102101

Lib/importlib/_bootstrap_external.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ def get_filename(self, fullname):
918918

919919
def get_data(self, path):
920920
"""Return the data from path as raw bytes."""
921-
if isinstance(self, (SourceLoader, ExtensionFileLoader)):
921+
if isinstance(self, (SourceLoader, SourcelessFileLoader, ExtensionFileLoader)):
922922
with _io.open_code(str(path)) as file:
923923
return file.read()
924924
else:

Lib/test/test_capi/test_dict.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,18 @@ def test_dict_copy(self):
9898
# Test PyDict_Copy()
9999
copy = _testlimitedcapi.dict_copy
100100
for dict_type in ANYDICT_TYPES:
101-
if issubclass(dict_type, frozendict):
102-
expected_type = frozendict
103-
else:
104-
expected_type = dict
105101
dct = dict_type({1: 2})
106102
dct_copy = copy(dct)
107-
self.assertIs(type(dct_copy), expected_type)
108-
self.assertEqual(dct_copy, dct)
103+
if dict_type == frozendict:
104+
expected_type = frozendict
105+
self.assertIs(dct_copy, dct)
106+
else:
107+
if issubclass(dict_type, frozendict):
108+
expected_type = frozendict
109+
else:
110+
expected_type = dict
111+
self.assertIs(type(dct_copy), expected_type)
112+
self.assertEqual(dct_copy, dct)
109113

110114
for test_type in NOT_ANYDICT_TYPES + OTHER_TYPES:
111115
self.assertRaises(SystemError, copy, test_type())

Lib/test/test_gdb/test_pretty_print.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,14 @@ def test_dicts(self):
8282
self.assertGdbRepr({})
8383
self.assertGdbRepr({'foo': 'bar'}, "{'foo': 'bar'}")
8484
# Python preserves insertion order since 3.6
85-
self.assertGdbRepr({'foo': 'bar', 'douglas': 42}, "{'foo': 'bar', 'douglas': 42}")
85+
self.assertGdbRepr({'foo': 'bar', 'douglas': 42},
86+
"{'foo': 'bar', 'douglas': 42}")
87+
88+
# frozendict
89+
self.assertGdbRepr(frozendict(),
90+
"frozendict({})")
91+
self.assertGdbRepr(frozendict({'foo': 'bar', 'douglas': 42}),
92+
"frozendict({'foo': 'bar', 'douglas': 42})")
8693

8794
def test_lists(self):
8895
'Verify the pretty-printing of lists'

Lib/test/test_launcher.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ def run_py(self, args, env=None, allow_fail=False, expect_returncode=0, argv=Non
227227
"PYLAUNCHER_LIMIT_TO_COMPANY": "",
228228
**{k.upper(): v for k, v in (env or {}).items()},
229229
}
230+
if ini_dir := getattr(self, '_ini_dir', None):
231+
env.setdefault("_PYLAUNCHER_INIDIR", ini_dir)
230232
if not argv:
231233
argv = [self.py_exe, *args]
232234
with subprocess.Popen(
@@ -262,11 +264,14 @@ def run_py(self, args, env=None, allow_fail=False, expect_returncode=0, argv=Non
262264
return data
263265

264266
def py_ini(self, content):
265-
local_appdata = os.environ.get("LOCALAPPDATA")
266-
if not local_appdata:
267-
raise unittest.SkipTest("LOCALAPPDATA environment variable is "
268-
"missing or empty")
269-
return PreservePyIni(Path(local_appdata) / "py.ini", content)
267+
ini_dir = getattr(self, '_ini_dir', None)
268+
if not ini_dir:
269+
local_appdata = os.environ.get("LOCALAPPDATA")
270+
if not local_appdata:
271+
raise unittest.SkipTest("LOCALAPPDATA environment variable is "
272+
"missing or empty")
273+
ini_dir = local_appdata
274+
return PreservePyIni(Path(ini_dir) / "py.ini", content)
270275

271276
@contextlib.contextmanager
272277
def script(self, content, encoding="utf-8"):
@@ -302,6 +307,8 @@ def setUpClass(cls):
302307
p = subprocess.check_output("reg query HKCU\\Software\\Python /s")
303308
#print(p.decode('mbcs'))
304309

310+
cls._ini_dir = tempfile.mkdtemp()
311+
cls.addClassCleanup(shutil.rmtree, cls._ini_dir, ignore_errors=True)
305312

306313
@classmethod
307314
def tearDownClass(cls):

Lib/test/test_tools/test_compute_changes.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
from pathlib import Path
77
from unittest.mock import patch
88

9-
from test.test_tools import skip_if_missing, imports_under_tool
9+
from test.support import os_helper
10+
from test.test_tools import basepath, skip_if_missing, imports_under_tool
1011

1112
skip_if_missing("build")
1213

@@ -15,6 +16,7 @@
1516
compute_changes = importlib.import_module("compute-changes")
1617

1718
process_changed_files = compute_changes.process_changed_files
19+
is_fuzzable_library_file = compute_changes.is_fuzzable_library_file
1820
Outputs = compute_changes.Outputs
1921
ANDROID_DIRS = compute_changes.ANDROID_DIRS
2022
IOS_DIRS = compute_changes.IOS_DIRS
@@ -45,16 +47,16 @@ def test_docs(self):
4547
self.assertFalse(result.run_tests)
4648

4749
def test_ci_fuzz_stdlib(self):
48-
for p in LIBRARY_FUZZER_PATHS:
49-
with self.subTest(p=p):
50-
if p.is_dir():
51-
f = p / "file"
52-
elif p.is_file():
53-
f = p
54-
else:
55-
continue
56-
result = process_changed_files({f})
57-
self.assertTrue(result.run_ci_fuzz_stdlib)
50+
with os_helper.change_cwd(basepath):
51+
for p in LIBRARY_FUZZER_PATHS:
52+
with self.subTest(p=p):
53+
if p.is_dir():
54+
f = p / "file"
55+
elif p.is_file():
56+
f = p
57+
result = process_changed_files({f})
58+
self.assertTrue(result.run_ci_fuzz_stdlib)
59+
self.assertTrue(is_fuzzable_library_file(f))
5860

5961
def test_android(self):
6062
for d in ANDROID_DIRS:

0 commit comments

Comments
 (0)