Skip to content

Commit 0fc0183

Browse files
ambvclaude
andauthored
[3.11] Fix Windows build regen with Python 3.15 as the host Python (#160621)
The windows-2022 GitHub runner image no longer ships Python 3.10, so PCbuild/find_python.bat fell through to NuGet and installed the latest pythonx86 package, which is now 3.15.1. Python 3.15 removed Loader.load_module(), which Python/makeopcodetargets.py used to import Lib/opcode.py, so the _RegenOpcodes target failed and broke every Windows CI build on this branch. Load Lib/opcode.py through importlib.util instead, and extend the py.exe search list in find_python.bat up to 3.14 so the build picks up the runner's preinstalled Python rather than whatever NuGet considers latest. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
1 parent e4f63e6 commit 0fc0183

2 files changed

Lines changed: 11 additions & 19 deletions

File tree

‎PCbuild/find_python.bat‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
@if NOT "%HOST_PYTHON%"=="" @%HOST_PYTHON% -Ec "import sys; assert sys.version_info[:2] >= (3, 9)" >nul 2>nul && (set PYTHON="%HOST_PYTHON%") && (set _Py_Python_Source=found as HOST_PYTHON) && goto :found
4343

4444
@rem If py.exe finds a recent enough version, use that one
45-
@for %%p in (3.10 3.9) do @py -%%p -EV >nul 2>&1 && (set PYTHON=py -%%p) && (set _Py_Python_Source=found %%p with py.exe) && goto :found
45+
@for %%p in (3.14 3.13 3.12 3.11 3.10 3.9) do @py -%%p -EV >nul 2>&1 && (set PYTHON=py -%%p) && (set _Py_Python_Source=found %%p with py.exe) && goto :found
4646

4747
@if NOT exist "%_Py_EXTERNALS_DIR%" mkdir "%_Py_EXTERNALS_DIR%"
4848
@set _Py_NUGET=%NUGET%

‎Python/makeopcodetargets.py‎

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,20 @@
33
(for compilers supporting computed gotos or "labels-as-values", such as gcc).
44
"""
55

6+
import importlib.util
67
import os
78
import sys
89

910

10-
try:
11-
from importlib.machinery import SourceFileLoader
12-
except ImportError:
13-
import imp
14-
15-
def find_module(modname):
16-
"""Finds and returns a module in the local dist/checkout.
17-
"""
18-
modpath = os.path.join(
19-
os.path.dirname(os.path.dirname(__file__)), "Lib")
20-
return imp.load_module(modname, *imp.find_module(modname, [modpath]))
21-
else:
22-
def find_module(modname):
23-
"""Finds and returns a module in the local dist/checkout.
24-
"""
25-
modpath = os.path.join(
26-
os.path.dirname(os.path.dirname(__file__)), "Lib", modname + ".py")
27-
return SourceFileLoader(modname, modpath).load_module()
11+
def find_module(modname):
12+
"""Finds and returns a module in the local dist/checkout.
13+
"""
14+
modpath = os.path.join(
15+
os.path.dirname(os.path.dirname(__file__)), "Lib", modname + ".py")
16+
spec = importlib.util.spec_from_file_location(modname, modpath)
17+
module = importlib.util.module_from_spec(spec)
18+
spec.loader.exec_module(module)
19+
return module
2820

2921

3022
def write_contents(f):

0 commit comments

Comments
 (0)