Skip to content

Commit a7c315d

Browse files
fpistmmassonal
authored andcommitted
fix: apply black formatter
Signed-off-by: Frederic Pillon <[email protected]>
1 parent 720d122 commit a7c315d

13 files changed

+387
-236
lines changed

Diff for: cmake/scripts/ccwrapper.py

+19-10
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,30 @@
77
import argparse
88

99
parser = argparse.ArgumentParser()
10-
parser.add_argument("--source", "-i", type=pathlib.Path, required=True, help="input file being compiled")
11-
parser.add_argument("--logdir", "-d", type=pathlib.Path, required=True, help="log directory")
12-
parser.add_argument("cmd", action="extend", nargs="+", help="full compilation command (including -H etc...)")
10+
parser.add_argument(
11+
"--source", "-i", type=pathlib.Path, required=True, help="input file being compiled"
12+
)
13+
parser.add_argument(
14+
"--logdir", "-d", type=pathlib.Path, required=True, help="log directory"
15+
)
16+
parser.add_argument(
17+
"cmd",
18+
action="extend",
19+
nargs="+",
20+
help="full compilation command (including -H etc...)",
21+
)
1322

1423
shargs = parser.parse_args()
1524

16-
logline = re.compile("^\.* .+$") # a series of dots, a space, a filename
25+
logline = re.compile("^\.* .+$") # a series of dots, a space, a filename
1726

1827

1928
proc = subprocess.run(shargs.cmd, capture_output=True, encoding="ascii")
20-
if proc.returncode != 0 :
29+
if proc.returncode != 0:
2130
exit(proc.returncode)
2231

23-
with open(shargs.logdir/(shargs.source.name+".log"), "w") as file :
24-
print(" "+str(shargs.source), file=file)
25-
for line in io.StringIO(proc.stderr) :
26-
if logline.match(line) :
27-
print(line.rstrip(), file=file) # remove trailing '\n'
32+
with open(shargs.logdir / (shargs.source.name + ".log"), "w") as file:
33+
print(" " + str(shargs.source), file=file)
34+
for line in io.StringIO(proc.stderr):
35+
if logline.match(line):
36+
print(line.rstrip(), file=file) # remove trailing '\n'

Diff for: cmake/scripts/cmake_core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
templates_dir = script_path / ".." / "templates"
1717
j2_env = Environment(
18-
loader=FileSystemLoader(str(templates_dir)), trim_blocks=True, lstrip_blocks=True
18+
loader=FileSystemLoader(str(templates_dir)), trim_blocks=True, lstrip_blocks=True
1919
)
2020
cmake_template = j2_env.get_template("CMakeLists.txt")
2121

Diff for: cmake/scripts/cmake_easy_setup.py

+87-50
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,55 @@
1313
from parse_boards import parse_file
1414

1515
parser = argparse.ArgumentParser()
16-
parser.add_argument("--cli", "-x", type=pathlib.Path, required=False, default=shutil.which("arduino-cli"), help="path to arduino-cli")
16+
parser.add_argument(
17+
"--cli",
18+
"-x",
19+
type=pathlib.Path,
20+
required=False,
21+
default=shutil.which("arduino-cli"),
22+
help="path to arduino-cli",
23+
)
1724
parser.add_argument("--board", "-b", type=str, default="", help="board name")
18-
parser.add_argument("--fire", action="store_true", default=False, help="launch the build immediately (use with caution!)")
25+
parser.add_argument(
26+
"--fire",
27+
action="store_true",
28+
default=False,
29+
help="launch the build immediately (use with caution!)",
30+
)
1931
output_args = parser.add_mutually_exclusive_group(required=True)
20-
output_args.add_argument("--output", "-o", type=pathlib.Path, help="output file (CMake) with placeholders")
21-
output_args.add_argument("--sketch", "-s", type=pathlib.Path, help="output file (CMake) filled given a sketch folder")
32+
output_args.add_argument(
33+
"--output", "-o", type=pathlib.Path, help="output file (CMake) with placeholders"
34+
)
35+
output_args.add_argument(
36+
"--sketch",
37+
"-s",
38+
type=pathlib.Path,
39+
help="output file (CMake) filled given a sketch folder",
40+
)
2241

