Skip to content
Snippets Groups Projects
Select Git revision
  • ba2ff160097154b4a16e29a12abad347febd705f
  • master default protected
  • rangersbach/c-interfacing
  • fhennig/devel
  • v0.1a4
  • v0.1a3
  • v0.1a2
  • v0.1a1
8 results

index.md

Blame
  • clang_format.py 749 B
    import subprocess
    import shutil
    
    from ..configuration import SfgCodeStyle
    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
    
        result = subprocess.run(args, input=code, capture_output=True, text=True)
    
        if result.returncode != 0:
            if codestyle.force_clang_format:
                raise SfgException(f"Call to clang-format failed: \n{result.stderr}")
            else:
                return code
    
        return result.stdout