Skip to content

Commit 0e8dd23

Browse files
committed
make executable optional, invoke ruff with sys
1 parent b183eb1 commit 0e8dd23

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

pylsp_ruff/plugin.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -465,13 +465,15 @@ def run_ruff(
465465
executable = settings.executable
466466
arguments = build_arguments(document_path, settings, fix, extra_arguments)
467467

468-
log.debug(f"Calling {executable} with args: {arguments} on '{document_path}'")
469-
try:
470-
cmd = [executable]
471-
cmd.extend(arguments)
472-
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
473-
except Exception:
474-
log.debug(f"Can't execute {executable}. Trying with '{sys.executable} -m ruff'")
468+
if executable is not None:
469+
log.debug(f"Calling {executable} with args: {arguments} on '{document_path}'")
470+
try:
471+
cmd = [executable]
472+
cmd.extend(arguments)
473+
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
474+
except Exception:
475+
log.error(f"Can't execute ruff with given executable '{executable}'.")
476+
else:
475477
cmd = [sys.executable, "-m", "ruff"]
476478
cmd.extend(arguments)
477479
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)

pylsp_ruff/settings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
@dataclass
99
class PluginSettings:
1010
enabled: bool = True
11-
executable: str = "ruff"
12-
unsafe_fixes: bool = False
13-
11+
executable: Optional[str] = None
1412
config: Optional[str] = None
1513
line_length: Optional[int] = None
1614

@@ -25,6 +23,8 @@ class PluginSettings:
2523

2624
format: Optional[List[str]] = None
2725

26+
unsafe_fixes: bool = False
27+
2828
severities: Optional[Dict[str, str]] = None
2929

3030

0 commit comments

Comments
 (0)