Skip to content

Commit

Permalink
Fix uv_sync_flags fails in TOML config and add support for dependency…
Browse files Browse the repository at this point in the history
…_groups

Signed-off-by: Bernát Gábor <[email protected]>
  • Loading branch information
gaborbernat committed Oct 30, 2024
1 parent c0a2add commit 3357be9
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ 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.

### `dependency_groups`

Specify [PEP 735 – Dependency Groups](https://peps.python.org/pep-0735/) to install.

### `uv_sync_flags`

A list of strings, containing additional flags to pass to uv sync (useful because some flags are not configurable via
Expand Down
12 changes: 10 additions & 2 deletions src/tox_uv/_run_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING, cast
from typing import TYPE_CHECKING, List, Set, cast # noqa: UP035

from tox.execute.request import StdinSource
from tox.tox_env.python.package import SdistPackage, WheelPackage
Expand Down Expand Up @@ -44,9 +44,15 @@ def register_config(self) -> None:
default=False,
desc="Install dev dependencies or not",
)
self.conf.add_config(
keys=["dependency_groups"],
of_type=Set[str], # noqa: UP006
default=set(),
desc="dependency groups to install of the target package",
)
self.conf.add_config(
keys=["uv_sync_flags"],
of_type=list[str],
of_type=List[str], # noqa: UP006
default=[],
desc="Additional flags to pass to uv sync (for flags not configurable via environment variables)",
)
Expand All @@ -64,6 +70,8 @@ def _setup_env(self) -> None:
cmd.append("--no-install-project")
if self.options.verbosity > 3: # noqa: PLR2004
cmd.append("-v")
for group in sorted(self.conf["dependency_groups"]):
cmd.extend(("--group", group))
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)
Expand Down
66 changes: 66 additions & 0 deletions tests/test_tox_uv_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,69 @@ def test_uv_sync_extra_flags(tox_project: ToxProjectCreator) -> None:
("py", "commands[0]", ["python", "hello"]),
]
assert calls == expected


def test_uv_sync_extra_flags_toml(tox_project: ToxProjectCreator) -> None:
project = tox_project({
"tox.toml": """
[env_run_base]
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


def test_uv_sync_dependency_groups(tox_project: ToxProjectCreator) -> None:
project = tox_project({
"tox.toml": """
[env_run_base]
runner = "uv-venv-lock-runner"
with_dev = true
dependency_groups = ["test", "type"]
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", "--group", "test", "--group", "type"],
),
("py", "commands[0]", ["python", "hello"]),
]
assert calls == expected

0 comments on commit 3357be9

Please sign in to comment.