From 8a6fac9b694467ee55b6f62a2d66ed19c89f83d1 Mon Sep 17 00:00:00 2001 From: Chris Reeves Date: Fri, 22 Dec 2023 15:43:17 +0000 Subject: [PATCH] Fall back to python module if ruff executable is missing Fixes #69. --- pylsp_ruff/plugin.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pylsp_ruff/plugin.py b/pylsp_ruff/plugin.py index 1df0461..fa7a98c 100644 --- a/pylsp_ruff/plugin.py +++ b/pylsp_ruff/plugin.py @@ -510,6 +510,7 @@ def run_ruff( arguments = subcommand.build_args(document_path, settings, fix, extra_arguments) + p = None if executable is not None: log.debug(f"Calling {executable} with args: {arguments} on '{document_path}'") try: @@ -518,7 +519,11 @@ def run_ruff( p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) except Exception: log.error(f"Can't execute ruff with given executable '{executable}'.") - else: + if p is None: + log.debug( + f"Calling ruff via '{sys.executable} -m ruff'" + f" with args: {arguments} on '{document_path}'" + ) cmd = [sys.executable, "-m", "ruff", str(subcommand)] cmd.extend(arguments) p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)