Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/usethis/_integrations/uv/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ def call_uv_subprocess(args: list[str]) -> str:
UVSubprocessFailedError: If the subprocess fails.
"""
read_pyproject_toml_from_path.cache_clear()
new_args = ["uv", *args]

if usethis_config.frozen and args[0] in {
"run",
"add",
"remove",
"sync",
"lock",
"export",
"tree",
"run",
}:
new_args.append("--frozen")
new_args = ["uv", args[0], "--frozen", *args[1:]]
else:
new_args = ["uv", *args]

try:
return call_subprocess(new_args)
except SubprocessFailedError as err:
Expand Down
1 change: 0 additions & 1 deletion src/usethis/_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ def get_pyproject_configs(self) -> list[PyProjectConfig]:
PyProjectConfig(
id_keys=["tool", "codespell"],
value={
"ignore-words-list": [],
"ignore-regex": [
"[A-Za-z0-9+/]{100,}" # Ignore long base64 strings
],
Expand Down
10 changes: 9 additions & 1 deletion tests/usethis/_core/test_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def test_config(self, uv_init_dir: Path, capfd: pytest.CaptureFixture[str]):
assert (uv_init_dir / "pyproject.toml").read_text() == content + "\n" + (
"""\
[tool.codespell]
ignore-words-list = []
ignore-regex = ["[A-Za-z0-9+/]{100,}"]
"""
)
Expand Down Expand Up @@ -125,6 +124,15 @@ def test_pre_commit_integration(
"☐ Run 'pre-commit run codespell --all-files' to run the Codespell spellchecker.\n"
)

@pytest.mark.usefixtures("_vary_network_conn")
def test_runs(self, uv_env_dir: Path):
with change_cwd(uv_env_dir):
# Arrange
use_codespell()

# Act, Assert (no errors)
call_uv_subprocess(["run", "codespell"])

class TestRemove:
@pytest.mark.usefixtures("_vary_network_conn")
def test_config_file(
Expand Down
21 changes: 21 additions & 0 deletions tests/usethis/_integrations/uv/test_call.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest

import usethis._integrations.uv.call
from usethis._config import usethis_config
from usethis._integrations.uv.call import call_uv_subprocess
from usethis._integrations.uv.errors import UVSubprocessFailedError

Expand All @@ -18,3 +20,22 @@ def test_nonexistent_command(self):
match = ".*error: unrecognized subcommand 'does-not-exist'.*"
with pytest.raises(UVSubprocessFailedError, match=match):
call_uv_subprocess(["does-not-exist"])

def test_frozen_added_in_uv_run(self, monkeypatch: pytest.MonkeyPatch):
# Mock the usethis._subprocess.call_subprocess function to check args passed

# Arrange
# Mock the call_subprocess function to check the args passed
def mock_call_subprocess(args: list[str]) -> str:
return " ".join(args)

monkeypatch.setattr(
usethis._integrations.uv.call, "call_subprocess", mock_call_subprocess
)

with usethis_config.set(frozen=True):
# Act, Assert
# Check the args passed to call_subprocess
assert call_uv_subprocess(["run", "pre-commit", "install"]) == (
"uv run --frozen pre-commit install"
)