Skip to content

Commit

Permalink
make executable optional, invoke ruff with sys
Browse files Browse the repository at this point in the history
  • Loading branch information
jhossbach committed Oct 20, 2023
1 parent b183eb1 commit 0e8dd23
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
16 changes: 9 additions & 7 deletions pylsp_ruff/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,15 @@ def run_ruff(
executable = settings.executable
arguments = build_arguments(document_path, settings, fix, extra_arguments)

log.debug(f"Calling {executable} with args: {arguments} on '{document_path}'")
try:
cmd = [executable]
cmd.extend(arguments)
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
except Exception:
log.debug(f"Can't execute {executable}. Trying with '{sys.executable} -m ruff'")
if executable is not None:
log.debug(f"Calling {executable} with args: {arguments} on '{document_path}'")
try:
cmd = [executable]
cmd.extend(arguments)
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
except Exception:
log.error(f"Can't execute ruff with given executable '{executable}'.")
else:
cmd = [sys.executable, "-m", "ruff"]
cmd.extend(arguments)
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
Expand Down
6 changes: 3 additions & 3 deletions pylsp_ruff/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
@dataclass
class PluginSettings:
enabled: bool = True
executable: str = "ruff"
unsafe_fixes: bool = False

executable: Optional[str] = None
config: Optional[str] = None
line_length: Optional[int] = None

Expand All @@ -25,6 +23,8 @@ class PluginSettings:

format: Optional[List[str]] = None

unsafe_fixes: bool = False

severities: Optional[Dict[str, str]] = None


Expand Down

0 comments on commit 0e8dd23

Please sign in to comment.