2342
shargs = parser.parse_args()
2443
shargs.board = shargs.board.upper()
2544

26-
if shargs.sketch and not shargs.board :
27-
print("""
45+
if shargs.sketch and not shargs.board:
46+
print(
47+
"""
2848
Warning: you did not specify which board you were targeting;
2949
please review the generated CMakeLists.txt to remove the placeholder value before calling `cmake`.
30-
""")
50+
"""
51+
)
3152

32-
if shargs.cli is None :
33-
print("""
53+
if shargs.cli is None:
54+
print(
55+
"""
3456
Error: `arduino-cli` not found in $PATH.
3557
Please install arduino-cli and make it available from your system $PATH,
3658
or give its location through the `--cli` argument.
37-
""")
59+
"""
60+
)
3861
exit(-1)
3962

40-
def arduino(*args) :
63+
64+
def arduino(*args):
4165
# return (out.stdout, logfile)
4266
# raises an exception if the command fails
4367
handle, logfile = tempfile.mkstemp()
@@ -50,47 +74,50 @@ def arduino(*args) :
5074
).stdout
5175
return (out, logfile)
5276

53-
def get_log(fname) :
54-
with open(fname) as file :
55-
for line in file :
77+
78+
def get_log(fname):
79+
with open(fname) as file:
80+
for line in file:
5681
yield json.loads(line)
5782

58-
def get_boards(boardstxt) :
83+
84+
def get_boards(boardstxt):
5985

6086
# we "reject" everything because we don't care about the values, only the keys
61-
families = parse_file(boardstxt, lambda x:True)
87+
families = parse_file(boardstxt, lambda x: True)
6288
del families["menu"]
6389

6490
boards = set()
65-
for fam, famcfg in families.items() :
91+
for fam, famcfg in families.items():
6692
boards.update(famcfg.menu.pnum.keys())
6793

6894
return boards
6995

96+
7097
_, logf = arduino("lib", "list")
7198

72-
allboards = get_boards(pathlib.Path(__file__).parent.parent.parent/"boards.txt")
99+
allboards = get_boards(pathlib.Path(__file__).parent.parent.parent / "boards.txt")
73100

74101

75-
if shargs.board and shargs.board not in allboards :
102+
if shargs.board and shargs.board not in allboards:
76103
print(f"Unrecognized board name: '{shargs.board}'")
77104
print("Possible matches:")
78105
options = difflib.get_close_matches(shargs.board, allboards, n=9, cutoff=0.0)
79106
print("0. (keep as-is)")
80-
for i, x in enumerate(options, start=1) :
107+
for i, x in enumerate(options, start=1):
81108
print(f"{i}. {x}")
82109
choice = input("Choice number: ")
83-
while not choice.isdecimal() :
110+
while not choice.isdecimal():
84111
choice = input("Invalid choice *number*. Select a board: ")
85112
choice = int(choice)
86-
if choice != 0 :
113+
if choice != 0:
87114
choice -= 1
88115
shargs.board = options[choice]
89116

90117

91118
libpaths = dict()
92-
for line in get_log(logf) :
93-
if line["msg"] == "Adding libraries dir" :
119+
for line in get_log(logf):
120+
if line["msg"] == "Adding libraries dir":
94121
libpaths[line["location"]] = pathlib.Path(line["dir"])
95122

96123
# platform lib path is already known, obviously, since that's where this script resides
@@ -99,18 +126,20 @@ def get_boards(boardstxt) :
99126
corepath = pathlib.Path(__file__).parent.parent.parent.resolve()
100127

