From fbea9f6cf859c9dfa6311c117f8f2d1b23b2a396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Fri, 16 Feb 2024 14:18:14 -0800 Subject: [PATCH] Disable adding the seed packages by default (#6) --- README.md | 10 ++++++++-- pyproject.toml | 4 ++-- src/tox_uv/_venv.py | 15 ++++++++++++++- tests/test_tox_uv_installer.py | 12 +++++++++++- tox.ini | 2 +- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 726296c..a2a0b66 100644 --- a/README.md +++ b/README.md @@ -12,5 +12,11 @@ Simply install `tox-uv` into the environment your tox is installed and will repl run environments with uv. Note: currently we haven't implemented uv support for packaging environments, so only your run tox environments will -use uv. Also, uv does not have at the moment a `pip freeze/list` like feature, so we still install pip into the -environment to perform this operation via pip. +use uv. + +## Configuration + +### uv_seed + +This flag controls if the created virtual environment injects pip/setuptools/wheel into the created virtual environment +or not. By default, is off. diff --git a/pyproject.toml b/pyproject.toml index 057d965..a5e4a5e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,7 +44,7 @@ dependencies = [ optional-dependencies.test = [ "covdefaults>=2.3", "devpi-process>=1", - "pytest>=8", + "pytest>=8.0.1", "pytest-cov>=4.1", "pytest-mock>=3.12", ] @@ -104,7 +104,7 @@ html.show_contexts = true html.skip_covered = false paths.source = ["src", ".tox/*/.venv/lib/*/site-packages", ".tox\\*\\.venv\\Lib\\site-packages", "**/src", "**\\src"] paths.other = [".", "*/tox_uv", "*\\tox_uv"] -report.fail_under = 96 +report.fail_under = 100 run.parallel = true run.plugins = ["covdefaults"] diff --git a/src/tox_uv/_venv.py b/src/tox_uv/_venv.py index c65f5a5..c739a27 100644 --- a/src/tox_uv/_venv.py +++ b/src/tox_uv/_venv.py @@ -27,6 +27,16 @@ def __init__(self, create_args: ToxEnvCreateArgs) -> None: self._installer: UvInstaller | None = None super().__init__(create_args) + def register_config(self) -> None: + super().register_config() + desc = "add seed packages to the created venv" + self.conf.add_config(keys=["uv_seed"], of_type=bool, default=False, desc=desc) + + def python_cache(self) -> dict[str, Any]: + result = super().python_cache() + result["seed"] = self.conf["uv_seed"] + return result + @property def executor(self) -> Execute: if self._executor is None: @@ -94,7 +104,10 @@ def environment_variables(self) -> dict[str, str]: def create_python_env(self) -> None: base = self.base_python - cmd = [self.uv, "venv", "-p", base.version_dot, "--seed", str(self.venv_dir)] + cmd = [self.uv, "venv", "-p", base.version_dot] + if self.conf["uv_seed"]: + cmd.append("--seed") + cmd.append(str(self.venv_dir)) outcome = self.execute(cmd, stdin=StdinSource.OFF, run_id="venv", show=False) outcome.assert_success() diff --git a/tests/test_tox_uv_installer.py b/tests/test_tox_uv_installer.py index 963f57e..ee2a213 100644 --- a/tests/test_tox_uv_installer.py +++ b/tests/test_tox_uv_installer.py @@ -12,7 +12,17 @@ def test_uv_install_in_ci_list(tox_project: ToxProjectCreator, monkeypatch: pyte project = tox_project({"tox.ini": "[testenv]\ndeps = tomli\npackage=skip"}) result = project.run() result.assert_success() - assert "tomli==" in result.out + report = {i.split("=")[0] for i in result.out.splitlines()[-3][4:].split(",")} + assert report == {"tomli"} + + +def test_uv_install_in_ci_seed(tox_project: ToxProjectCreator, monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("CI", "1") + project = tox_project({"tox.ini": "[testenv]\npackage=skip\nuv_seed = true"}) + result = project.run() + result.assert_success() + report = {i.split("=")[0] for i in result.out.splitlines()[-3][4:].split(",")} + assert report == {"pip", "setuptools", "wheel"} def test_uv_install_with_pre(tox_project: ToxProjectCreator) -> None: diff --git a/tox.ini b/tox.ini index 4c4c705..77ca003 100644 --- a/tox.ini +++ b/tox.ini @@ -68,5 +68,5 @@ package = editable extras = test commands = - python -m pip list --format=columns + uv pip freeze python -c 'import sys; print(sys.executable)'