Make packagebuilder not crash if linter doesn't exist

This commit is contained in:
Theodore Aptekarev
2023-07-10 16:06:36 +02:00
parent 6f0e3946ec
commit eceb4a232e

View File

@@ -1,4 +1,5 @@
import builtins
import shutil
import subprocess
from collections import OrderedDict
from dataclasses import MISSING
@@ -484,14 +485,17 @@ class Linters:
linter: Literal["black", "ruff", "mypy"], flags: Optional[List[str]] = None
):
"""Run linter with flags."""
print(f"\n* {linter}")
Linters.print_separator("^")
command = [linter, Linters.current_folder]
if flags:
command.extend(flags)
if shutil.which(linter):
print(f"\n* {linter}")
Linters.print_separator("^")
command = [linter, Linters.current_folder]
if flags:
command.extend(flags)
subprocess.run(command, check=False)
Linters.print_separator("-")
subprocess.run(command, check=False) # noqa: S603
Linters.print_separator("-")
else:
print(f"\n* {linter} not found")
@classmethod
def black(cls):