Skip to content

Commit 0a59807

Browse files
🎨 Adjust some Python formatting (#27649)
1 parent 861dd33 commit 0a59807

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

buildroot/share/PlatformIO/scripts/chitu_crypt.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def calculate_crc(contents, seed):
1212
accumulating_xor_value = seed
1313

1414
for i in range(0, len(contents), 4):
15-
value = struct.unpack('<I', contents[ i : i + 4])[0]
15+
value = struct.unpack("<I", contents[i : i + 4])[0]
1616
accumulating_xor_value = accumulating_xor_value ^ value
1717
return accumulating_xor_value
1818

@@ -29,8 +29,8 @@ def xor_block(r0, r1, block_number, block_size, file_key):
2929
# This is the block counter
3030
block_number = xor_seed * block_number
3131

32-
#load the xor key from the file
33-
r7 = file_key
32+
# load the xor key from the file
33+
r7 = file_key
3434

3535
for loop_counter in range(0, block_size):
3636
# meant to make sure different bits of the key are used.
@@ -54,10 +54,10 @@ def xor_block(r0, r1, block_number, block_size, file_key):
5454
# and then with IP
5555
xor_seed = xor_seed ^ ip
5656

57-
#Now store the byte back
57+
# Now store the byte back
5858
r1[loop_counter] = xor_seed & 0xFF
5959

60-
#increment the loop_counter
60+
# increment the loop_counter
6161
loop_counter = loop_counter + 1
6262

6363
def encrypt_file(input, output_file, file_length):
@@ -82,15 +82,15 @@ def encrypt_file(input, output_file, file_length):
8282
# write the file_key
8383
output_file.write(struct.pack("<I", file_key))
8484

85-
#TODO - how to enforce that the firmware aligns to block boundaries?
85+
# TODO: - how to enforce that the firmware aligns to block boundaries?
8686
block_count = len(input_file) // block_size
87-
print ("Block Count is ", block_count)
87+
print("Block Count is ", block_count)
8888
for block_number in range(0, block_count):
89-
block_offset = (block_number * block_size)
89+
block_offset = block_number * block_size
9090
block_end = block_offset + block_size
91-
block_array = bytearray(input_file[block_offset: block_end])
91+
block_array = bytearray(input_file[block_offset:block_end])
9292
xor_block(block_array, block_array, block_number, block_size, file_key)
93-
for n in range (0, block_size):
93+
for n in range(0, block_size):
9494
input_file[block_offset + n] = block_array[n]
9595

9696
# update the expected CRC value.

buildroot/share/PlatformIO/scripts/common-dependencies.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def validate_pio():
4141
except:
4242
print("Can't detect PlatformIO Version")
4343

44-
def blab(str,level=1):
44+
def blab(str, level=1):
4545
if verbose >= level:
4646
print("[deps] %s" % str)
4747

@@ -206,6 +206,7 @@ def addentry(fullpath, info=None):
206206
else:
207207
blab("Added src file %s " % relp, 3)
208208
cur_srcs.add(relp)
209+
209210
# Special rule: If a direct folder is specified add all files within.
210211
fullplain = os.path.join(marlinbasedir, plain)
211212
if os.path.isdir(fullplain):
@@ -218,6 +219,7 @@ def addentry(fullpath, info=None):
218219
def srepl(matchi):
219220
g0 = matchi.group(0)
220221
return r"**" + g0[1:]
222+
221223
gpattern = re.sub(r'[*]($|[^*])', srepl, plain)
222224
gpattern = os.path.join(marlinbasedir, gpattern)
223225

@@ -230,21 +232,25 @@ def onremove(relp, info=None):
230232
blab("Removed src file %s (%s)" % (relp, str(info)), 3)
231233
else:
232234
blab("Removed src file %s " % relp, 3)
235+
233236
fullplain = os.path.join(marlinbasedir, plain)
234237
if os.path.isdir(fullplain):
235238
blab("Directory content removal for %s " % plain, 2)
239+
236240
def filt(x):
237241
common = os.path.commonpath([plain, x])
238242
if not common == os.path.normpath(plain): return True
239243
onremove(x, "dcr")
240244
return False
245+
241246
cur_srcs = set(filter(filt, cur_srcs))
242247
else:
243248
# Remove matching source entries.
244249
def filt(x):
245250
if not fnmatch.fnmatch(x, plain): return True
246251
onremove(x)
247252
return False
253+
248254
cur_srcs = set(filter(filt, cur_srcs))
249255
# Transform the resulting set into a string.
250256
for x in cur_srcs:

buildroot/share/PlatformIO/scripts/configuration.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ def apply_opt(name, val, conf=None):
2828
# 7: Option value
2929
# 8: Whitespace after value
3030
# 9: End comment
31-
regex = re.compile(rf'^(\s*)(//\s*)?(#define\s+)({name}\b)(\s?)(\s*)(.*?)(\s*)(//.*)?$', re.IGNORECASE)
31+
regex = re.compile(
32+
rf"^(\s*)(//\s*)?(#define\s+)({name}\b)(\s?)(\s*)(.*?)(\s*)(//.*)?$",
33+
re.IGNORECASE
34+
)
3235

3336
# Find and enable and/or update all matches
3437
for file in ("Configuration.h", "Configuration_adv.h"):

buildroot/share/PlatformIO/scripts/preprocessor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def blab(str):
1515
# Invoke GCC to run the preprocessor and extract enabled features
1616
#
1717
preprocessor_cache = {}
18+
1819
def run_preprocessor(env, fn=None):
1920
filename = fn or 'buildroot/share/PlatformIO/scripts/common-dependencies.h'
2021
if filename in preprocessor_cache:

buildroot/share/scripts/validate_boards.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ def logmsg(msg, line):
1212

1313
# Print a formatted error
1414
def err(board, msg):
15-
print(f'[ERROR] {board:30} {msg}')
15+
print(f"[ERROR] {board:30} {msg}")
1616

1717
# Print a formatted warning
1818
def warn(board, msg):
19-
print(f'[WARNING] {board:30} {msg}')
19+
print(f"[WARNING] {board:30} {msg}")
2020

2121
def bshort(board):
2222
return board.replace('BOARD_', '')
@@ -119,7 +119,7 @@ def boards_checks(argv):
119119
print(f'[ERROR] Non-matching boards order in pins.h. Expected {bshort(boards_boards[i])} but got {bshort(pins_boards[i])}')
120120
break
121121

122-
return ERRS;
122+
return ERRS
123123

124124
if __name__ == '__main__':
125125
ERR_COUNT = boards_checks(sys.argv[1:])

0 commit comments

Comments
 (0)