From 0e8dd23506a26474de469e4b2c68abb4935a8879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Ho=C3=9Fbach?= Date: Fri, 20 Oct 2023 09:57:39 +0200 Subject: [PATCH] make executable optional, invoke ruff with sys --- pylsp_ruff/plugin.py | 16 +++++++++------- pylsp_ruff/settings.py | 6 +++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/pylsp_ruff/plugin.py b/pylsp_ruff/plugin.py index e74b166..a36babf 100644 --- a/pylsp_ruff/plugin.py +++ b/pylsp_ruff/plugin.py @@ -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) diff --git a/pylsp_ruff/settings.py b/pylsp_ruff/settings.py index 5585e83..0ccda7e 100644 --- a/pylsp_ruff/settings.py +++ b/pylsp_ruff/settings.py @@ -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 @@ -25,6 +23,8 @@ class PluginSettings: format: Optional[List[str]] = None + unsafe_fixes: bool = False + severities: Optional[Dict[str, str]] = None