diff --git a/pyproject.toml b/pyproject.toml index 00e2bae..06af648 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,7 +43,7 @@ dependencies = [ "packaging>=24.2", "tox>=4.24.1,<5", "typing-extensions>=4.12.2; python_version<'3.10'", - "uv>=0.5.22,<1", + "uv>=0.5.27,<1", ] urls.Changelog = "https://github.com/tox-dev/tox-uv/releases" urls.Documentation = "https://github.com/tox-dev/tox-uv#tox-uv" @@ -62,14 +62,14 @@ dev = [ test = [ "covdefaults>=2.3", "devpi-process>=1.0.2", - "diff-cover>=9.2.1", + "diff-cover>=9.2.2", "pytest>=8.3.4", "pytest-cov>=6", "pytest-mock>=3.14", ] type = [ "mypy==1.14.1", { include-group = "test" } ] lint = [ "pre-commit-uv>=4.1.4" ] -pkg-meta = [ "check-wheel-contents>=0.6.1", "twine>=6.1", "uv>=0.5.22" ] +pkg-meta = [ "check-wheel-contents>=0.6.1", "twine>=6.1", "uv>=0.5.27" ] [tool.hatch] build.hooks.vcs.version-file = "src/tox_uv/version.py" diff --git a/src/tox_uv/_run_lock.py b/src/tox_uv/_run_lock.py index 0e00d13..82dcbc4 100644 --- a/src/tox_uv/_run_lock.py +++ b/src/tox_uv/_run_lock.py @@ -60,31 +60,32 @@ def register_config(self) -> None: def _setup_env(self) -> None: super()._setup_env() - cmd = [ - "uv", - "sync", - "--frozen", - ] - if self.conf["uv_python_preference"] != "none": - cmd.extend(("--python-preference", self.conf["uv_python_preference"])) - for extra in cast("set[str]", sorted(self.conf["extras"])): - cmd.extend(("--extra", extra)) - groups = sorted(self.conf["dependency_groups"]) - if self.conf["no_default_groups"] and not groups: - cmd.append("--no-default-groups") install_pkg = getattr(self.options, "install_pkg", None) - if install_pkg is not None: - cmd.append("--no-install-project") - if self.options.verbosity > 3: # noqa: PLR2004 - cmd.append("-v") - for group in groups: - cmd.extend(("--group", group)) - cmd.extend(self.conf["uv_sync_flags"]) - cmd.extend(("-p", self.env_version_spec())) - - show = self.options.verbosity > 2 # noqa: PLR2004 - outcome = self.execute(cmd, stdin=StdinSource.OFF, run_id="uv-sync", show=show) - outcome.assert_success() + if not getattr(self.options, "skip_uv_sync", False): + cmd = [ + "uv", + "sync", + "--frozen", + ] + if self.conf["uv_python_preference"] != "none": + cmd.extend(("--python-preference", self.conf["uv_python_preference"])) + for extra in cast("set[str]", sorted(self.conf["extras"])): + cmd.extend(("--extra", extra)) + groups = sorted(self.conf["dependency_groups"]) + if self.conf["no_default_groups"] and not groups: + cmd.append("--no-default-groups") + if install_pkg is not None: + cmd.append("--no-install-project") + if self.options.verbosity > 3: # noqa: PLR2004 + cmd.append("-v") + for group in groups: + cmd.extend(("--group", group)) + cmd.extend(self.conf["uv_sync_flags"]) + cmd.extend(("-p", self.env_version_spec())) + + show = self.options.verbosity > 2 # noqa: PLR2004 + outcome = self.execute(cmd, stdin=StdinSource.OFF, run_id="uv-sync", show=show) + outcome.assert_success() if install_pkg is not None: path = Path(install_pkg) pkg = (WheelPackage if path.suffix == ".whl" else SdistPackage)(path, deps=[]) diff --git a/src/tox_uv/plugin.py b/src/tox_uv/plugin.py index d410428..c6aa257 100644 --- a/src/tox_uv/plugin.py +++ b/src/tox_uv/plugin.py @@ -12,6 +12,7 @@ from ._run_lock import UvVenvLockRunner if TYPE_CHECKING: + from tox.config.cli.parser import ToxParser from tox.tox_env.register import ToxEnvRegister @@ -24,6 +25,17 @@ def tox_register_tox_env(register: ToxEnvRegister) -> None: register._default_run_env = UvVenvRunner.id() # noqa: SLF001 +@impl +def tox_add_option(parser: ToxParser) -> None: + for key in ("run", "exec"): + parser.handlers[key][0].add_argument( + "--skip-uv-sync", + dest="skip_uv_sync", + help="skip uv sync (lock mode only)", + action="store_true", + ) + + def tox_append_version_info() -> str: return f"with uv=={version('uv')}" diff --git a/tests/test_tox_uv_lock.py b/tests/test_tox_uv_lock.py index 3a3690a..efcfe61 100644 --- a/tests/test_tox_uv_lock.py +++ b/tests/test_tox_uv_lock.py @@ -454,3 +454,38 @@ def test_uv_sync_uv_python_preference( ("py", "commands[0]", ["python", "hello"]), ] assert calls == expected + + +def test_skip_uv_sync(tox_project: ToxProjectCreator) -> None: + project = tox_project({ + "tox.toml": """ + [env_run_base] + runner = "uv-venv-lock-runner" + commands = [["python", "hello"]] + """ + }) + execute_calls = project.patch_execute(lambda r: 0 if r.run_id != "venv" else None) + result = project.run("run", "--skip-uv-sync") + 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", + "--python-preference", + "system", + str(project.path / ".tox" / "py"), + ], + ), + ("py", "commands[0]", ["python", "hello"]), + ] + assert calls == expected diff --git a/tox.ini b/tox.ini index 98d8672..712901b 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] requires = tox>=4.24.1 - tox-uv>=1.20 + tox-uv>=1.21.1 env_list = fix 3.13