Skip to content

Commit ea5f874

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

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
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-
exceptException:
474-
log.debug(f"Can't execute {executable}. Trying with '{sys.executable} -m ruff'")
468+
ifexecutableisnotNone:
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+
exceptException:
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
classPluginSettings:
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

‎tests/test_ruff_lint.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright 2021- Python Language Server Contributors.
33

44
importos
5+
importsys
56
importtempfile
67
fromunittest.mockimportMock, patch
78

@@ -154,7 +155,6 @@ def f():
154155
)
155156

156157
# Check that user config is ignored
157-
assertruff_settings.executable=="ruff"
158158
empty_keys= [
159159
"config",
160160
"line_length",
@@ -175,6 +175,8 @@ def f():
175175

176176
call_args=popen_mock.call_args[0][0]
177177
assertcall_args== [
178+
str(sys.executable),
179+
"-m",
178180
"ruff",
179181
"--quiet",
180182
"--exit-zero",

0 commit comments

Comments
(0)