File tree Expand file tree Collapse file tree
tools/board_stubs/circuitpython_setboard Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# SPDX-FileCopyrightText: 2024 Tim Cocks
22#
33# SPDX-License-Identifier: MIT
4- import sys
4+ from importlib import resources
55import os
6+ import sys
67import shutil
78
89
910def set_board ():
11+ if len (sys .argv ) != 2 :
12+ print (f"Incorrect args. Please call with: 'circuitpython_setboard chosen_board'" )
13+ return
14+
1015 chosen_board = sys .argv [1 ]
1116 print (f"setting board: { chosen_board } " )
12- board_defs_path = (
13- os .path .sep .join (__file__ .split ("/" )[:- 2 ]) + f"{ os .path .sep } board_definitions{ os .path .sep } "
14- )
15- board_stubs_path = (
16- os .path .sep .join (__file__ .split ("/" )[:- 2 ])
17- + f"{ os .path .sep } board-stubs{ os .path .sep } __init__.pyi"
18- )
1917
20- if chosen_board not in os .listdir (board_defs_path ):
18+ board_stubs_file = resources .files ("board-stubs" ).joinpath ("__init__.pyi" )
19+ board_definitions_path = resources .files ("board_definitions" ).joinpath (chosen_board )
20+ board_definitions_file = board_definitions_path .joinpath ("__init__.pyi" )
21+
22+ if not board_definitions_file .is_file ():
2123 print (f"Board: '{ chosen_board } ' was not found" )
2224 return
2325
24- shutil .copyfile (
25- board_defs_path + f"{ os .path .sep } { chosen_board } { os .path .sep } __init__.pyi" , board_stubs_path
26- )
26+ shutil .copyfile (board_definitions_file , board_stubs_file )
You can’t perform that action at this time.
0 commit comments