Skip to content
Snippets Groups Projects
Commit f8065ea3 authored by Frederik Hennig's avatar Frederik Hennig
Browse files

moved clang-format binary check to post-init of config

parent adafdfab
No related merge requests found
......@@ -85,6 +85,15 @@ class SfgCodeStyle:
prefix = " " * self.indent_width
return indent(s, prefix)
def __post__init__(self):
if self.force_clang_format:
import shutil
if not shutil.which(self.clang_format_binary):
raise SfgException(
"`force_clang_format` set to true in code style, but clang-format binary not found."
)
@dataclass
class SfgOutputSpec:
......
......@@ -8,11 +8,8 @@ from ..exceptions import SfgException
def invoke_clang_format(code: str, codestyle: SfgCodeStyle) -> str:
args = [codestyle.clang_format_binary, f"--style={codestyle.code_style}"]
if not shutil.which("clang-format"):
if codestyle.force_clang_format:
raise SfgException("Could not find clang-format binary.")
else:
return code
if not shutil.which(codestyle.clang_format_binary):
return code
result = subprocess.run(args, input=code, capture_output=True, text=True)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment