Skip to content

Commit

Permalink
Fix deprecated 'ruff' command
Browse files Browse the repository at this point in the history
  • Loading branch information
provinzkraut committed Jun 30, 2024
1 parent 15babfa commit d9c748a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions test/test_tree_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,21 @@ def test_ruff_fix(tmp_path, monkeypatch) -> None:
assert transformer(dedent(source)) == dedent(expected)


def test_ruff_fix_ruff_error_raises(tmp_path, monkeypatch) -> None:
config_file = tmp_path / "ruff.toml"
monkeypatch.chdir(tmp_path)
config_file.write_text(tomli_w.dumps({"select": ["FOO017"]}))
monkeypatch.chdir(tmp_path)
transformer = TreeTransformer(ruff_fix=True)

source = """
import asyncio
"""

with pytest.raises(ChildProcessError, match="Error calling ruff"):
transformer(dedent(source))


def test_async_comprehension(transformer: TreeTransformer) -> None:
source = """
[x async for x in foo()]
Expand Down
6 changes: 5 additions & 1 deletion unasyncd/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def _run_ruff(self, source: str, output: str, tree: cst.Module) -> str:
sys.executable,
"-m",
"ruff",
"check",
"--no-cache",
"--fix",
"--quiet",
Expand All @@ -195,7 +196,10 @@ def _run_ruff(self, source: str, output: str, tree: cst.Module) -> str:
stdin=subprocess.PIPE,
encoding="utf-8",
) as process:
return process.communicate(input=output)[0]
stdout, stderr = process.communicate(input=output)
if process.returncode != 0:
raise ChildProcessError(f"Error calling ruff: {stderr}")
return stdout

def __call__(self, source: str) -> str:
if not source:
Expand Down

0 comments on commit d9c748a

Please sign in to comment.