Skip to content

fix: Update venv redirector detection for Python 3.13 on Windows #2920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog/2851.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Support renamed Windows venv redirector (`venvlauncher.exe` and `venvwlauncher.exe`) on Python 3.13
Contributed by :user:`esafak`.
38 changes: 35 additions & 3 deletions src/virtualenv/create/via_global_ref/builtin/cpython/cpython3.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from textwrap import dedent

from virtualenv.create.describe import Python3Supports
from virtualenv.create.via_global_ref.builtin.ref import PathRefToDest
from virtualenv.create.via_global_ref.builtin.ref import ExePathRefToDest, PathRefToDest
from virtualenv.create.via_global_ref.store import is_store_python

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

@classmethod
def executables(cls, interpreter):
return super().sources(interpreter)
sources = super().sources(interpreter)
if interpreter.version_info >= (3, 13):
# Create new refs with corrected launcher paths
updated_sources = []
for ref in sources:
if ref.src.name == "python.exe":
launcher_path = ref.src.with_name("venvlauncher.exe")
if launcher_path.exists():
new_ref = ExePathRefToDest(
launcher_path, dest=ref.dest, targets=[ref.base, *ref.aliases], must=ref.must, when=ref.when
)
updated_sources.append(new_ref)
continue
elif ref.src.name == "pythonw.exe":
w_launcher_path = ref.src.with_name("venvwlauncher.exe")
if w_launcher_path.exists():
new_ref = ExePathRefToDest(
w_launcher_path,
dest=ref.dest,
targets=[ref.base, *ref.aliases],
must=ref.must,
when=ref.when,
)
updated_sources.append(new_ref)
continue
# Keep the original ref unchanged
updated_sources.append(ref)
return updated_sources
return sources

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

@classmethod
def shim(cls, interpreter):
shim = Path(interpreter.system_stdlib) / "venv" / "scripts" / "nt" / "python.exe"
root = Path(interpreter.system_stdlib) / "venv" / "scripts" / "nt"
# Before 3.13 the launcher was called python.exe, after is venvlauncher.exe
# https://github.com/python/cpython/issues/112984
exe_name = "venvlauncher.exe" if interpreter.version_info >= (3, 13) else "python.exe"
shim = root / exe_name
if shim.exists():
return shim
return None
Expand Down
Loading