Skip to content

Commit 9872144

Browse files
esafakgoogle-labs-jules[bot]pre-commit-ci[bot]
authored
fix: Update venv redirector detection for Python 3.13 on Windows (#2920)
Signed-off-by: Emre Şafak <[email protected]> Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 31eb8b9 commit 9872144

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

docs/changelog/2851.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Support renamed Windows venv redirector (`venvlauncher.exe` and `venvwlauncher.exe`) on Python 3.13
2+
Contributed by :user:`esafak`.

src/virtualenv/create/via_global_ref/builtin/cpython/cpython3.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from textwrap import dedent
99

1010
from virtualenv.create.describe import Python3Supports
11-
from virtualenv.create.via_global_ref.builtin.ref import PathRefToDest
11+
from virtualenv.create.via_global_ref.builtin.ref import ExePathRefToDest, PathRefToDest
1212
from virtualenv.create.via_global_ref.store import is_store_python
1313

1414
from .common import CPython, CPythonPosix, CPythonWindows, is_mac_os_framework, is_macos_brew
@@ -69,15 +69,47 @@ def sources(cls, interpreter):
6969

7070
@classmethod
7171
def executables(cls, interpreter):
72-
return super().sources(interpreter)
72+
sources = super().sources(interpreter)
73+
if interpreter.version_info >= (3, 13):
74+
# Create new refs with corrected launcher paths
75+
updated_sources = []
76+
for ref in sources:
77+
if ref.src.name == "python.exe":
78+
launcher_path = ref.src.with_name("venvlauncher.exe")
79+
if launcher_path.exists():
80+
new_ref = ExePathRefToDest(
81+
launcher_path, dest=ref.dest, targets=[ref.base, *ref.aliases], must=ref.must, when=ref.when
82+
)
83+
updated_sources.append(new_ref)
84+
continue
85+
elif ref.src.name == "pythonw.exe":
86+
w_launcher_path = ref.src.with_name("venvwlauncher.exe")
87+
if w_launcher_path.exists():
88+
new_ref = ExePathRefToDest(
89+
w_launcher_path,
90+
dest=ref.dest,
91+
targets=[ref.base, *ref.aliases],
92+
must=ref.must,
93+
when=ref.when,
94+
)
95+
updated_sources.append(new_ref)
96+
continue
97+
# Keep the original ref unchanged
98+
updated_sources.append(ref)
99+
return updated_sources
100+
return sources
73101

74102
@classmethod
75103
def has_shim(cls, interpreter):
76104
return interpreter.version_info.minor >= 7 and cls.shim(interpreter) is not None # noqa: PLR2004
77105

78106
@classmethod
79107
def shim(cls, interpreter):
80-
shim = Path(interpreter.system_stdlib) / "venv" / "scripts" / "nt" / "python.exe"
108+
root = Path(interpreter.system_stdlib) / "venv" / "scripts" / "nt"
109+
# Before 3.13 the launcher was called python.exe, after is venvlauncher.exe
110+
# https://github.com/python/cpython/issues/112984
111+
exe_name = "venvlauncher.exe" if interpreter.version_info >= (3, 13) else "python.exe"
112+
shim = root / exe_name
81113
if shim.exists():
82114
return shim
83115
return None

0 commit comments

Comments
 (0)