Skip to content

Commit 49e0f5a

Browse files
committed
search by port, dont print dev info
1 parent 8c92cd8 commit 49e0f5a

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

tools/board_stubs/circuitpython_setboard/__init__.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from importlib.abc import Traversable
1010

1111

12-
def get_definitions_or_raise(board: str) -> Traversable:
12+
def get_definitions_or_exit(board: str) -> Traversable:
1313
"""Get the definitions file for a board given its name."""
1414

1515
path = resources.files("board_definitions").joinpath(board)
@@ -22,10 +22,10 @@ def get_definitions_or_raise(board: str) -> Traversable:
2222
return file
2323

2424

25-
def get_doc_or_raise(board: str) -> str:
25+
def get_doc_or_exit(board: str) -> str:
2626
"""Get the docstring for a board given its name."""
2727

28-
with get_definitions_or_raise(board).open("r") as f:
28+
with get_definitions_or_exit(board).open("r") as f:
2929
return f.read().split('"""')[1]
3030

3131

@@ -52,14 +52,10 @@ def set_board():
5252
if args.list:
5353
port_boards: defaultdict[str, list[str]] = defaultdict(list)
5454

55-
for board in resources.files("board_definitions").iterdir():
56-
# if we receive both the list flag and a board name, use it as filter
57-
if (
58-
args.chosen_board is not None
59-
and args.chosen_board.lower() not in board.name.lower()
60-
):
61-
continue
55+
# NOTE: "" in some_str == True
56+
looking_for = "" if args.chosen_board is None else args.chosen_board.lower()
6257

58+
for board in resources.files("board_definitions").iterdir():
6359
# NOTE: For the hand-crafted finding of port in the docstring, its
6460
# format is assumed to be:
6561
#
@@ -72,9 +68,12 @@ def set_board():
7268
# - Frozen libraries: ...
7369
#
7470

75-
lines = get_doc_or_raise(board).split("\n")
71+
lines = get_doc_or_exit(board).split("\n")
7672
port = lines[2].split("-")[1].split(":")[1].strip()
7773

74+
if looking_for not in board.name.lower() and looking_for not in port.lower():
75+
continue
76+
7877
port_boards[port].append(board.name)
7978

8079
if not port_boards:
@@ -98,11 +97,7 @@ def set_board():
9897
sys.stderr.write("Must select a board\n")
9998
sys.exit(1)
10099

101-
board_definitions_file = get_definitions_or_raise(args.chosen_board)
100+
board_definitions_file = get_definitions_or_exit(args.chosen_board)
102101

103102
board_stubs_file = resources.files("board-stubs").joinpath("__init__.pyi")
104103
shutil.copyfile(board_definitions_file, board_stubs_file)
105-
106-
sys.stdout.write(
107-
header("Information about the board") + get_doc_or_raise(args.chosen_board) + "\n"
108-
)

0 commit comments

Comments
 (0)