Use uv for installing dynamic dependencies in mypy_test.py and regr_test.py (#11517)

This commit is contained in:
Alex Waygood
2024-03-02 08:38:34 +00:00
committed by GitHub
parent 176c89c06f
commit 2c5712b7f4
6 changed files with 60 additions and 77 deletions

View File

@@ -25,13 +25,12 @@ from parse_metadata import get_recursive_requirements, read_metadata
from utils import (
PYTHON_VERSION,
PackageInfo,
VenvInfo,
colored,
get_all_testcase_directories,
get_mypy_req,
make_venv,
print_error,
testcase_dir_from_package_name,
venv_python,
)
ReturnCode: TypeAlias = int
@@ -148,13 +147,16 @@ def setup_testcase_dir(package: PackageInfo, tempdir: Path, verbosity: Verbosity
shutil.copytree(Path("stubs", requirement), new_typeshed / "stubs" / requirement)
if requirements.external_pkgs:
pip_exe = make_venv(tempdir / VENV_DIR).pip_exe
venv_location = str(tempdir / VENV_DIR)
subprocess.run(["uv", "venv", venv_location], check=True, capture_output=True)
# Use --no-cache-dir to avoid issues with concurrent read/writes to the cache
pip_command = [pip_exe, "install", get_mypy_req(), *requirements.external_pkgs, "--no-cache-dir"]
uv_command = ["uv", "pip", "install", get_mypy_req(), *requirements.external_pkgs, "--no-cache-dir"]
if verbosity is Verbosity.VERBOSE:
verbose_log(f"{package.name}: Setting up venv in {tempdir / VENV_DIR}. {pip_command=}\n")
verbose_log(f"{package.name}: Setting up venv in {venv_location}. {uv_command=}\n")
try:
subprocess.run(pip_command, check=True, capture_output=True, text=True)
subprocess.run(
uv_command, check=True, capture_output=True, text=True, env=os.environ | {"VIRTUAL_ENV": venv_location}
)
except subprocess.CalledProcessError as e:
_PRINT_QUEUE.put(f"{package.name}\n{e.stderr}")
raise
@@ -193,7 +195,7 @@ def run_testcases(
env_vars["MYPYPATH"] = os.pathsep.join(map(str, custom_typeshed.glob("stubs/*")))
has_non_types_dependencies = (tempdir / VENV_DIR).exists()
if has_non_types_dependencies:
python_exe = VenvInfo.of_existing_venv(tempdir / VENV_DIR).python_exe
python_exe = str(venv_python(tempdir / VENV_DIR))
else:
python_exe = sys.executable
flags.append("--no-site-packages")