Skip to content

Commit 72776f2

Browse files
🎨 refactor(create): read the system exe without narrowing (#3224)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 8fab8d6 commit 72776f2

9 files changed

Lines changed: 15 additions & 13 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Bump the ``python-discovery`` minimum to ``>=1.6`` for ``PythonInfo.system_exe``, which reports the system interpreter
2+
without the nullable typing of ``system_executable`` - by :user:`gaborbernat`.

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ dependencies = [
4949
"filelock>=3.16.1,<=3.19.1; python_version<'3.10'",
5050
"filelock>=3.24.2,<4; python_version>='3.10'",
5151
"platformdirs>=3.9.1,<5",
52-
"python-discovery>=1.4.2",
52+
"python-discovery>=1.6",
5353
"typing-extensions>=4.13.2; python_version<'3.11'",
5454
]
5555
urls.Documentation = "https://virtualenv.pypa.io"

‎src/virtualenv/create/via_global_ref/builtin/cpython/common.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class CPythonPosix(CPython, PosixSupports, ABC):
3131

3232
@classmethod
3333
def _executables(cls, interpreter: PythonInfo) -> Generator[tuple[Path, list[str], str, str]]:
34-
host_exe = Path(interpreter.system_executable) # ty: ignore[invalid-argument-type]
34+
host_exe = Path(interpreter.system_exe)
3535
minor = interpreter.version_info.minor
3636
names = [
3737
"python",
@@ -57,7 +57,7 @@ def _executables(cls, interpreter: PythonInfo) -> Generator[tuple[Path, list[str
5757
"python3.exe",
5858
"python3",
5959
# host is the venvlauncher shim on CPython 3.13+, so the alias comes from the interpreter, not from host
60-
Path(interpreter.system_executable).name, # ty: ignore[invalid-argument-type]
60+
Path(interpreter.system_exe).name,
6161
*((f"python3.{minor}t.exe",) if interpreter.free_threaded else ()),
6262
}
6363
for path in (host.parent / n for n in names):
@@ -73,7 +73,7 @@ def _executables(cls, interpreter: PythonInfo) -> Generator[tuple[Path, list[str
7373

7474
@classmethod
7575
def host_python(cls, interpreter: PythonInfo) -> Path:
76-
return Path(interpreter.system_executable) # ty: ignore[invalid-argument-type]
76+
return Path(interpreter.system_exe)
7777

7878

7979
def is_mac_os_framework(interpreter: PythonInfo) -> bool:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def host_python(cls, interpreter: PythonInfo) -> Path:
150150

151151
@classmethod
152152
def dll_and_pyd(cls, interpreter: PythonInfo) -> Generator[PathRefToDest]:
153-
folders = [Path(interpreter.system_executable).parent] # ty: ignore[invalid-argument-type]
153+
folders = [Path(interpreter.system_exe).parent]
154154

155155
# May be missing on some Python hosts.
156156
# See https://github.com/pypa/virtualenv/issues/2368

‎src/virtualenv/create/via_global_ref/builtin/graalpy/__init__.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ def exe_names(cls, interpreter: PythonInfo) -> set[str]:
4040

4141
@classmethod
4242
def _executables(cls, interpreter: PythonInfo) -> Generator[tuple[Path, list[str], RefMust, RefWhen], None, None]: # ty: ignore[invalid-method-override]
43-
host = Path(interpreter.system_executable) # ty: ignore[invalid-argument-type]
43+
host = Path(interpreter.system_exe)
4444
targets = sorted(f"{name}{cls.suffix}" for name in cls.exe_names(interpreter))
4545
yield host, targets, RefMust.NA, RefWhen.ANY
4646

4747
@classmethod
4848
def sources(cls, interpreter: PythonInfo) -> Generator[PathRefToDest]: # ty: ignore[invalid-method-override]
4949
yield from super().sources(interpreter)
50-
python_dir = Path(interpreter.system_executable).resolve().parent # ty: ignore[invalid-argument-type]
50+
python_dir = Path(interpreter.system_exe).resolve().parent
5151
if python_dir.name in {"bin", "Scripts"}:
5252
python_dir = python_dir.parent
5353

@@ -90,7 +90,7 @@ def _native_lib(cls, lib_dir: Path, platform: str) -> Path: # ruff:ignore[unuse
9090
def set_pyenv_cfg(self) -> None:
9191
# GraalPy needs an additional entry in pyvenv.cfg on Windows
9292
super().set_pyenv_cfg()
93-
self.pyenv_cfg["venvlauncher_command"] = self.interpreter.system_executable # ty: ignore[invalid-assignment]
93+
self.pyenv_cfg["venvlauncher_command"] = self.interpreter.system_exe
9494

9595

9696
__all__ = [

‎src/virtualenv/create/via_global_ref/builtin/pypy/common.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def can_describe(cls, interpreter: PythonInfo) -> bool:
2222

2323
@classmethod
2424
def _executables(cls, interpreter: PythonInfo) -> Generator[tuple[Path, list[str], str, str]]:
25-
host = Path(interpreter.system_executable) # ty: ignore[invalid-argument-type]
25+
host = Path(interpreter.system_exe)
2626
targets = sorted(f"{name}{PyPy.suffix}" for name in cls.exe_names(interpreter))
2727
yield host, targets, RefMust.NA, RefWhen.ANY
2828

@@ -48,7 +48,7 @@ def sources(cls, interpreter: PythonInfo) -> Generator[PathRef]: # ty: ignore[i
4848
@classmethod
4949
def _add_shared_libs(cls, interpreter: PythonInfo) -> Generator[Path]:
5050
# https://bitbucket.org/pypy/pypy/issue/1922/future-proofing-virtualenv
51-
python_dir = Path(interpreter.system_executable).resolve().parent # ty: ignore[invalid-argument-type]
51+
python_dir = Path(interpreter.system_exe).resolve().parent
5252
yield from cls._shared_libs(python_dir)
5353

5454
@classmethod

‎src/virtualenv/create/via_global_ref/builtin/rustpython/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def exe_names(cls, interpreter: PythonInfo) -> set[str]:
3434

3535
@classmethod
3636
def _executables(cls, interpreter: PythonInfo) -> Generator[tuple[Path, list[str], RefMust, RefWhen], None, None]: # ty: ignore[invalid-method-override]
37-
host = Path(interpreter.system_executable) # ty: ignore[invalid-argument-type]
37+
host = Path(interpreter.system_exe)
3838
targets = sorted(f"{name}{cls.suffix}" for name in cls.exe_names(interpreter))
3939
yield host, targets, RefMust.NA, RefWhen.ANY
4040

‎src/virtualenv/create/via_global_ref/builtin/via_global_self_do.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def set_pyenv_cfg(self) -> None:
126126
super().set_pyenv_cfg()
127127
self.pyenv_cfg["base-prefix"] = self.interpreter.system_prefix
128128
self.pyenv_cfg["base-exec-prefix"] = self.interpreter.system_exec_prefix
129-
self.pyenv_cfg["base-executable"] = self.interpreter.system_executable # ty: ignore[invalid-assignment]
129+
self.pyenv_cfg["base-executable"] = self.interpreter.system_exe
130130

131131

132132
__all__ = [

‎src/virtualenv/create/via_global_ref/store.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def handle_store_python(meta: ViaGlobalRefMeta, interpreter: PythonInfo) -> ViaG
1616

1717

1818
def is_store_python(interpreter: PythonInfo) -> bool:
19-
parts = Path(interpreter.system_executable).parts # ty: ignore[invalid-argument-type]
19+
parts = Path(interpreter.system_exe).parts
2020
return (
2121
len(parts) > 4 # ruff:ignore[magic-value-comparison]
2222
and parts[-4] == "Microsoft"

0 commit comments

Comments
 (0)