format.py 730 B

12345678910111213141516171819202122
  1. import os
  2. import subprocess
  3. def get_all_files(root: str):
  4. for path, _, files in os.walk(root):
  5. for file in files:
  6. fullpath = os.path.join(path, file)
  7. # ignore some files
  8. if fullpath.startswith('include/pybind11'):
  9. continue
  10. if file.startswith('_'):
  11. continue
  12. if not file.endswith('.cpp') and not file.endswith('.h') and not file.endswith('.hpp'):
  13. continue
  14. yield fullpath
  15. if __name__ == '__main__':
  16. files = []
  17. files.extend(get_all_files('include'))
  18. files.extend(get_all_files('src'))
  19. files.extend(get_all_files('src2'))
  20. subprocess.run(['clang-format', '-i'] + files, check=True)