From b7bad45c43745ff1951cc2e35b386b785d82769d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Fri, 11 Oct 2024 12:13:19 -0700 Subject: [PATCH] Allow passing extra flags to uv sync (#107) --- README.md | 10 ++++++++++ src/tox_uv/_run_lock.py | 7 +++++++ tests/test_tox_uv_lock.py | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/README.md b/README.md index bdd2218..8bba59c 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,16 @@ A list of string that selects, which extra groups you want to install with `uv s A boolean flag to toggle installation of the `uv` development dependencies. By default, it is false. +### `uv_sync_flags` + +A list of strings, containing additional flags to pass to uv sync (useful because some flags are not configurable via +environment variables). For example, if you want to install the package in non editable mode and keep extra packages +installed into the environment you can do: + +```ini +uv_sync_flags = --no-editable, --inexact +``` + ### External package support Should tox be invoked with the [`--installpkg`](https://tox.wiki/en/stable/cli_interface.html#tox-run---installpkg) flag diff --git a/src/tox_uv/_run_lock.py b/src/tox_uv/_run_lock.py index eb474fc..9dafafd 100644 --- a/src/tox_uv/_run_lock.py +++ b/src/tox_uv/_run_lock.py @@ -44,6 +44,12 @@ def register_config(self) -> None: default=False, desc="Install dev dependencies or not", ) + self.conf.add_config( + keys=["uv_sync_flags"], + of_type=list[str], + default=[], + desc="Additional flags to pass to uv sync (for flags not configurable via environment variables)", + ) add_skip_missing_interpreters_to_core(self.core, self.options) def _setup_env(self) -> None: @@ -58,6 +64,7 @@ def _setup_env(self) -> None: cmd.append("--no-install-project") if self.options.verbosity > 3: # noqa: PLR2004 cmd.append("-v") + cmd.extend(self.conf["uv_sync_flags"]) show = self.options.verbosity > 2 # noqa: PLR2004 outcome = self.execute(cmd, stdin=StdinSource.OFF, run_id="uv-sync", show=show) outcome.assert_success() diff --git a/tests/test_tox_uv_lock.py b/tests/test_tox_uv_lock.py index a1d1361..dd42f25 100644 --- a/tests/test_tox_uv_lock.py +++ b/tests/test_tox_uv_lock.py @@ -134,3 +134,36 @@ def test_uv_lock_with_install_pkg(tox_project: ToxProjectCreator, name: str) -> ), ] assert calls == expected + + +def test_uv_sync_extra_flags(tox_project: ToxProjectCreator) -> None: + project = tox_project({ + "tox.ini": """ + [testenv] + runner = uv-venv-lock-runner + with_dev = true + uv_sync_flags = --no-editable, --inexact + commands = python hello + """ + }) + execute_calls = project.patch_execute(lambda r: 0 if r.run_id != "venv" else None) + result = project.run() + result.assert_success() + + calls = [(i[0][0].conf.name, i[0][3].run_id, i[0][3].cmd) for i in execute_calls.call_args_list] + uv = find_uv_bin() + + expected = [ + ( + "py", + "venv", + [uv, "venv", "-p", sys.executable, "--allow-existing", str(project.path / ".tox" / "py")], + ), + ( + "py", + "uv-sync", + ["uv", "sync", "--frozen", "--no-editable", "--inexact"], + ), + ("py", "commands[0]", ["python", "hello"]), + ] + assert calls == expected