101128
j2_env = Environment(
102-
loader=FileSystemLoader(str(corepath/"cmake"/"templates")), trim_blocks=True, lstrip_blocks=True
129+
loader=FileSystemLoader(str(corepath / "cmake" / "templates")),
130+
trim_blocks=True,
131+
lstrip_blocks=True,
103132
)
104133
cmake_template = j2_env.get_template("easy_cmake.cmake")
105134

106135

107136
userhome = pathlib.Path.home()
108-
if userlibs.is_relative_to(userhome) :
137+
if userlibs.is_relative_to(userhome):
109138
userlibs = "~/" + str(userlibs.relative_to(userhome))
110-
if corepath.is_relative_to(userhome) :
139+
if corepath.is_relative_to(userhome):
111140
corepath = "~/" + str(corepath.relative_to(userhome))
112141

113-
if shargs.sketch :
142+
if shargs.sketch:
114143
SOURCEFILE_EXTS = (".c", ".cpp", ".S", ".ino")
115144
sources = {
116145
file.relative_to(shargs.sketch)
@@ -123,37 +152,45 @@ def get_boards(boardstxt) :
123152
if file.is_file() and file.suffix in SOURCEFILE_EXTS
124153
}
125154
tgtname = shargs.sketch.resolve().name
126-
else :
155+
else:
127156
tgtname = ""
128157
sources = set()
129158

130159
scriptname = pathlib.Path(__file__)
131-
if scriptname.is_relative_to(userhome) :
160+
if scriptname.is_relative_to(userhome):
132161
scriptname = "~/" + str(scriptname.relative_to(userhome))
133162

134-
with open(shargs.output or shargs.sketch/"CMakeLists.txt", "w") as out :
135-
out.write(cmake_template.render(
136-
corepath=str(corepath).replace("\\", "\\\\"), # escape backslashes for CMake
137-
userlibs=str(userlibs).replace("\\", "\\\\"),
138-
libs=libs,
139-
scriptfile=scriptname,
140-
tgtname=tgtname,
141-
scrcfiles=sources,
142-
boardname=shargs.board,
143-
))
144-
145-
146-
print("Generated", shargs.output or shargs.sketch/"CMakeLists.txt")
147-
print("""
163+
with open(shargs.output or shargs.sketch / "CMakeLists.txt", "w") as out:
164+
out.write(
165+
cmake_template.render(
166+
corepath=str(corepath).replace(
167+
"\\", "\\\\"
168+
), # escape backslashes for CMake
169+
userlibs=str(userlibs).replace("\\", "\\\\"),
170+
libs=libs,
171+
scriptfile=scriptname,
172+
tgtname=tgtname,
173+
scrcfiles=sources,
174+
boardname=shargs.board,
175+
)
176+
)
177+
178+
179+
print("Generated", shargs.output or shargs.sketch / "CMakeLists.txt")
180+
print(
181+
"""
148182
Unless you are building a very simple sketch with no library (e.g., Blink),
149183
you are advised to edit this file to fill in any missing dependency relationship.
150184
For details, please refer to
151185
https://github.com/massonal/Arduino_Core_STM32/wiki/Arduino-(in)compatibility#library-management
152-
""")
186+
"""
187+
)
153188

154-
if shargs.fire :
155-
if not (shargs.sketch and shargs.board) :
156-
print("There remains some placeholder in the output file; I won't build _that_.")
189+
if shargs.fire:
190+
if not (shargs.sketch and shargs.board):
191+
print(
192+
"There remains some placeholder in the output file; I won't build _that_."
193+
)
157194
exit(1)
158-
subprocess.run(("cmake", "-S", shargs.sketch, "-B", shargs.sketch/"build"))
159-
subprocess.run(("cmake", "--build", shargs.sketch/"build"))
195+
subprocess.run(("cmake", "-S", shargs.sketch, "-B", shargs.sketch / "build"))
196+
subprocess.run(("cmake", "--build", shargs.sketch / "build"))

0 commit comments

Comments
 (0)