2 from subprocess
import Popen
4 from sys
import argv
, executable
9 SUFFIX
= (".c", ".h", ".cc", ".hh", ".cpp", ".hpp", ".cxx", ".hxx")
11 def __init__(self
, dirs
: [str]) -> None:
13 if hasattr({}, "__contains__"):
17 def __call__(self
) -> format
:
18 script
= ("clang-format", "--verbose", "-style=file", "-i")
19 script
+= tuple(sorted(self
.sources
))
22 except Exception as e
:
24 script
= (executable
, "-m", "black", os
.getcwd())
27 except Exception as e
:
31 def scan(self
, path
: str) -> format
:
32 for source
in glob(os
.path
.join(path
, "**"), recursive
=True):
33 if os
.path
.splitext(source
)[-1] in self
.SUFFIX
:
34 self
.sources
.add(os
.path
.relpath(source
))
38 if __name__
== "__main__":
48 format(dirs
+ argv
[1:])()