Skip to content

Commit c41950a

Browse files
committed
[genpinmap] Use Flake8 for Style Guide Enforcement
http://flake8.pycqa.org/ Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
1 parent 27cea3c commit c41950a

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

src/genpinmap/.flake8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length = 88

src/genpinmap/genpinmap_arduino.py

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import re
77
import sys
88
import textwrap
9-
from xml.dom import minidom
109
from xml.dom.minidom import parse, Node
1110
from argparse import RawTextHelpFormatter
1211

@@ -64,7 +63,7 @@ def get_gpio_af_num(pintofind, iptofind):
6463
if m.nodeType == Node.ELEMENT_NODE:
6564
for secondlevel in m.attributes.items():
6665
k += 1
67-
# if 'I2C1_SDA' in secondlevel:
66+
# if 'I2C1_SDA' in secondlevel:
6867
if iptofind in secondlevel:
6968
# DBG print (i, j, m.attributes.items())
7069
# m = IP node found
@@ -115,22 +114,22 @@ def get_gpio_af_numF1(pintofind, iptofind):
115114
for secondlevel in m.attributes.items():
116115
# print ('secondlevel ' , i, j, k , secondlevel)
117116
k += 1
118-
# if 'I2C1_SDA' in secondlevel:
117+
# if 'I2C1_SDA' in secondlevel:
119118
if iptofind in secondlevel:
120119
# m = IP node found
121120
# print (i, j, m.attributes.items())
122121
for p in m.childNodes:
123122
# p node 'RemapBlock'
124123
if (
125124
p.nodeType == Node.ELEMENT_NODE
126-
and p.hasChildNodes() == False
125+
and p.hasChildNodes() is False
127126
):
128127
mygpioaf += " AFIO_NONE"
129128
else:
130129
for s in p.childNodes:
131130
if s.nodeType == Node.ELEMENT_NODE:
132131
# s node 'Specific parameter'
133-
# DBG print (i,j,k,p.attributes.items())
132+
# print (i,j,k,p.attributes.items())
134133
for myc in s.childNodes:
135134
# DBG print (myc)
136135
if (
@@ -282,7 +281,7 @@ def print_header():
282281
""" % (
283282
datetime.datetime.now().year,
284283
os.path.basename(input_file_name),
285-
re.sub("\.c$", "", out_c_filename),
284+
re.sub("\\.c$", "", out_c_filename),
286285
)
287286
out_c_file.write(s)
288287

@@ -427,8 +426,8 @@ def print_dac():
427426
)
428427

429428

430-
def print_i2c(l):
431-
for p in l:
429+
def print_i2c(lst):
430+
for p in lst:
432431
result = get_gpio_af_num(p[1], p[2])
433432
if result != "NOTFOUND":
434433
s1 = "%-12s" % (" {" + p[0] + ",")
@@ -481,15 +480,15 @@ def print_pwm():
481480
)
482481

483482

484-
def print_uart(l):
485-
for p in l:
483+
def print_uart(lst):
484+
for p in lst:
486485
result = get_gpio_af_num(p[1], p[2])
487486
if result != "NOTFOUND":
488487
s1 = "%-12s" % (" {" + p[0] + ",")
489488
# 2nd element is the UART_XX signal
490489
b = p[2].split("_")[0]
491490
s1 += "%-9s" % (b[: len(b) - 1] + b[len(b) - 1 :] + ",")
492-
if "STM32F10" in mcu_file and l == uartrx_list:
491+
if "STM32F10" in mcu_file and lst == uartrx_list:
493492
s1 += "STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, "
494493
else:
495494
s1 += "STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, "
@@ -505,8 +504,8 @@ def print_uart(l):
505504
)
506505

507506

508-
def print_spi(l):
509-
for p in l:
507+
def print_spi(lst):
508+
for p in lst:
510509
result = get_gpio_af_num(p[1], p[2])
511510
if result != "NOTFOUND":
512511
s1 = "%-12s" % (" {" + p[0] + ",")
@@ -525,17 +524,16 @@ def print_spi(l):
525524
)
526525

527526

528-
def print_can(l):
529-
for p in l:
530-
b = p[2]
527+
def print_can(lst):
528+
for p in lst:
531529
result = get_gpio_af_num(p[1], p[2])
532530
if result != "NOTFOUND":
533531
s1 = "%-12s" % (" {" + p[0] + ",")
534532
# 2nd element is the CAN_XX signal
535533
instance = p[2].split("_")[0].replace("CAN", "")
536534
if len(instance) == 0:
537535
instance = "1"
538-
if "STM32F10" in mcu_file and l == canrd_list:
536+
if "STM32F10" in mcu_file and lst == canrd_list:
539537
s1 += "CAN" + instance + ", STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, "
540538
else:
541539
s1 += "CAN" + instance + ", STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, "
@@ -807,9 +805,9 @@ def parse_pins():
807805
args = parser.parse_args()
808806

809807
if not (os.path.isdir(cubemxdir)):
810-
print("\n ! ! ! Cube Mx seems not to be installed or not at the requested location")
808+
print("\nCube Mx seems not to be installed or not at the requested location.")
811809
print(
812-
"\n ! ! ! please check the value you set for 'CUBEMX_DIRECTORY' in '%s' file"
810+
"\nPlease check the value you set for 'CUBEMX_DIRECTORY' in '%s' file."
813811
% config_filename
814812
)
815813
quit()
@@ -819,10 +817,10 @@ def parse_pins():
819817
if args.mcu:
820818
# check input file exists
821819
if not (os.path.isfile(os.path.join(cubemxdir, args.mcu))):
822-
print("\n ! ! ! " + args.mcu + " file not found")
823-
print("\n ! ! ! Check in " + cubemxdir + " the correct name of this file")
820+
print("\n" + args.mcu + " file not found")
821+
print("\nCheck in " + cubemxdir + " the correct name of this file")
824822
print(
825-
"\n ! ! ! You may use double quotes for this file if it contains special characters"
823+
"\nYou may use double quotes for file containing special characters"
826824
)
827825
quit()
828826
mcu_list.append(args.mcu)
@@ -848,11 +846,9 @@ def parse_pins():
848846

849847
# open output file
850848
if os.path.isfile(output_c_filename):
851-
# print (" * Requested %s file already exists and will be overwritten" % out_c_filename)
852849
os.remove(output_c_filename)
853850
out_c_file = open(output_c_filename, "w")
854851
if os.path.isfile(output_h_filename):
855-
# print (" * Requested %s file already exists and will be overwritten" % out_h_filename)
856852
os.remove(output_h_filename)
857853
out_h_file = open(output_h_filename, "w")
858854

0 commit comments

Comments
 (0)