Skip to content

Commit 4424437

Browse files
authored
Force reinstall of wheel project for lock files (#176)
Signed-off-by: Bernát Gábor <[email protected]>
1 parent 9fdd862 commit 4424437

File tree

3 files changed

+50
-13
lines changed

3 files changed

+50
-13
lines changed

pyproject.toml

+4-6
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ build.targets.sdist.include = [
7979
]
8080
version.source = "vcs"
8181

82-
[tool.black]
83-
line-length = 120
84-
8582
[tool.ruff]
8683
line-length = 120
8784
format.preview = true
@@ -128,6 +125,10 @@ count = true
128125
[tool.pyproject-fmt]
129126
max_supported_python = "3.13"
130127

128+
[tool.pytest.ini_options]
129+
norecursedirs = "tests/data/*"
130+
verbosity_assertions = 2
131+
131132
[tool.coverage]
132133
html.show_contexts = true
133134
html.skip_covered = false
@@ -162,6 +163,3 @@ overrides = [
162163
"uv.*",
163164
], ignore_missing_imports = true },
164165
]
165-
166-
[tool.uv]
167-
cache-keys = [ { file = "pyproject.toml" }, { git = true } ]

src/tox_uv/_run_lock.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
22

33
from __future__ import annotations
44

5+
import sys
56
from pathlib import Path
67
from typing import TYPE_CHECKING, List, Literal, Set, cast # noqa: UP035
78

89
from tox.execute.request import StdinSource
10+
from tox.report import HandledError
911
from tox.tox_env.python.package import SdistPackage, WheelPackage
1012
from tox.tox_env.python.runner import add_extras_to_env, add_skip_missing_interpreters_to_core
1113
from tox.tox_env.runner import RunToxEnv
1214

1315
from ._venv import UvVenv
1416

17+
if sys.version_info >= (3, 11): # pragma: no cover (py311+)
18+
import tomllib
19+
else: # pragma: no cover (py311+)
20+
import tomli as tomllib
21+
1522
if TYPE_CHECKING:
1623
from tox.tox_env.package import Package
1724

@@ -64,7 +71,7 @@ def register_config(self) -> None:
6471
)
6572
add_skip_missing_interpreters_to_core(self.core, self.options)
6673

67-
def _setup_env(self) -> None:
74+
def _setup_env(self) -> None: # noqa: C901
6875
super()._setup_env()
6976
install_pkg = getattr(self.options, "install_pkg", None)
7077
if not getattr(self.options, "skip_uv_sync", False):
@@ -86,7 +93,17 @@ def _setup_env(self) -> None:
8693
if self.options.verbosity > 3: # noqa: PLR2004
8794
cmd.append("-v")
8895
if package == "wheel":
89-
cmd.append("--no-editable")
96+
# need the package name here but we don't have the packaging infrastructure -> read from pyproject.toml
97+
project_file = self.core["tox_root"] / "pyproject.toml"
98+
name = None
99+
if project_file.exists():
100+
with project_file.open("rb") as file_handler:
101+
raw = tomllib.load(file_handler)
102+
name = raw.get("project", {}).get("name")
103+
if name is None:
104+
msg = "Could not detect project name"
105+
raise HandledError(msg)
106+
cmd.extend(("--no-editable", "--reinstall-package", name))
90107
for group in groups:
91108
cmd.extend(("--group", group))
92109
cmd.extend(self.conf["uv_sync_flags"])

tests/test_tox_uv_lock.py

+27-5
Original file line numberDiff line numberDiff line change
@@ -491,14 +491,18 @@ def test_skip_uv_sync(tox_project: ToxProjectCreator, monkeypatch: pytest.Monkey
491491
assert calls == expected
492492

493493

494-
def test_skip_uv_package_wheel(tox_project: ToxProjectCreator, monkeypatch: pytest.MonkeyPatch) -> None:
494+
def test_uv_package_wheel(tox_project: ToxProjectCreator, monkeypatch: pytest.MonkeyPatch) -> None:
495495
monkeypatch.delenv("UV_PYTHON_PREFERENCE", raising=False)
496496
project = tox_project({
497497
"tox.toml": """
498-
[env_run_base]
499-
runner = "uv-venv-lock-runner"
500-
package = "wheel"
501-
"""
498+
[env_run_base]
499+
runner = "uv-venv-lock-runner"
500+
package = "wheel"
501+
""",
502+
"pyproject.toml": """
503+
[project]
504+
name = "demo"
505+
""",
502506
})
503507
execute_calls = project.patch_execute(lambda r: 0 if r.run_id != "venv" else None)
504508
result = project.run("run", "--notest")
@@ -532,6 +536,8 @@ def test_skip_uv_package_wheel(tox_project: ToxProjectCreator, monkeypatch: pyte
532536
"--python-preference",
533537
"system",
534538
"--no-editable",
539+
"--reinstall-package",
540+
"demo",
535541
"-p",
536542
sys.executable,
537543
],
@@ -540,6 +546,22 @@ def test_skip_uv_package_wheel(tox_project: ToxProjectCreator, monkeypatch: pyte
540546
assert calls == expected
541547

542548

549+
def test_uv_package_wheel_no_pyproject(tox_project: ToxProjectCreator, monkeypatch: pytest.MonkeyPatch) -> None:
550+
monkeypatch.delenv("UV_PYTHON_PREFERENCE", raising=False)
551+
project = tox_project({
552+
"tox.toml": """
553+
[env_run_base]
554+
runner = "uv-venv-lock-runner"
555+
package = "wheel"
556+
""",
557+
})
558+
project.patch_execute(lambda r: 0 if r.run_id != "venv" else None)
559+
560+
result = project.run("run", "--notest")
561+
562+
result.assert_failed()
563+
564+
543565
def test_skip_uv_package_skip(tox_project: ToxProjectCreator, monkeypatch: pytest.MonkeyPatch) -> None:
544566
monkeypatch.delenv("UV_PYTHON_PREFERENCE", raising=False)
545567
project = tox_project({

0 commit comments

Comments
 (0)