File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed
tools/board_stubs/circuitpython_setboard Expand file tree Collapse file tree 1 file changed +12
-8
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
- site_packages_path = os .path .sep .join (__file__ .split (os .path .sep )[:- 2 ])
13
- board_defs_path = f"{ site_packages_path } { os .path .sep } board_definitions{ os .path .sep } "
14
- board_stubs_path = f"{ site_packages_path } { os .path .sep } board-stubs{ os .path .sep } __init__.pyi"
15
17
16
- 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 ():
17
23
print (f"Board: '{ chosen_board } ' was not found" )
18
24
return
19
25
20
- shutil .copyfile (
21
- board_defs_path + f"{ os .path .sep } { chosen_board } { os .path .sep } __init__.pyi" , board_stubs_path
22
- )
26
+ shutil .copyfile (board_definitions_file , board_stubs_file )
You can’t perform that action at this time.
0 commit comments