mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-02-07 18:30:57 +08:00
Use uv for installing dynamic dependencies in mypy_test.py and regr_test.py (#11517)
This commit is contained in:
@@ -4,13 +4,10 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import venv
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
from typing import Any, Final, NamedTuple
|
||||
from typing_extensions import Annotated
|
||||
|
||||
import pathspec
|
||||
|
||||
@@ -51,34 +48,11 @@ def print_success_msg() -> None:
|
||||
# ====================================================================
|
||||
|
||||
|
||||
class VenvInfo(NamedTuple):
|
||||
pip_exe: Annotated[str, "A path to the venv's pip executable"]
|
||||
python_exe: Annotated[str, "A path to the venv's python executable"]
|
||||
|
||||
@staticmethod
|
||||
def of_existing_venv(venv_dir: Path) -> VenvInfo:
|
||||
if sys.platform == "win32":
|
||||
pip = venv_dir / "Scripts" / "pip.exe"
|
||||
python = venv_dir / "Scripts" / "python.exe"
|
||||
else:
|
||||
pip = venv_dir / "bin" / "pip"
|
||||
python = venv_dir / "bin" / "python"
|
||||
|
||||
return VenvInfo(str(pip), str(python))
|
||||
|
||||
|
||||
def make_venv(venv_dir: Path) -> VenvInfo:
|
||||
try:
|
||||
venv.create(venv_dir, with_pip=True, clear=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
if "ensurepip" in e.cmd and b"KeyboardInterrupt" not in e.stdout.splitlines():
|
||||
print_error(
|
||||
"stubtest requires a Python installation with ensurepip. "
|
||||
"If on Linux, you may need to install the python3-venv package."
|
||||
)
|
||||
raise
|
||||
|
||||
return VenvInfo.of_existing_venv(venv_dir)
|
||||
@cache
|
||||
def venv_python(venv_dir: Path) -> Path:
|
||||
if sys.platform == "win32":
|
||||
return venv_dir / "Scripts" / "python.exe"
|
||||
return venv_dir / "bin" / "python"
|
||||
|
||||
|
||||
@cache
|
||||
|
||||
Reference in New Issue
Block a user