9
9
from importlib .abc import Traversable
10
10
11
11
12
- def get_definitions_or_raise (board : str ) -> Traversable :
12
+ def get_definitions_or_exit (board : str ) -> Traversable :
13
13
"""Get the definitions file for a board given its name."""
14
14
15
15
path = resources .files ("board_definitions" ).joinpath (board )
@@ -22,10 +22,10 @@ def get_definitions_or_raise(board: str) -> Traversable:
22
22
return file
23
23
24
24
25
- def get_doc_or_raise (board : str ) -> str :
25
+ def get_doc_or_exit (board : str ) -> str :
26
26
"""Get the docstring for a board given its name."""
27
27
28
- with get_definitions_or_raise (board ).open ("r" ) as f :
28
+ with get_definitions_or_exit (board ).open ("r" ) as f :
29
29
return f .read ().split ('"""' )[1 ]
30
30
31
31
@@ -52,14 +52,10 @@ def set_board():
52
52
if args .list :
53
53
port_boards : defaultdict [str , list [str ]] = defaultdict (list )
54
54
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 ()
62
57
58
+ for board in resources .files ("board_definitions" ).iterdir ():
63
59
# NOTE: For the hand-crafted finding of port in the docstring, its
64
60
# format is assumed to be:
65
61
#
@@ -72,9 +68,12 @@ def set_board():
72
68
# - Frozen libraries: ...
73
69
#
74
70
75
- lines = get_doc_or_raise (board ).split ("\n " )
71
+ lines = get_doc_or_exit (board ).split ("\n " )
76
72
port = lines [2 ].split ("-" )[1 ].split (":" )[1 ].strip ()
77
73
74
+ if looking_for not in board .name .lower () and looking_for not in port .lower ():
75
+ continue
76
+
78
77
port_boards [port ].append (board .name )
79
78
80
79
if not port_boards :
@@ -98,11 +97,7 @@ def set_board():
98
97
sys .stderr .write ("Must select a board\n " )
99
98
sys .exit (1 )
100
99
101
- board_definitions_file = get_definitions_or_raise (args .chosen_board )
100
+ board_definitions_file = get_definitions_or_exit (args .chosen_board )
102
101
103
102
board_stubs_file = resources .files ("board-stubs" ).joinpath ("__init__.pyi" )
104
103
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