summaryrefslogtreecommitdiff
path: root/misc/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'misc/scripts')
-rwxr-xr-xmisc/scripts/fix_headers.py24
-rwxr-xr-xmisc/scripts/fix_style.sh20
2 files changed, 31 insertions, 13 deletions
diff --git a/misc/scripts/fix_headers.py b/misc/scripts/fix_headers.py
index f0038a8351..7af97eec4b 100755
--- a/misc/scripts/fix_headers.py
+++ b/misc/scripts/fix_headers.py
@@ -37,24 +37,24 @@ files = open("files", "r")
fname = files.readline()
-while (fname != ""):
+while fname != "":
# Handle replacing $filename with actual filename and keep alignment
fsingle = fname.strip()
- if (fsingle.find("/") != -1):
- fsingle = fsingle[fsingle.rfind("/") + 1:]
+ if fsingle.find("/") != -1:
+ fsingle = fsingle[fsingle.rfind("/") + 1 :]
rep_fl = "$filename"
rep_fi = fsingle
len_fl = len(rep_fl)
len_fi = len(rep_fi)
# Pad with spaces to keep alignment
- if (len_fi < len_fl):
+ if len_fi < len_fl:
for x in range(len_fl - len_fi):
rep_fi += " "
- elif (len_fl < len_fi):
+ elif len_fl < len_fi:
for x in range(len_fi - len_fl):
rep_fl += " "
- if (header.find(rep_fl) != -1):
+ if header.find(rep_fl) != -1:
text = header.replace(rep_fl, rep_fi)
else:
text = header.replace("$filename", fsingle)
@@ -71,21 +71,21 @@ while (fname != ""):
line = fileread.readline()
header_done = False
- while (line.strip() == ""): # Skip empty lines at the top
+ while line.strip() == "": # Skip empty lines at the top
line = fileread.readline()
- if (line.find("/**********") == -1): # Godot header starts this way
+ if line.find("/**********") == -1: # Godot header starts this way
# Maybe starting with a non-Godot comment, abort header magic
header_done = True
- while (not header_done): # Handle header now
- if (line.find("/*") != 0): # No more starting with a comment
+ while not header_done: # Handle header now
+ if line.find("/*") != 0: # No more starting with a comment
header_done = True
- if (line.strip() != ""):
+ if line.strip() != "":
text += line
line = fileread.readline()
- while (line != ""): # Dump everything until EOF
+ while line != "": # Dump everything until EOF
text += line
line = fileread.readline()
diff --git a/misc/scripts/fix_style.sh b/misc/scripts/fix_style.sh
index b33cb0a7b4..2eee61a459 100755
--- a/misc/scripts/fix_style.sh
+++ b/misc/scripts/fix_style.sh
@@ -1,9 +1,10 @@
#!/usr/bin/env bash
# Command line arguments
+run_black=false
run_clang_format=false
run_fix_headers=false
-usage="Invalid argument. Usage:\n$0 <option>\n\t--clang-format|-c\n\t--headers|-h\n\t--all|-a"
+usage="Invalid argument. Usage:\n$0 <option>\n\t--black|-b\n\t--clang-format|-c\n\t--headers|-h\n\t--all|-a"
if [ -z "$1" ]; then
echo -e $usage
@@ -12,6 +13,9 @@ fi
while [ $# -gt 0 ]; do
case "$1" in
+ --black|-b)
+ run_black=true
+ ;;
--clang-format|-c)
run_clang_format=true
;;
@@ -19,6 +23,7 @@ while [ $# -gt 0 ]; do
run_fix_headers=true
;;
--all|-a)
+ run_black=true
run_clang_format=true
run_fix_headers=true
;;
@@ -32,6 +37,19 @@ done
echo "Removing generated files, some have binary data and make clang-format freeze."
find -name "*.gen.*" -delete
+# Apply black
+if $run_black; then
+ echo -e "Formatting Python files..."
+ PY_FILES=$(find \( -path "./.git" \
+ -o -path "./thirdparty" \
+ \) -prune \
+ -o \( -name "SConstruct" \
+ -o -name "SCsub" \
+ -o -name "*.py" \
+ \) -print)
+ black -l 120 $PY_FILES
+fi
+
# Apply clang-format
if $run_clang_format; then
# Sync list with pre-commit hook