From fbdb5660796d292232332f6a80ab29cb14f8e17f Mon Sep 17 00:00:00 2001 From: skshetry <18718008+skshetry@users.noreply.github.com> Date: Thu, 23 Nov 2023 14:53:39 +0545 Subject: [PATCH] remove pytest-virtualenv (#10103) * remove pytest-virtualenv It does not look like it's being actively maintained. * force virtualenv * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- dvc/testing/benchmarks/fixtures.py | 35 ++++++++++++++++++++++++------ pyproject.toml | 9 +++----- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/dvc/testing/benchmarks/fixtures.py b/dvc/testing/benchmarks/fixtures.py index 18171cac4..3b9466330 100644 --- a/dvc/testing/benchmarks/fixtures.py +++ b/dvc/testing/benchmarks/fixtures.py @@ -2,26 +2,47 @@ import os import shutil from pathlib import Path from subprocess import check_output +from typing import Dict, Optional import pytest +import virtualenv from dulwich.porcelain import clone from funcy import first from packaging import version +from dvc.types import StrPath + @pytest.fixture(scope="session") def bench_config(request): return request.config.bench_config +class VirtualEnv: + def __init__(self, path: StrPath) -> None: + self.path = Path(path) + self.bin = self.path / ("Scripts" if os.name == "nt" else "bin") + + def create(self) -> None: + virtualenv.cli_run([os.fspath(self.path)]) + + 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 + + def which(self, cmd: str) -> str: + assert self.bin.exists() + return shutil.which(cmd, path=self.bin) or cmd + + @pytest.fixture(scope="session") def make_dvc_venv(tmp_path_factory): def _make_dvc_venv(name): - from pytest_virtualenv import VirtualEnv - name = _sanitize_venv_name(name) venv_dir = tmp_path_factory.mktemp(f"dvc-venv-{name}") - return VirtualEnv(workspace=venv_dir) + venv = VirtualEnv(venv_dir) + venv.create() + return venv return _make_dvc_venv @@ -74,16 +95,16 @@ def make_dvc_bin( venv = dvc_venvs.get(dvc_rev) if not venv: venv = make_dvc_venv(dvc_rev) - venv.run("pip install -U pip") + venv.run("pip", "install", "-U", "pip") if bench_config.dvc_install_deps: egg = f"dvc[{bench_config.dvc_install_deps}]" else: egg = "dvc" - venv.run(f"pip install git+file://{dvc_git_repo}@{dvc_rev}#egg={egg}") + 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") + venv.run("pip", "install", "fsspec==2022.11.0") dvc_venvs[dvc_rev] = venv - dvc_bin = venv.virtualenv / "bin" / "dvc" + dvc_bin = venv.which("dvc") else: dvc_bin = bench_config.dvc_bin diff --git a/pyproject.toml b/pyproject.toml index 2b9293da0..694fd180e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,9 +90,9 @@ s3 = ["dvc-s3==2.23.0"] ssh = ["dvc-ssh>=2.22.1,<3"] ssh_gssapi = ["dvc-ssh[gssapi]>=2.22.1,<3"] testing = [ - "pytest-test-utils", "pytest-benchmark[histogram]", - "pytest-virtualenv", + "pytest-test-utils", + "virtualenv", ] tests = [ "dvc[testing]", @@ -156,8 +156,6 @@ filterwarnings = [ # google.logging: https://github.com/googleapis/python-logging/issues/730 # Also happens with `zc.lockfile`. "ignore:Deprecated call to `pkg_resources.declare_namespace:DeprecationWarning", - # tpi imports pkg_resources - "ignore:pkg_resources is deprecated as an API:DeprecationWarning", # see https://github.com/networkx/networkx/issues/5723. "ignore:nx.nx_pydot.* depends on the pydot package, which has.*known issues and is not actively maintained:DeprecationWarning", ] @@ -230,12 +228,11 @@ module = [ "pyparsing", "pytest_benchmark.*", "pytest_docker.plugin", - "pytest_virtualenv.*", "ruamel.*", "ruamel.yaml.*", "shortuuid", "shtab", - "tpi.*", + "virtualenv", "viztracer", "voluptuous", "yappi",