File tree Expand file tree Collapse file tree 1 file changed +12
-12
lines changed
tools/board_stubs/circuitpython_setboard Expand file tree Collapse file tree 1 file changed +12
-12
lines changed Original file line number Diff line number Diff line change 1
1
# SPDX-FileCopyrightText: 2024 Tim Cocks
2
2
#
3
3
# SPDX-License-Identifier: MIT
4
- import sys
4
+ from importlib import resources
5
5
import os
6
+ import sys
6
7
import shutil
7
8
8
9
9
10
def set_board ():
11
+ if len (sys .argv ) != 2 :
12
+ print (f"Incorrect args. Please call with: 'circuitpython_setboard chosen_board'" )
13
+ return
14
+
10
15
chosen_board = sys .argv [1 ]
11
16
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
- )
19
17
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 ():
21
23
print (f"Board: '{ chosen_board } ' was not found" )
22
24
return
23
25
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