mirror of
https://github.com/astral-sh/ruff
synced 2026-01-20 21:10:48 -05:00
[ty] Improve tracebacks when installing dependencies fails in ty_benchmark (#22399)
This commit is contained in:
@@ -92,7 +92,7 @@ class Project(NamedTuple):
|
||||
)
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
raise RuntimeError(f"Failed to clone {self.name}: {e.stderr}")
|
||||
raise RuntimeError(f"Failed to clone {self.name}:\n\n{e.stderr}") from e
|
||||
|
||||
logging.info(f"Cloned {self.name} to {checkout_dir}.")
|
||||
|
||||
|
||||
@@ -147,7 +147,9 @@ def main() -> None:
|
||||
cwd = Path(tempdir)
|
||||
project.clone(cwd)
|
||||
|
||||
venv = Venv.create(cwd, project.python_version)
|
||||
venv = Venv.create(
|
||||
project=project.name, parent=cwd, python_version=project.python_version
|
||||
)
|
||||
venv.install(project.install_arguments)
|
||||
|
||||
commands = []
|
||||
|
||||
@@ -42,7 +42,9 @@ def project_setup(
|
||||
cwd = Path(tempdir)
|
||||
project.clone(cwd)
|
||||
|
||||
venv = Venv.create(cwd, project.python_version)
|
||||
venv = Venv.create(
|
||||
project=project.name, parent=cwd, python_version=project.python_version
|
||||
)
|
||||
venv.install(project.install_arguments)
|
||||
|
||||
yield project, venv
|
||||
|
||||
@@ -3,15 +3,15 @@ from __future__ import annotations
|
||||
import logging
|
||||
import subprocess
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True, slots=True)
|
||||
class Venv:
|
||||
project_name: str
|
||||
project_path: Path
|
||||
|
||||
def __init__(self, path: Path):
|
||||
self.project_path = path
|
||||
|
||||
@property
|
||||
def path(self) -> Path:
|
||||
return self.project_path / "venv"
|
||||
@@ -36,7 +36,7 @@ class Venv:
|
||||
return self.bin / f"{name}{extension}"
|
||||
|
||||
@staticmethod
|
||||
def create(parent: Path, python_version: str) -> Venv:
|
||||
def create(*, project: str, parent: Path, python_version: str) -> Venv:
|
||||
"""Creates a new, empty virtual environment."""
|
||||
|
||||
command = [
|
||||
@@ -53,9 +53,10 @@ class Venv:
|
||||
command, cwd=parent, check=True, capture_output=True, text=True
|
||||
)
|
||||
except subprocess.CalledProcessError as e:
|
||||
raise RuntimeError(f"Failed to create venv: {e.stderr}")
|
||||
msg = f"Failed to create venv for {project}:\n\n{e.stderr}"
|
||||
raise RuntimeError(msg) from e
|
||||
|
||||
return Venv(parent)
|
||||
return Venv(project_name=project, project_path=parent)
|
||||
|
||||
def install(self, pip_install_args: list[str]) -> None:
|
||||
"""Installs the dependencies required to type check the project."""
|
||||
@@ -87,4 +88,7 @@ class Venv:
|
||||
text=True,
|
||||
)
|
||||
except subprocess.CalledProcessError as e:
|
||||
raise RuntimeError(f"Failed to install dependencies: {e.stderr}")
|
||||
msg = (
|
||||
f"Failed to install dependencies for {self.project_name}:\n\n{e.stderr}"
|
||||
)
|
||||
raise RuntimeError(msg) from e
|
||||
|
||||
Reference in New Issue
Block a user