Skip to content

Commit 4c9173d

Browse files
committed
add ruff_select, use --extend-select, add ignore_errors
1 parent a36b4ca commit 4c9173d

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

pytest_examples/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ExamplesConfig:
2626
upgrade: bool = False
2727
isort: bool = False
2828
ruff_line_length: int | None = None
29+
ruff_select: list[str] | None = None
2930
ruff_ignore: list[str] | None = None
3031

3132
def black_mode(self):
@@ -54,6 +55,9 @@ def ruff_config(self) -> tuple[str, ...]:
5455
else:
5556
args.append(f'--line-length={self.ruff_line_length}')
5657

58+
if self.ruff_select:
59+
select.extend(self.ruff_select)
60+
5761
if self.quotes == 'single':
5862
# enforce single quotes using ruff, black will enforce double quotes
5963
select.append('Q')

pytest_examples/eval_example.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def set_config(
4141
upgrade: bool = False,
4242
isort: bool = False,
4343
ruff_line_length: int | None = None,
44+
ruff_select: list[str] | None = None,
4445
ruff_ignore: list[str] | None = None,
4546
):
4647
"""
@@ -53,7 +54,8 @@ def set_config(
5354
:param upgrade: If True, upgrade the code to the target version, defaults to False.
5455
:param isort: If True, run ruff's isort extension on the code, defaults to False.
5556
:param ruff_line_length: In general, we disable line-length checks in ruff, to let black take care of them.
56-
:param ruff_ignore: Ruff rule to ignore
57+
:param ruff_select: Ruff rules to select
58+
:param ruff_ignore: Ruff rules to ignore
5759
"""
5860
self.config = ExamplesConfig(
5961
line_length=line_length,
@@ -63,6 +65,7 @@ def set_config(
6365
upgrade=upgrade,
6466
isort=isort,
6567
ruff_line_length=ruff_line_length,
68+
ruff_select=ruff_select,
6669
ruff_ignore=ruff_ignore,
6770
)
6871

pytest_examples/lint.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ class FormatError(ValueError):
2323
def ruff_format(
2424
example: CodeExample,
2525
config: ExamplesConfig | None,
26+
*,
27+
ignore_errors: bool = False,
2628
) -> str:
2729
args = ('--fix',)
30+
if ignore_errors:
31+
args += ('--exit-zero',)
2832
try:
2933
return ruff_check(example, config, extra_ruff_args=args)
3034
except FormatError:
@@ -43,9 +47,7 @@ def ruff_check(
4347
*,
4448
extra_ruff_args: tuple[str, ...] = (),
4549
) -> str:
46-
args = 'ruff', '-', *config.ruff_config()
47-
48-
args += extra_ruff_args
50+
args = 'ruff', '-', *config.ruff_config(), *extra_ruff_args
4951

5052
p = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)
5153
stdout, stderr = p.communicate(example.source, timeout=2)

0 commit comments

Comments
 (0)