Skip to content

Commit e401c28

Browse files
authored
Update to build on Python 3.15rc1 (#397)
This includes a fairly fragile hack to work around an issue in 3.15.0rc1. It will hopefully be removed for a 3.15.0rc2 build.
1 parent 0e7ea19 commit e401c28

7 files changed

Lines changed: 44 additions & 16 deletions

File tree

.github/workflows/build.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,30 @@ jobs:
3333
}
3434
shell: powershell
3535

36-
#- name: Set up Python 3.14
36+
#- name: Set up Python 3.15
3737
# uses: actions/setup-python@v5
3838
# with:
39-
# python-version: 3.14-dev
39+
# python-version: 3.15-dev
4040

4141
# We move faster than GitHub's Python runtimes, so use NuGet instead
4242
# One day we can use ourselves to download Python, but not yet...
4343
- name: Set up NuGet
4444
uses: nuget/setup-nuget@b26b823c478ee115be5c9403e62c90b0bf943843 # v3.1.0
4545

46-
- name: Set up Python 3.14.6
46+
- name: Set up Python 3.15.0rc1
4747
run: |
48-
nuget install python -Version 3.14.6 -x -o .
48+
nuget install python -Version 3.15.0-rc1 -x -o .
4949
$py = Get-Item python\tools
5050
Write-Host "Adding $py to PATH"
5151
"$py" | Out-File $env:GITHUB_PATH -Encoding UTF8 -Append
5252
working-directory: ${{ runner.temp }}
5353

54-
- name: Check Python version is 3.14.6
54+
- name: Check Python version is 3.15.0rc1
5555
run: >
5656
python -c "import sys;
5757
print(sys.version);
5858
print(sys.executable);
59-
sys.exit(0 if sys.version_info[:5] == (3, 14, 6, 'final', 0) else 1)"
59+
sys.exit(0 if sys.version_info[:5] == (3, 15, 0, 'candidate', 1) else 1)"
6060
6161
- name: Install build dependencies
6262
run: python -m pip install "pymsbuild==1.2.2"

_msbuild.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
DLL_NAME = "python{0.major}{0.minor}".format(sys.version_info)
88
VER_NUM = "{0.major}.{0.minor}.{0.micro}".format(sys.version_info)
9-
EMBED_URL = f"https://www.python.org/ftp/python/{VER_NUM}/python-{VER_NUM}-embed-amd64.zip"
9+
if sys.version_info.releaselevel == "candidate":
10+
VER_NUM_RC = f"rc{sys.version_info.serial}"
11+
else:
12+
VER_NUM_RC = ""
13+
EMBED_URL = f"https://www.python.org/ftp/python/{VER_NUM}/python-{VER_NUM}{VER_NUM_RC}-embed-amd64.zip"
1014

1115
def can_embed(tag):
1216
"""Return False if tag doesn't match DLL_NAME and EMBED_URL.

ci/release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,19 @@ stages:
9595
displayName: 'Install Nuget'
9696

9797
- powershell: |
98-
nuget install python -Version 3.14.6 -x -noninteractive -o host_python
98+
nuget install python -Version 3.15.0-rc1 -x -noninteractive -o host_python
9999
$py = Get-Item host_python\python\tools
100100
Write-Host "Adding $py to PATH"
101101
Write-Host "##vso[task.prependpath]$py"
102-
displayName: Set up Python 3.14.6
102+
displayName: Set up Python 3.15.0rc1
103103
workingDirectory: $(Build.BinariesDirectory)
104104
105105
- powershell: >
106106
python -c "import sys;
107107
print(sys.version);
108108
print(sys.executable);
109-
sys.exit(0 if sys.version_info[:5] == (3, 14, 6, 'final', 0) else 1)"
110-
displayName: Check Python version is 3.14.6
109+
sys.exit(0 if sys.version_info[:5] == (3, 15, 0, 'candidate', 1) else 1)"
110+
displayName: Check Python version is 3.15.0rc1
111111
112112
- powershell: |
113113
python -m pip install "pymsbuild==1.2.2"

src/manage/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
################################################################################
2+
# HACK: Work around gh-148750 in 3.15
3+
# In short, encodings is now partially frozen, which means its submodules can
4+
# only be loaded if they are also frozen or if they are in their default
5+
# location relative to the executable. For embedded runtimes, this is not true,
6+
# so we need to patch the __path__ to point at our expected location.
7+
# This code is very fragile and should not be reused.
8+
import sys
9+
import encodings
10+
for p in sys.path:
11+
if p.endswith(".zip"):
12+
encodings.__path__[:] = [f"{p}\\encodings"]
13+
break
14+
################################################################################
15+
116
from .exceptions import (
217
ArgumentError,
318
AutomaticInstallDisabledError,

src/manage/commands.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,10 +472,9 @@ def __init__(self, args, root=None):
472472

473473
if not self.default_platform:
474474
from _native import get_processor_architecture
475-
LOGGER.debug("Get CPU architecture, its prefix is %s", get_processor_architecture())
475+
self.default_platform = get_processor_architecture()
476+
LOGGER.debug("Default to current CPU architecture: %s", self.default_platform)
476477

477-
# Currently, we always default to -64.
478-
self.default_platform = "-64"
479478

480479
# If our command has any config, load them to override anything that
481480
# wasn't set on the command line.

src/manage/firstrun.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,9 @@ def first_run(cmd):
413413
LOGGER.print("!Y!The global shortcuts directory is not "
414414
"configured.!W!", level=logging.WARN)
415415
LOGGER.print("\nConfiguring this enables commands like "
416-
"!B!python3.14.exe!W! to run from your terminal, "
416+
"!B!python3.15.exe!W! to run from your terminal, "
417417
"but is not needed for the !B!python!W! or !B!py!W! "
418-
"commands (for example, !B!py -V:3.14!W!).",
418+
"commands (for example, !B!py -V:3.15!W!).",
419419
wrap=True)
420420
LOGGER.print("\nWe can add the directory (!B!%s!W!) to PATH now, "
421421
"but you will need to restart your terminal to use "

tests/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
_native.coinitialize()
2121

2222

23+
################################################################################
24+
# HACK: Work around gh-148750 in 3.15
25+
import encodings
26+
_orig_encodings_path = encodings.__path__[:]
27+
import manage
28+
# Importing manage has changed this value because of our hack
29+
encodings.__path__[:] = _orig_encodings_path
30+
################################################################################
31+
32+
2333
# Importing in order carefully to ensure the variables we override are handled
2434
# correctly by submodules.
2535
import manage

0 commit comments

Comments
 (0)