use uv for benchmark tests while installing/creating virtualenv (#10520)

This commit is contained in:
skshetry
2024-08-13 22:27:05 +05:45
committed by GitHub
parent 853116a0e3
commit c514b0ea31
2 changed files with 14 additions and 13 deletions
+13 -12
View File
@@ -1,7 +1,8 @@
import os import os
import shutil import shutil
import sys
from pathlib import Path from pathlib import Path
from subprocess import check_output from subprocess import check_call, check_output
from typing import Optional from typing import Optional
import pytest import pytest
@@ -23,13 +24,14 @@ class VirtualEnv:
self.bin = self.path / ("Scripts" if os.name == "nt" else "bin") self.bin = self.path / ("Scripts" if os.name == "nt" else "bin")
def create(self) -> None: 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: def run(self, cmd: str, *args: str, env: Optional[dict[str, str]] = None) -> None:
exe = self.which(cmd) 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: def which(self, cmd: str) -> str:
assert self.bin.exists() assert self.bin.exists()
@@ -93,22 +95,21 @@ def make_dvc_bin(
request, request,
): ):
if dvc_rev: if dvc_rev:
venv = dvc_venvs.get(dvc_rev) venv: VirtualEnv = dvc_venvs.get(dvc_rev)
if not venv: if not venv:
venv = make_dvc_venv(dvc_rev) venv = make_dvc_venv(dvc_rev)
venv.run("pip", "install", "-U", "pip")
if bench_config.dvc_install_deps: if bench_config.dvc_install_deps:
egg = f"dvc[{bench_config.dvc_install_deps}]" pkg = f"dvc[{bench_config.dvc_install_deps}]"
else: else:
egg = "dvc" pkg = "dvc"
venv.run("pip", "install", f"git+file://{dvc_git_repo}@{dvc_rev}#egg={egg}") packages = [f"{pkg} @ git+file://{dvc_git_repo}@{dvc_rev}"]
if dvc_rev in ["2.18.1", "2.11.0", "2.6.3"]:
venv.run("pip", "install", "fsspec==2022.11.0")
try: try:
if version.Version(dvc_rev) < version.Version("3.50.3"): 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: except version.InvalidVersion:
pass pass
venv.install(*packages)
dvc_venvs[dvc_rev] = venv dvc_venvs[dvc_rev] = venv
dvc_bin = venv.which("dvc") dvc_bin = venv.which("dvc")
else: else:
+1 -1
View File
@@ -101,7 +101,7 @@ ssh_gssapi = ["dvc-ssh[gssapi]>=4,<5"]
testing = [ testing = [
"pytest-benchmark[histogram]", "pytest-benchmark[histogram]",
"pytest-test-utils", "pytest-test-utils",
"virtualenv", "uv",
] ]
tests = [ tests = [
"dvc[testing]", "dvc[testing]",