Skip to content

Commit

Permalink
Disable adding the seed packages by default (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbernat authored Feb 16, 2024
1 parent d3c7230 commit fbea9f6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down Expand Up @@ -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"]

Expand Down
15 changes: 14 additions & 1 deletion src/tox_uv/_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()

Expand Down
12 changes: 11 additions & 1 deletion tests/test_tox_uv_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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)'

0 comments on commit fbea9f6

Please sign in to comment.