diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2020-03-30 08:28:32 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2020-03-30 09:05:53 +0200 |
commit | cd4e46ee65dab6baa6a143bf3b3f64244be36712 (patch) | |
tree | 689e53265691e782ae35a961445c975219e1155d /misc/scripts/fix_headers.py | |
parent | 0168709978154a89f137b44f33647e5d28a46250 (diff) |
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.
Diffstat (limited to 'misc/scripts/fix_headers.py')
-rwxr-xr-x | misc/scripts/fix_headers.py | 24 |
1 files changed, 12 insertions, 12 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() |