Skip to content

Commit 32966bb

Browse files
committed
Stylize and add function docs
1 parent ae22684 commit 32966bb

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

tools/targets/lint.py

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,60 @@
1010
from tools.targets import Target, set_targets_json_location, TARGET_MAP
1111

1212
def must_have_keys(keys, dict):
13+
"""Require keys in an MCU/Board
14+
15+
is a generator for errors
16+
"""
1317
for key in keys:
1418
if key not in dict:
1519
yield "%s not found, and is required" % key
1620

1721
def may_have_keys(keys, dict):
22+
"""Disable all other keys in an MCU/Board
23+
24+
is a generator for errors
25+
"""
1826
for key in dict.keys():
1927
if key not in keys:
2028
yield "%s found, and is not allowed" % key
2129

2230

2331
MCU_REQUIRED_KEYS = ["release_versions", "supported_toolchains",
2432
"default_lib", "public", "inherits"]
25-
MCU_ALLOWED_KEYS = ["device_has", "core", "extra_labels", "features", "bootloader_supported", "device_name", "post_binary_hook", "default_toolchain"] + MCU_REQUIRED_KEYS
33+
MCU_ALLOWED_KEYS = ["device_has", "core", "extra_labels", "features",
34+
"bootloader_supported", "device_name", "post_binary_hook",
35+
"default_toolchain"] + MCU_REQUIRED_KEYS
2636
def check_mcu(mcu_json, strict=False):
27-
"""Generate a list of problems with an mcu"""
37+
"""Generate a list of problems with an MCU
38+
39+
:param: mcu_json the MCU's dict to check
40+
:param: strict enforce required keys
41+
"""
2842
if strict:
2943
for err in must_have_keys(MCU_REQUIRED_KEYS, mcu_json):
3044
yield err
3145
for err in may_have_keys(MCU_ALLOWED_KEYS, mcu_json):
3246
yield err
3347
if 'public' in mcu_json and mcu_json['public']:
3448
yield "public must be false"
35-
if ("release_versions" in mcu_json and
36-
"5" in mcu_json["release_versions"] and
37-
"supported_toolchains" in mcu_json):
38-
for tc in ["GCC_ARM", "ARM", "IAR"]:
39-
if tc not in mcu_json["supported_toolchains"]:
49+
if ("release_versions" in mcu_json and
50+
"5" in mcu_json["release_versions"] and
51+
"supported_toolchains" in mcu_json):
52+
for toolc in ["GCC_ARM", "ARM", "IAR"]:
53+
if toolc not in mcu_json["supported_toolchains"]:
4054
yield ("%s not found in supported_toolchains, and is "
41-
"required by mbed OS 5" % tc)
55+
"required by mbed OS 5" % toolc)
4256

4357
BOARD_REQUIRED_KEYS = ["inherits"]
44-
BOARD_ALLOWED_KEYS = ["supported_form_factors", "is_disk_virtual", "detect_code", "device_name", "extra_labels", "public"] + BOARD_REQUIRED_KEYS
58+
BOARD_ALLOWED_KEYS = ["supported_form_factors", "is_disk_virtual",
59+
"detect_code", "device_name", "extra_labels",
60+
"public"] + BOARD_REQUIRED_KEYS
4561
def check_board(board_json, strict=False):
62+
"""Generate a list of problems with an board
63+
64+
:param: board_json the mcus dict to check
65+
:param: strict enforce required keys
66+
"""
4667
if strict:
4768
for err in must_have_keys(BOARD_REQUIRED_KEYS, board_json):
4869
yield err
@@ -51,10 +72,12 @@ def check_board(board_json, strict=False):
5172

5273

5374
def add_if(dict, key, val):
75+
"""Add a value to a dict if it's non-empty"""
5476
if val:
5577
dict[key] = val
5678

5779
def _split_boards(resolution_order, tgt):
80+
"""Split the resolution order between boards and mcus"""
5881
mcus = []
5982
boards = []
6083
iterable = iter(resolution_order)
@@ -128,11 +151,13 @@ def check_hierarchy(tgt):
128151

129152

130153
def main():
154+
"""entry point"""
131155
import argparse
132156
parser = argparse.ArgumentParser()
133-
parser.add_argument("mcu", choices=TARGET_MAP.keys(), metavar="MCU")
157+
parser.add_argument("mcu", choices=TARGET_MAP.keys(), metavar="MCU", )
134158
options = parser.parse_args()
135-
print dump(check_hierarchy(TARGET_MAP[options.mcu]), default_flow_style=False)
159+
print dump(check_hierarchy(TARGET_MAP[options.mcu]),
160+
default_flow_style=False)
136161
return 0
137162

138163
if __name__ == "__main__":

0 commit comments

Comments
 (0)