Skip to content

Commit e1e76b1

Browse files
committed
Lock mode: allow setting package to editable, wheel or skip
Signed-off-by: Bernát Gábor <[email protected]>
1 parent d59c60f commit e1e76b1

File tree

4 files changed

+114
-3
lines changed

4 files changed

+114
-3
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ repos:
2424
hooks:
2525
- id: pyproject-fmt
2626
- repo: https://github.com/astral-sh/ruff-pre-commit
27-
rev: "v0.9.4"
27+
rev: "v0.9.5"
2828
hooks:
2929
- id: ruff-format
3030
- id: ruff

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ Note that when using `uv-venv-lock-runner`, _all_ dependencies will come from th
9393
Therefore, options like `deps` are ignored (and all others
9494
[enumerated here](https://tox.wiki/en/stable/config.html#python-run) as Python run flags).
9595

96+
### `package`
97+
98+
How to install the source tree package, one of `wheel`, `editable` or `skip`. By default will do `editable`.
99+
96100
### `extras`
97101

98102
A list of string that selects, which extra groups you want to install with `uv sync`. By default, it is empty.

src/tox_uv/_run_lock.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
from pathlib import Path
6-
from typing import TYPE_CHECKING, List, Set, cast # noqa: UP035
6+
from typing import TYPE_CHECKING, List, Literal, Set, cast # noqa: UP035
77

88
from tox.execute.request import StdinSource
99
from tox.tox_env.python.package import SdistPackage, WheelPackage
@@ -56,6 +56,12 @@ def register_config(self) -> None:
5656
default=[],
5757
desc="Additional flags to pass to uv sync (for flags not configurable via environment variables)",
5858
)
59+
self.conf.add_config(
60+
keys=["package"],
61+
of_type=Literal["editable", "wheel", "skip"],
62+
default="editable",
63+
desc="How should the package be installed",
64+
)
5965
add_skip_missing_interpreters_to_core(self.core, self.options)
6066

6167
def _setup_env(self) -> None:
@@ -74,10 +80,13 @@ def _setup_env(self) -> None:
7480
groups = sorted(self.conf["dependency_groups"])
7581
if self.conf["no_default_groups"]:
7682
cmd.append("--no-default-groups")
77-
if install_pkg is not None:
83+
package = self.conf["package"]
84+
if install_pkg is not None or package == "skip":
7885
cmd.append("--no-install-project")
7986
if self.options.verbosity > 3: # noqa: PLR2004
8087
cmd.append("-v")
88+
if package == "wheel":
89+
cmd.append("--no-editable")
8190
for group in groups:
8291
cmd.extend(("--group", group))
8392
cmd.extend(self.conf["uv_sync_flags"])

tests/test_tox_uv_lock.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,101 @@ def test_skip_uv_sync(tox_project: ToxProjectCreator, monkeypatch: pytest.Monkey
489489
("py", "commands[0]", ["python", "hello"]),
490490
]
491491
assert calls == expected
492+
493+
494+
def test_skip_uv_package_wheel(tox_project: ToxProjectCreator, monkeypatch: pytest.MonkeyPatch) -> None:
495+
monkeypatch.delenv("UV_PYTHON_PREFERENCE", raising=False)
496+
project = tox_project({
497+
"tox.toml": """
498+
[env_run_base]
499+
runner = "uv-venv-lock-runner"
500+
package = "wheel"
501+
"""
502+
})
503+
execute_calls = project.patch_execute(lambda r: 0 if r.run_id != "venv" else None)
504+
result = project.run("run", "--notest")
505+
result.assert_success()
506+
507+
calls = [(i[0][0].conf.name, i[0][3].run_id, i[0][3].cmd) for i in execute_calls.call_args_list]
508+
uv = find_uv_bin()
509+
510+
expected = [
511+
(
512+
"py",
513+
"venv",
514+
[
515+
uv,
516+
"venv",
517+
"-p",
518+
sys.executable,
519+
"--allow-existing",
520+
"--python-preference",
521+
"system",
522+
str(project.path / ".tox" / "py"),
523+
],
524+
),
525+
(
526+
"py",
527+
"uv-sync",
528+
[
529+
"uv",
530+
"sync",
531+
"--frozen",
532+
"--python-preference",
533+
"system",
534+
"--no-editable",
535+
"-p",
536+
sys.executable,
537+
],
538+
),
539+
]
540+
assert calls == expected
541+
542+
543+
def test_skip_uv_package_skip(tox_project: ToxProjectCreator, monkeypatch: pytest.MonkeyPatch) -> None:
544+
monkeypatch.delenv("UV_PYTHON_PREFERENCE", raising=False)
545+
project = tox_project({
546+
"tox.toml": """
547+
[env_run_base]
548+
runner = "uv-venv-lock-runner"
549+
package = "skip"
550+
"""
551+
})
552+
execute_calls = project.patch_execute(lambda r: 0 if r.run_id != "venv" else None)
553+
result = project.run("run", "--notest")
554+
result.assert_success()
555+
556+
calls = [(i[0][0].conf.name, i[0][3].run_id, i[0][3].cmd) for i in execute_calls.call_args_list]
557+
uv = find_uv_bin()
558+
559+
expected = [
560+
(
561+
"py",
562+
"venv",
563+
[
564+
uv,
565+
"venv",
566+
"-p",
567+
sys.executable,
568+
"--allow-existing",
569+
"--python-preference",
570+
"system",
571+
str(project.path / ".tox" / "py"),
572+
],
573+
),
574+
(
575+
"py",
576+
"uv-sync",
577+
[
578+
"uv",
579+
"sync",
580+
"--frozen",
581+
"--python-preference",
582+
"system",
583+
"--no-install-project",
584+
"-p",
585+
sys.executable,
586+
],
587+
),
588+
]
589+
assert calls == expected

0 commit comments

Comments
 (0)