|
10 | 10 | from subprocess import PIPE, Popen |
11 | 11 | from typing import Dict, Generator, List, Optional |
12 | 12 |
|
| 13 | +if sys.platform == "win32": |
| 14 | + from subprocess import CREATE_NO_WINDOW |
| 15 | +else: |
| 16 | + # CREATE_NO_WINDOW flag only available on Windows. |
| 17 | + # Set constant as default `Popen` `creationflag` kwarg value (`0`) |
| 18 | + CREATE_NO_WINDOW = 0 |
| 19 | + |
13 | 20 | if sys.version_info >= (3, 11): |
14 | 21 | import tomllib |
15 | 22 | else: |
@@ -502,7 +509,7 @@ def find_executable(executable) -> List[str]: |
502 | 509 | # try the python module |
503 | 510 | if cmd is None: |
504 | 511 | if importlib.util.find_spec("ruff") is not None: |
505 | | - cmd = [sys.executable, "-m", "ruff"] |
| 512 | + cmd = [sys.executable.replace("pythonw", "python"), "-m", "ruff"] |
506 | 513 |
|
507 | 514 | # try system's ruff executable |
508 | 515 | if cmd is None: |
@@ -557,7 +564,7 @@ def run_ruff( |
557 | 564 | cmd = [*find_executable(executable), str(subcommand), *arguments] |
558 | 565 |
|
559 | 566 | log.debug(f"Calling {cmd} on '{document_path}'") |
560 | | - p = Popen(cmd, stdin=PIPE, stdout=PIPE) |
| 567 | + p = Popen(cmd, stdin=PIPE, stdout=PIPE, creationflags=CREATE_NO_WINDOW) |
561 | 568 | (stdout, _) = p.communicate(document_source.encode()) |
562 | 569 |
|
563 | 570 | if p.returncode != 0: |
|
0 commit comments