Skip to content

Commit 2c1ed32

Browse files
committed
fix: Correctly calls ruff
1 parent 709aedc commit 2c1ed32

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/mkdocstrings_handlers/python/rendering.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
import enum
6-
import importlib
76
import random
87
import re
98
import string
@@ -448,18 +447,25 @@ def _get_formatter() -> Callable[[str, int], str]:
448447
return lambda text, _: text
449448

450449

451-
@lru_cache(maxsize=1)
452450
def _get_ruff_formatter() -> Callable[[str, int], str] | None:
453-
if importlib.util.find_spec("ruff") is None:
451+
try:
452+
from ruff.__main__ import find_ruff_bin
453+
except ImportError:
454454
return None
455455

456+
try:
457+
ruff_bin = find_ruff_bin()
458+
except FileNotFoundError:
459+
ruff_bin = "ruff"
460+
456461
def formatter(code: str, line_length: int) -> str:
457462
try:
458463
completed_process = subprocess.run( # noqa: S603
459464
[ # noqa: S607
460-
"ruff",
465+
ruff_bin,
461466
"format",
462-
f'--config "line-length={line_length}"',
467+
"--config",
468+
f"line-length={line_length}",
463469
"--stdin-filename",
464470
"file.py",
465471
"-",
@@ -477,7 +483,6 @@ def formatter(code: str, line_length: int) -> str:
477483
return formatter
478484

479485

480-
@lru_cache(maxsize=1)
481486
def _get_black_formatter() -> Callable[[str, int], str] | None:
482487
try:
483488
from black import InvalidInput, Mode, format_str

0 commit comments

Comments
 (0)