Skip to content

Commit e9c106c

Browse files
committed
Modify project:fix and project:format to include ruff
1 parent 9c208f8 commit e9c106c

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

exasol/toolbox/nox/_format.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,26 @@ def _pyupgrade(session: Session, config: Config, files: Iterable[str]) -> None:
3535
)
3636

3737

38+
def _ruff(session: Session, mode: Mode, files: Iterable[str]):
39+
def command(*args: str) -> Iterable[str]:
40+
return args if mode == Mode.Check else list(args) + ["--fix"]
41+
42+
session.run(*command("ruff", "check"), *files)
43+
44+
3845
@nox.session(name="project:fix", python=False)
3946
def fix(session: Session) -> None:
4047
"""Runs all automated fixes on the code base"""
4148
py_files = python_files(PROJECT_CONFIG.root)
4249
_version(session, Mode.Fix)
4350
_pyupgrade(session, config=PROJECT_CONFIG, files=py_files)
51+
_ruff(session, mode=Mode.Fix, files=py_files)
4452
_code_format(session, Mode.Fix, py_files)
4553

4654

4755
@nox.session(name="project:format", python=False)
4856
def fmt_check(session: Session) -> None:
4957
"""Checks the project for correct formatting"""
5058
py_files = python_files(PROJECT_CONFIG.root)
59+
_ruff(session, mode=Mode.Check, files=py_files)
5160
_code_format(session=session, mode=Mode.Check, files=py_files)

test/unit/nox/_format_test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pytest
2+
from nox.command import CommandFailed
3+
from toolbox.nox._format import _ruff
4+
5+
from exasol.toolbox.nox._shared import Mode
6+
7+
8+
@pytest.fixture
9+
def file_with_unneeded_import(tmp_path):
10+
file_path = tmp_path / "dummy_file.py"
11+
file_path.write_text("import black")
12+
return file_path
13+
14+
15+
class TestRuff:
16+
@staticmethod
17+
def test_mode_fix(nox_session, file_with_unneeded_import):
18+
_ruff(
19+
session=nox_session, mode=Mode.Fix, files=[str(file_with_unneeded_import)]
20+
)
21+
assert file_with_unneeded_import.read_text() == ""
22+
23+
@staticmethod
24+
def test_mode_check(nox_session, file_with_unneeded_import):
25+
with pytest.raises(CommandFailed):
26+
_ruff(
27+
session=nox_session,
28+
mode=Mode.Check,
29+
files=[str(file_with_unneeded_import)],
30+
)
31+
assert file_with_unneeded_import.read_text() == "import black"

0 commit comments

Comments
 (0)