mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-12 16:59:00 +08:00
Update format_sources.py
This commit is contained in:
parent
ea1eb83a28
commit
75f5a12f4d
@ -3,6 +3,19 @@
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
def format_sources():
|
||||
"""
|
||||
Formats the source code files in the ESP3D project using clang-format with Google style.
|
||||
|
||||
This script recursively searches for C, C++, H, and INO files in the ESP3D project directory
|
||||
and its subdirectories. It then applies the clang-format tool to each file, using the Google
|
||||
style for formatting.
|
||||
|
||||
Note: Make sure you have clang-format installed and available in your system's PATH.
|
||||
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
# Base directory of the script
|
||||
script_path = os.path.abspath(__file__)
|
||||
|
||||
@ -12,7 +25,7 @@ script_dir = os.path.dirname(script_path)
|
||||
# Build path of sources dir: ../esp3d
|
||||
base_dir = os.path.abspath(os.path.normpath(os.path.join(script_dir, '..', 'esp3d')))
|
||||
|
||||
# Parse all c, h , cpp files in all directories and sub directories
|
||||
# Parse all c, h, cpp, and ino files in all directories and subdirectories
|
||||
file_paths = []
|
||||
for root, dirs, files in os.walk(base_dir):
|
||||
for file in files:
|
||||
@ -23,10 +36,13 @@ for root, dirs, files in os.walk(base_dir):
|
||||
# Now format all files one by one with clang-format
|
||||
for file_path in file_paths:
|
||||
tmpPath = '"' + file_path + '"'
|
||||
print("Formating " + tmpPath, end="")
|
||||
print("Formatting " + tmpPath, end="")
|
||||
try:
|
||||
command = ['clang-format', '-i', '--style=Google', file_path]
|
||||
subprocess.run(command, check=False)
|
||||
print(" => Ok")
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f'=> Error: {e}')
|
||||
|
||||
# Call the format_sources function to format the source code
|
||||
format_sources()
|
||||
|
Loading…
x
Reference in New Issue
Block a user