Skip to content

Commit 9d7aea1

Browse files
authored
fix: add option to avoid addition of --locked to uv sync (#231)
1 parent 33173a7 commit 9d7aea1

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ will get both the benefits (performance) or downsides (bugs) of `uv`.
1818
- [no_default_groups](#no_default_groups)
1919
- [dependency_groups](#dependency_groups)
2020
- [uv_sync_flags](#uv_sync_flags)
21+
- [uv_sync_locked](#uv_sync_locked)
2122
- [External package support](#external-package-support)
2223
- [Environment creation](#environment-creation)
2324
- [uv_seed](#uv_seed)
@@ -132,6 +133,12 @@ installed into the environment you can do:
132133
uv_sync_flags = --no-editable, --inexact
133134
```
134135

136+
### `uv_sync_locked`
137+
138+
By default tox-uv will call `uv sync` with `--locked` argument, which is incompatible with other arguments like
139+
`--prerelease` or `--upgrade ` that you might want to add to `uv_sync_flags` for some test scenarios. You can set this
140+
to `false` to avoid such conflicts.
141+
135142
### External package support
136143

137144
Should tox be invoked with the [`--installpkg`](https://tox.wiki/en/stable/cli_interface.html#tox-run---installpkg) flag

src/tox_uv/_run_lock.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ def register_config(self) -> None:
6363
default=[],
6464
desc="Additional flags to pass to uv sync (for flags not configurable via environment variables)",
6565
)
66+
self.conf.add_config(
67+
keys=["uv_sync_locked"],
68+
of_type=bool,
69+
default=True,
70+
desc="When set to 'false', it will remove `--locked` argument from 'uv sync' implicit arguments.",
71+
)
6672
self.conf.add_config(
6773
keys=["package"],
6874
of_type=Literal["editable", "wheel", "skip"], # type: ignore[arg-type]
@@ -71,15 +77,16 @@ def register_config(self) -> None:
7177
)
7278
add_skip_missing_interpreters_to_core(self.core, self.options)
7379

74-
def _setup_env(self) -> None: # noqa: C901
80+
def _setup_env(self) -> None: # noqa: C901,PLR0912
7581
super()._setup_env()
7682
install_pkg = getattr(self.options, "install_pkg", None)
7783
if not getattr(self.options, "skip_uv_sync", False):
7884
cmd = [
7985
"uv",
8086
"sync",
81-
"--locked",
8287
]
88+
if self.conf["uv_sync_locked"]:
89+
cmd.append("--locked")
8390
if self.conf["uv_python_preference"] != "none":
8491
cmd.extend(("--python-preference", self.conf["uv_python_preference"]))
8592
if self.conf["uv_resolution"]:

tests/test_tox_uv_lock.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,16 @@ def test_uv_lock_with_install_pkg(tox_project: ToxProjectCreator, name: str) ->
231231

232232

233233
@pytest.mark.usefixtures("clear_python_preference_env_var")
234-
def test_uv_sync_extra_flags(tox_project: ToxProjectCreator) -> None:
234+
@pytest.mark.parametrize("uv_sync_locked", [True, False])
235+
def test_uv_sync_extra_flags(tox_project: ToxProjectCreator, uv_sync_locked: bool) -> None:
236+
uv_sync_locked_str = str(uv_sync_locked).lower()
235237
project = tox_project({
236-
"tox.ini": """
238+
"tox.ini": f"""
237239
[testenv]
238240
runner = uv-venv-lock-runner
239241
no_default_groups = false
240242
uv_sync_flags = --no-editable, --inexact
243+
uv_sync_locked = {uv_sync_locked_str}
241244
commands = python hello
242245
"""
243246
})
@@ -269,7 +272,7 @@ def test_uv_sync_extra_flags(tox_project: ToxProjectCreator) -> None:
269272
[
270273
"uv",
271274
"sync",
272-
"--locked",
275+
*(["--locked"] if uv_sync_locked else []),
273276
"--python-preference",
274277
"system",
275278
"--no-editable",

0 commit comments

Comments
 (0)