Skip to content

Commit 71e6eca

Browse files
committed
Use importlib.resources
1 parent 6bdb4ae commit 71e6eca

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
# SPDX-FileCopyrightText: 2024 Tim Cocks
22
#
33
# SPDX-License-Identifier: MIT
4-
import sys
4+
from importlib import resources
55
import os
6+
import sys
67
import shutil
78

89

910
def 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-
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"
1517

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():
1723
print(f"Board: '{chosen_board}' was not found")
1824
return
1925

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)

0 commit comments

Comments
 (0)