From c514b0ea31339eada4da584063841cb303e0a67c Mon Sep 17 00:00:00 2001 From: skshetry <18718008+skshetry@users.noreply.github.com> Date: Tue, 13 Aug 2024 22:27:05 +0545 Subject: [PATCH] use uv for benchmark tests while installing/creating virtualenv (#10520) --- dvc/testing/benchmarks/fixtures.py | 25 +++++++++++++------------ pyproject.toml | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/dvc/testing/benchmarks/fixtures.py b/dvc/testing/benchmarks/fixtures.py index 19bf9ab8ea..749d5ab37a 100644 --- a/dvc/testing/benchmarks/fixtures.py +++ b/dvc/testing/benchmarks/fixtures.py @@ -1,7 +1,8 @@ import os import shutil +import sys from pathlib import Path -from subprocess import check_output +from subprocess import check_call, check_output from typing import Optional import pytest @@ -23,13 +24,14 @@ def __init__(self, path: StrPath) -> None: self.bin = self.path / ("Scripts" if os.name == "nt" else "bin") def create(self) -> None: - import virtualenv + check_call([sys.executable, "-m", "uv", "venv", self.path]) # noqa:S603 - virtualenv.cli_run([os.fspath(self.path)]) + def install(self, *packages: str) -> None: + check_call([sys.executable, "-m", "uv", "pip", "install", *packages]) # noqa: S603 def run(self, cmd: str, *args: str, env: Optional[dict[str, str]] = None) -> None: exe = self.which(cmd) - check_output([exe, *args], env=env) # noqa: S603 + check_call([exe, *args], env=env) # noqa: S603 def which(self, cmd: str) -> str: assert self.bin.exists() @@ -93,22 +95,21 @@ def make_dvc_bin( request, ): if dvc_rev: - venv = dvc_venvs.get(dvc_rev) + venv: VirtualEnv = dvc_venvs.get(dvc_rev) if not venv: venv = make_dvc_venv(dvc_rev) - venv.run("pip", "install", "-U", "pip") if bench_config.dvc_install_deps: - egg = f"dvc[{bench_config.dvc_install_deps}]" + pkg = f"dvc[{bench_config.dvc_install_deps}]" else: - egg = "dvc" - venv.run("pip", "install", f"git+file://{dvc_git_repo}@{dvc_rev}#egg={egg}") - if dvc_rev in ["2.18.1", "2.11.0", "2.6.3"]: - venv.run("pip", "install", "fsspec==2022.11.0") + pkg = "dvc" + packages = [f"{pkg} @ git+file://{dvc_git_repo}@{dvc_rev}"] try: if version.Version(dvc_rev) < version.Version("3.50.3"): - venv.run("pip", "install", "pygit2==1.14.1") + packages.append("pygit2==1.14.1") except version.InvalidVersion: pass + venv.install(*packages) + dvc_venvs[dvc_rev] = venv dvc_bin = venv.which("dvc") else: diff --git a/pyproject.toml b/pyproject.toml index d1a255d838..3f9d70cbb1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -101,7 +101,7 @@ ssh_gssapi = ["dvc-ssh[gssapi]>=4,<5"] testing = [ "pytest-benchmark[histogram]", "pytest-test-utils", - "virtualenv", + "uv", ] tests = [ "dvc[testing]",