1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

SCons: Format buildsystem files with psf/black

Configured for a max line length of 120 characters.

psf/black is very opinionated and purposely doesn't leave much room for
configuration. The output is mostly OK so that should be fine for us,
but some things worth noting:

- Manually wrapped strings will be reflowed, so by using a line length
  of 120 for the sake of preserving readability for our long command
  calls, it also means that some manually wrapped strings are back on
  the same line and should be manually merged again.

- Code generators using string concatenation extensively look awful,
  since black puts each operand on a single line. We need to refactor
  these generators to use more pythonic string formatting, for which
  many options are available (`%`, `format` or f-strings).

- CI checks and a pre-commit hook will be added to ensure that future
  buildsystem changes are well-formatted.

(cherry picked from commit cd4e46ee65)
This commit is contained in:
Rémi Verschelde
2020-03-30 08:28:32 +02:00
parent c3d04167a4
commit 7bf9787921
189 changed files with 4050 additions and 3315 deletions

View File

@@ -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()