Skip to content

Commit

Permalink
Allow passing extra flags to uv sync (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbernat authored Oct 11, 2024
1 parent a759339 commit b7bad45
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/tox_uv/_run_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand Down
33 changes: 33 additions & 0 deletions tests/test_tox_uv_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b7bad45

Please sign in to comment.