From 5c84958b219e5cc7e3c390448237eb39fb47d8ee Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Thu, 25 Sep 2025 15:13:25 -0500 Subject: [PATCH 1/2] Prevent showing cmd on Windows and add handling for ruff execution with pythonw --- .gitignore | 2 ++ pylsp_ruff/plugin.py | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 5a9e939..b59b74a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ __pycache__/ *.swp tags /build/ + +.spyproject/ diff --git a/pylsp_ruff/plugin.py b/pylsp_ruff/plugin.py index 23af27e..bb318e0 100644 --- a/pylsp_ruff/plugin.py +++ b/pylsp_ruff/plugin.py @@ -7,7 +7,7 @@ import sys from functools import lru_cache from pathlib import PurePath -from subprocess import PIPE, Popen +from subprocess import CREATE_NO_WINDOW, PIPE, Popen from typing import Dict, Generator, List, Optional if sys.version_info >= (3, 11): @@ -502,7 +502,7 @@ def find_executable(executable) -> List[str]: # try the python module if cmd is None: if importlib.util.find_spec("ruff") is not None: - cmd = [sys.executable, "-m", "ruff"] + cmd = [sys.executable.replace("pythonw", "python"), "-m", "ruff"] # try system's ruff executable if cmd is None: @@ -557,7 +557,7 @@ def run_ruff( cmd = [*find_executable(executable), str(subcommand), *arguments] log.debug(f"Calling {cmd} on '{document_path}'") - p = Popen(cmd, stdin=PIPE, stdout=PIPE) + p = Popen(cmd, stdin=PIPE, stdout=PIPE, creationflags=CREATE_NO_WINDOW) (stdout, _) = p.communicate(document_source.encode()) if p.returncode != 0: From 4968caacdda3799e6bdea8769a8552968adbecd1 Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Thu, 25 Sep 2025 15:31:28 -0500 Subject: [PATCH 2/2] Handle CREATE_NO_WINDOW subprocess flag value (only available on Windows) --- pylsp_ruff/plugin.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pylsp_ruff/plugin.py b/pylsp_ruff/plugin.py index bb318e0..e58c68f 100644 --- a/pylsp_ruff/plugin.py +++ b/pylsp_ruff/plugin.py @@ -7,9 +7,16 @@ import sys from functools import lru_cache from pathlib import PurePath -from subprocess import CREATE_NO_WINDOW, PIPE, Popen +from subprocess import PIPE, Popen from typing import Dict, Generator, List, Optional +if sys.platform == "win32": + from subprocess import CREATE_NO_WINDOW +else: + # CREATE_NO_WINDOW flag only available on Windows. + # Set constant as default `Popen` `creationflag` kwarg value (`0`) + CREATE_NO_WINDOW = 0 + if sys.version_info >= (3, 11): import tomllib else: