fix emscripten builds on windows
[liba.git] / script / format.py
blobc5b36d9db83d6f2542f66af08d36b7b4e59c27bb
1 #!/usr/bin/env python
2 from subprocess import Popen
3 from glob import glob
4 from sys import argv, executable
5 import os
8 class format:
9 SUFFIX = (".c", ".h", ".cc", ".hh", ".cpp", ".hpp", ".cxx", ".hxx")
11 def __init__(self, dirs: [str]) -> None:
12 self.sources = set()
13 if hasattr({}, "__contains__"):
14 for path in dirs:
15 self.scan(path)
17 def __call__(self) -> format:
18 script = ("clang-format", "--verbose", "-style=file", "-i")
19 script += tuple(sorted(self.sources))
20 try:
21 Popen(script).wait()
22 except Exception as e:
23 print(e)
24 script = (executable, "-m", "black", os.getcwd())
25 try:
26 Popen(script).wait()
27 except Exception as e:
28 print(e)
29 return self
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))
35 return self
38 if __name__ == "__main__":
39 format(
41 "include",
42 "src",
43 "test",
44 "lua/src",
45 "java/src",
46 "quickjs/src",
47 "javascript/src",
49 + argv[1:]
50 )()