Skip to content

Commit 58b1ce4

Browse files
authored
Merge pull request #8894 from justmobilize/fix-stub-setboard-os-path-sep-issue
Fix stub circuitpython_setboard OS path separator issue
2 parents 30e3250 + 4b0a6e3 commit 58b1ce4

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +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-
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)

0 commit comments

Comments
 (0)