Skip to content

Commit fbbdec6

Browse files
Ensure codespell runs successfully with default config on empty repo (#292)
* Ensure codespell runs successfully with default config on empty repo * Try to solve network issue in test * Add unit test for adding frozen flag * Fix typo
1 parent a2319be commit fbbdec6

4 files changed

Lines changed: 36 additions & 5 deletions

File tree

src/usethis/_integrations/uv/call.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@ def call_uv_subprocess(args: list[str]) -> str:
1111
UVSubprocessFailedError: If the subprocess fails.
1212
"""
1313
read_pyproject_toml_from_path.cache_clear()
14-
new_args = ["uv", *args]
14+
1515
if usethis_config.frozen and args[0] in {
16-
"run",
1716
"add",
1817
"remove",
1918
"sync",
2019
"lock",
2120
"export",
2221
"tree",
22+
"run",
2323
}:
24-
new_args.append("--frozen")
24+
new_args = ["uv", args[0], "--frozen", *args[1:]]
25+
else:
26+
new_args = ["uv", *args]
27+
2528
try:
2629
return call_subprocess(new_args)
2730
except SubprocessFailedError as err:

src/usethis/_tool.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ def get_pyproject_configs(self) -> list[PyProjectConfig]:
205205
PyProjectConfig(
206206
id_keys=["tool", "codespell"],
207207
value={
208-
"ignore-words-list": [],
209208
"ignore-regex": [
210209
"[A-Za-z0-9+/]{100,}" # Ignore long base64 strings
211210
],

tests/usethis/_core/test_tool.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def test_config(self, uv_init_dir: Path, capfd: pytest.CaptureFixture[str]):
6565
assert (uv_init_dir / "pyproject.toml").read_text() == content + "\n" + (
6666
"""\
6767
[tool.codespell]
68-
ignore-words-list = []
6968
ignore-regex = ["[A-Za-z0-9+/]{100,}"]
7069
"""
7170
)
@@ -131,6 +130,15 @@ def test_pre_commit_integration(
131130
"☐ Run 'pre-commit run codespell --all-files' to run the Codespell spellchecker.\n"
132131
)
133132

133+
@pytest.mark.usefixtures("_vary_network_conn")
134+
def test_runs(self, uv_env_dir: Path):
135+
with change_cwd(uv_env_dir):
136+
# Arrange
137+
use_codespell()
138+
139+
# Act, Assert (no errors)
140+
call_uv_subprocess(["run", "codespell"])
141+
134142
class TestRemove:
135143
@pytest.mark.usefixtures("_vary_network_conn")
136144
def test_config_file(

tests/usethis/_integrations/uv/test_call.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import pytest
22

3+
import usethis._integrations.uv.call
4+
from usethis._config import usethis_config
35
from usethis._integrations.uv.call import call_uv_subprocess
46
from usethis._integrations.uv.errors import UVSubprocessFailedError
57

@@ -18,3 +20,22 @@ def test_nonexistent_command(self):
1820
match = ".*error: unrecognized subcommand 'does-not-exist'.*"
1921
with pytest.raises(UVSubprocessFailedError, match=match):
2022
call_uv_subprocess(["does-not-exist"])
23+
24+
def test_frozen_added_in_uv_run(self, monkeypatch: pytest.MonkeyPatch):
25+
# Mock the usethis._subprocess.call_subprocess function to check args passed
26+
27+
# Arrange
28+
# Mock the call_subprocess function to check the args passed
29+
def mock_call_subprocess(args: list[str]) -> str:
30+
return " ".join(args)
31+
32+
monkeypatch.setattr(
33+
usethis._integrations.uv.call, "call_subprocess", mock_call_subprocess
34+
)
35+
36+
with usethis_config.set(frozen=True):
37+
# Act, Assert
38+
# Check the args passed to call_subprocess
39+
assert call_uv_subprocess(["run", "pre-commit", "install"]) == (
40+
"uv run --frozen pre-commit install"
41+
)

0 commit comments

Comments
 (0)