micropython-stubber 1.20.0__py3-none-any.whl → 1.20.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {micropython_stubber-1.20.0.dist-info → micropython_stubber-1.20.2.dist-info}/METADATA +6 -6
- {micropython_stubber-1.20.0.dist-info → micropython_stubber-1.20.2.dist-info}/RECORD +58 -51
- mpflash/README.md +54 -35
- mpflash/libusb_flash.ipynb +203 -203
- mpflash/mpflash/add_firmware.py +98 -0
- mpflash/mpflash/ask_input.py +106 -114
- mpflash/mpflash/cli_download.py +58 -37
- mpflash/mpflash/cli_flash.py +77 -35
- mpflash/mpflash/cli_group.py +14 -12
- mpflash/mpflash/cli_list.py +40 -4
- mpflash/mpflash/cli_main.py +20 -8
- mpflash/mpflash/common.py +125 -12
- mpflash/mpflash/config.py +2 -0
- mpflash/mpflash/connected.py +74 -0
- mpflash/mpflash/download.py +67 -50
- mpflash/mpflash/downloaded.py +9 -9
- mpflash/mpflash/flash.py +2 -2
- mpflash/mpflash/flash_esp.py +2 -2
- mpflash/mpflash/flash_uf2.py +16 -8
- mpflash/mpflash/flash_uf2_linux.py +5 -16
- mpflash/mpflash/flash_uf2_macos.py +78 -0
- mpflash/mpflash/flash_uf2_windows.py +1 -1
- mpflash/mpflash/list.py +58 -57
- mpflash/mpflash/mpboard_id/__init__.py +37 -44
- mpflash/mpflash/mpboard_id/add_boards.py +255 -0
- mpflash/mpflash/mpboard_id/board.py +37 -0
- mpflash/mpflash/mpboard_id/board_id.py +50 -43
- mpflash/mpflash/mpboard_id/board_info.zip +0 -0
- mpflash/mpflash/mpboard_id/store.py +42 -0
- mpflash/mpflash/mpremoteboard/__init__.py +18 -6
- mpflash/mpflash/mpremoteboard/runner.py +12 -12
- mpflash/mpflash/uf2disk.py +12 -0
- mpflash/mpflash/vendor/basicgit.py +288 -0
- mpflash/mpflash/vendor/dfu.py +1 -0
- mpflash/mpflash/vendor/versions.py +7 -3
- mpflash/mpflash/worklist.py +71 -48
- mpflash/poetry.lock +163 -137
- mpflash/pyproject.toml +18 -15
- stubber/__init__.py +1 -1
- stubber/board/createstubs.py +4 -3
- stubber/board/createstubs_db.py +5 -7
- stubber/board/createstubs_db_min.py +1 -1
- stubber/board/createstubs_db_mpy.mpy +0 -0
- stubber/board/createstubs_mem.py +6 -7
- stubber/board/createstubs_mem_min.py +1 -1
- stubber/board/createstubs_mem_mpy.mpy +0 -0
- stubber/board/createstubs_min.py +2 -2
- stubber/board/createstubs_mpy.mpy +0 -0
- stubber/board/modulelist.txt +1 -0
- stubber/commands/get_core_cmd.py +7 -6
- stubber/commands/get_docstubs_cmd.py +8 -3
- stubber/commands/get_frozen_cmd.py +5 -2
- stubber/publish/publish.py +18 -7
- stubber/utils/makeversionhdr.py +3 -2
- stubber/utils/versions.py +2 -1
- mpflash/mpflash/mpboard_id/board_info.csv +0 -2213
- mpflash/mpflash/mpboard_id/board_info.json +0 -19910
- {micropython_stubber-1.20.0.dist-info → micropython_stubber-1.20.2.dist-info}/LICENSE +0 -0
- {micropython_stubber-1.20.0.dist-info → micropython_stubber-1.20.2.dist-info}/WHEEL +0 -0
- {micropython_stubber-1.20.0.dist-info → micropython_stubber-1.20.2.dist-info}/entry_points.txt +0 -0
mpflash/mpflash/downloaded.py
CHANGED
@@ -16,11 +16,11 @@ def downloaded_firmwares(fw_folder: Path) -> List[FWInfo]:
|
|
16
16
|
firmwares: List[FWInfo] = []
|
17
17
|
try:
|
18
18
|
with jsonlines.open(fw_folder / "firmware.jsonl") as reader:
|
19
|
-
firmwares.
|
19
|
+
firmwares = [FWInfo.from_dict(item) for item in reader]
|
20
20
|
except FileNotFoundError:
|
21
21
|
log.error(f"No firmware.jsonl found in {fw_folder}")
|
22
22
|
# sort by filename
|
23
|
-
firmwares.sort(key=lambda x: x
|
23
|
+
firmwares.sort(key=lambda x: x.filename)
|
24
24
|
return firmwares
|
25
25
|
|
26
26
|
|
@@ -68,7 +68,7 @@ def find_downloaded_firmware(
|
|
68
68
|
)
|
69
69
|
# hope we have a match now for the board
|
70
70
|
# sort by filename
|
71
|
-
fw_list.sort(key=lambda x: x
|
71
|
+
fw_list.sort(key=lambda x: x.filename)
|
72
72
|
return fw_list
|
73
73
|
|
74
74
|
|
@@ -84,23 +84,23 @@ def filter_downloaded_fwlist(
|
|
84
84
|
"""Filter the downloaded firmware list based on the provided parameters"""
|
85
85
|
if "preview" in version:
|
86
86
|
# never get a preview for an older version
|
87
|
-
fw_list = [fw for fw in fw_list if fw
|
87
|
+
fw_list = [fw for fw in fw_list if fw.preview]
|
88
88
|
else:
|
89
|
-
fw_list = [fw for fw in fw_list if fw
|
89
|
+
fw_list = [fw for fw in fw_list if fw.version == version]
|
90
90
|
|
91
91
|
# filter by port
|
92
92
|
if port:
|
93
|
-
fw_list = [fw for fw in fw_list if fw
|
93
|
+
fw_list = [fw for fw in fw_list if fw.port == port]
|
94
94
|
|
95
95
|
if board_id:
|
96
96
|
if variants:
|
97
97
|
# any variant of this board_id
|
98
|
-
fw_list = [fw for fw in fw_list if fw
|
98
|
+
fw_list = [fw for fw in fw_list if fw.board == board_id]
|
99
99
|
else:
|
100
100
|
# the firmware variant should match exactly the board_id
|
101
|
-
fw_list = [fw for fw in fw_list if fw
|
101
|
+
fw_list = [fw for fw in fw_list if fw.variant == board_id]
|
102
102
|
if selector and port in selector:
|
103
|
-
fw_list = [fw for fw in fw_list if fw
|
103
|
+
fw_list = [fw for fw in fw_list if fw.filename.endswith(selector[port])]
|
104
104
|
return fw_list
|
105
105
|
|
106
106
|
|
mpflash/mpflash/flash.py
CHANGED
@@ -23,11 +23,11 @@ def flash_list(
|
|
23
23
|
"""Flash a list of boards with the specified firmware."""
|
24
24
|
flashed = []
|
25
25
|
for mcu, fw_info in todo:
|
26
|
-
fw_file = fw_folder / fw_info
|
26
|
+
fw_file = fw_folder / fw_info.filename
|
27
27
|
if not fw_file.exists():
|
28
28
|
log.error(f"File {fw_file} does not exist, skipping {mcu.board} on {mcu.serialport}")
|
29
29
|
continue
|
30
|
-
log.info(f"Updating {mcu.board} on {mcu.serialport} to {fw_info
|
30
|
+
log.info(f"Updating {mcu.board} on {mcu.serialport} to {fw_info.version}")
|
31
31
|
updated = None
|
32
32
|
# try:
|
33
33
|
if mcu.port in [port for port, exts in PORT_FWTYPES.items() if ".uf2" in exts] and fw_file.suffix == ".uf2":
|
mpflash/mpflash/flash_esp.py
CHANGED
@@ -10,7 +10,7 @@ from typing import List, Optional
|
|
10
10
|
import esptool
|
11
11
|
from loguru import logger as log
|
12
12
|
|
13
|
-
from mpflash.mpboard_id import
|
13
|
+
from mpflash.mpboard_id import find_known_board
|
14
14
|
from mpflash.mpremoteboard import MPRemoteBoard
|
15
15
|
|
16
16
|
|
@@ -22,7 +22,7 @@ def flash_esp(mcu: MPRemoteBoard, fw_file: Path, *, erase: bool = True) -> Optio
|
|
22
22
|
log.info(f"Flashing {fw_file} on {mcu.board} on {mcu.serialport}")
|
23
23
|
if not mcu.cpu:
|
24
24
|
# Lookup CPU based on the board name
|
25
|
-
mcu.cpu =
|
25
|
+
mcu.cpu = find_known_board(mcu.board).cpu
|
26
26
|
|
27
27
|
cmds: List[List[str]] = []
|
28
28
|
if erase:
|
mpflash/mpflash/flash_uf2.py
CHANGED
@@ -14,7 +14,9 @@ from rich.progress import track
|
|
14
14
|
from mpflash.mpremoteboard import MPRemoteBoard
|
15
15
|
|
16
16
|
from .common import PORT_FWTYPES
|
17
|
-
from .
|
17
|
+
from .config import config
|
18
|
+
from .flash_uf2_linux import dismount_uf2_linux, wait_for_UF2_linux
|
19
|
+
from .flash_uf2_macos import wait_for_UF2_macos
|
18
20
|
from .flash_uf2_windows import wait_for_UF2_windows
|
19
21
|
|
20
22
|
|
@@ -27,9 +29,9 @@ def flash_uf2(mcu: MPRemoteBoard, fw_file: Path, erase: bool) -> Optional[MPRemo
|
|
27
29
|
- copy the firmware file to the drive
|
28
30
|
- wait for the device to restart (5s)
|
29
31
|
|
30
|
-
for
|
31
|
-
|
32
|
-
|
32
|
+
for Linux - to support headless operation ( GH Actions ) :
|
33
|
+
pmount and pumount are used to mount and unmount the drive
|
34
|
+
as this is not done automatically by the OS in headless mode.
|
33
35
|
"""
|
34
36
|
if ".uf2" not in PORT_FWTYPES[mcu.port]:
|
35
37
|
log.error(f"UF2 not supported on {mcu.board} on {mcu.serialport}")
|
@@ -41,9 +43,15 @@ def flash_uf2(mcu: MPRemoteBoard, fw_file: Path, erase: bool) -> Optional[MPRemo
|
|
41
43
|
destination = wait_for_UF2_linux()
|
42
44
|
elif sys.platform == "win32":
|
43
45
|
destination = wait_for_UF2_windows()
|
46
|
+
elif sys.platform == "darwin":
|
47
|
+
log.warning(f"OS {sys.platform} not tested/supported")
|
48
|
+
# TODO: test which of the options is best
|
49
|
+
if "macos_uf2" in config.tests:
|
50
|
+
destination = wait_for_UF2_macos()
|
51
|
+
else:
|
52
|
+
destination = wait_for_UF2_linux()
|
44
53
|
else:
|
45
54
|
log.warning(f"OS {sys.platform} not tested/supported")
|
46
|
-
destination = wait_for_UF2_linux()
|
47
55
|
return None
|
48
56
|
|
49
57
|
if not destination or not destination.exists() or not (destination / "INFO_UF2.TXT").exists():
|
@@ -54,8 +62,8 @@ def flash_uf2(mcu: MPRemoteBoard, fw_file: Path, erase: bool) -> Optional[MPRemo
|
|
54
62
|
log.info(f"Copying {fw_file} to {destination}.")
|
55
63
|
shutil.copy(fw_file, destination)
|
56
64
|
log.success("Done copying, resetting the board and wait for it to restart")
|
57
|
-
if sys.platform in ["linux"
|
58
|
-
|
59
|
-
for _ in track(range(5 + 2), description="Waiting for the board to restart", transient=True):
|
65
|
+
if sys.platform in ["linux"]:
|
66
|
+
dismount_uf2_linux()
|
67
|
+
for _ in track(range(5 + 2), description="Waiting for the board to restart", transient=True, refresh_per_second=2):
|
60
68
|
time.sleep(1) # 5 secs to short on linux
|
61
69
|
return mcu
|
@@ -13,28 +13,15 @@ from loguru import logger as log
|
|
13
13
|
from rich.progress import track
|
14
14
|
|
15
15
|
from .flash_uf2_boardid import get_board_id
|
16
|
+
from .uf2disk import UF2Disk
|
16
17
|
|
17
18
|
glb_dismount_me: List[UF2Disk] = []
|
18
19
|
|
19
20
|
|
20
|
-
class UF2Disk:
|
21
|
-
"""Info to support mounting and unmounting of UF2 drives on linux"""
|
22
|
-
|
23
|
-
device_path: str
|
24
|
-
label: str
|
25
|
-
mountpoint: str
|
26
|
-
|
27
|
-
def __repr__(self):
|
28
|
-
return repr(self.__dict__)
|
29
|
-
|
30
|
-
|
31
21
|
def get_uf2_drives():
|
32
22
|
"""
|
33
23
|
Get a list of all the (un)mounted UF2 drives
|
34
24
|
"""
|
35
|
-
if sys.platform != "linux":
|
36
|
-
log.error("pumount only works on Linux")
|
37
|
-
return
|
38
25
|
# import blkinfo only on linux
|
39
26
|
from blkinfo import BlkDiskInfo
|
40
27
|
|
@@ -101,7 +88,7 @@ def pumount(disk: UF2Disk):
|
|
101
88
|
log.warning(f"{disk.label} already dismounted")
|
102
89
|
|
103
90
|
|
104
|
-
def
|
91
|
+
def dismount_uf2_linux():
|
105
92
|
global glb_dismount_me
|
106
93
|
for disk in glb_dismount_me:
|
107
94
|
pumount(disk)
|
@@ -113,7 +100,9 @@ def wait_for_UF2_linux(s_max: int = 10):
|
|
113
100
|
wait = 10
|
114
101
|
uf2_drives = []
|
115
102
|
# while not destination and wait > 0:
|
116
|
-
for _ in track(
|
103
|
+
for _ in track(
|
104
|
+
range(s_max), description="Waiting for mcu to mount as a drive", transient=True, refresh_per_second=2
|
105
|
+
):
|
117
106
|
# log.info(f"Waiting for mcu to mount as a drive : {wait} seconds left")
|
118
107
|
uf2_drives += list(get_uf2_drives())
|
119
108
|
for drive in get_uf2_drives():
|
@@ -0,0 +1,78 @@
|
|
1
|
+
""" Flashing UF2 based MCU on macos"""
|
2
|
+
|
3
|
+
# sourcery skip: snake-case-functions
|
4
|
+
from __future__ import annotations
|
5
|
+
|
6
|
+
import sys
|
7
|
+
import time
|
8
|
+
from pathlib import Path
|
9
|
+
|
10
|
+
from loguru import logger as log
|
11
|
+
from rich.progress import track
|
12
|
+
|
13
|
+
from .flash_uf2_boardid import get_board_id
|
14
|
+
from .uf2disk import UF2Disk
|
15
|
+
|
16
|
+
|
17
|
+
def get_uf2_drives():
|
18
|
+
"""
|
19
|
+
Get a list of all the (un)mounted UF2 drives
|
20
|
+
"""
|
21
|
+
if sys.platform != "linux":
|
22
|
+
log.error("pumount only works on Linux")
|
23
|
+
return
|
24
|
+
# import blkinfo only on linux
|
25
|
+
from blkinfo import BlkDiskInfo
|
26
|
+
|
27
|
+
myblkd = BlkDiskInfo()
|
28
|
+
filters = {
|
29
|
+
"tran": "usb",
|
30
|
+
}
|
31
|
+
usb_disks = myblkd.get_disks(filters)
|
32
|
+
for disk in usb_disks:
|
33
|
+
if disk["fstype"] == "vfat":
|
34
|
+
uf2_part = disk
|
35
|
+
# unpartioned usb disk or partition (e.g. /dev/sdb )
|
36
|
+
# SEEED WIO Terminal is unpartioned
|
37
|
+
# print( json.dumps(uf2_part, indent=4))
|
38
|
+
uf2 = UF2Disk()
|
39
|
+
uf2.device_path = "/dev/" + uf2_part["name"]
|
40
|
+
uf2.label = uf2_part["label"]
|
41
|
+
uf2.mountpoint = uf2_part["mountpoint"]
|
42
|
+
yield uf2
|
43
|
+
elif disk["type"] == "disk" and disk.get("children") and len(disk.get("children")) > 0:
|
44
|
+
if disk.get("children")[0]["type"] == "part" and disk.get("children")[0]["fstype"] == "vfat":
|
45
|
+
uf2_part = disk.get("children")[0]
|
46
|
+
# print( json.dumps(uf2_part, indent=4))
|
47
|
+
uf2 = UF2Disk()
|
48
|
+
uf2.device_path = "/dev/" + uf2_part["name"]
|
49
|
+
uf2.label = uf2_part["label"]
|
50
|
+
uf2.mountpoint = uf2_part["mountpoint"]
|
51
|
+
yield uf2
|
52
|
+
|
53
|
+
|
54
|
+
def wait_for_UF2_macos(s_max: int = 10):
|
55
|
+
destination = ""
|
56
|
+
wait = 10
|
57
|
+
uf2_drives = []
|
58
|
+
# while not destination and wait > 0:
|
59
|
+
for _ in track(
|
60
|
+
range(s_max), description="Waiting for mcu to mount as a drive", transient=True, refresh_per_second=2
|
61
|
+
):
|
62
|
+
# log.info(f"Waiting for mcu to mount as a drive : {wait} seconds left")
|
63
|
+
uf2_drives += list(get_uf2_drives())
|
64
|
+
for drive in get_uf2_drives():
|
65
|
+
time.sleep(1)
|
66
|
+
try:
|
67
|
+
if Path(drive.mountpoint, "INFO_UF2.TXT").exists():
|
68
|
+
board_id = get_board_id(Path(drive.mountpoint)) # type: ignore
|
69
|
+
destination = Path(drive.mountpoint)
|
70
|
+
break
|
71
|
+
except PermissionError:
|
72
|
+
log.debug(f"Permission error on {drive.mountpoint}")
|
73
|
+
continue
|
74
|
+
if destination:
|
75
|
+
break
|
76
|
+
time.sleep(1)
|
77
|
+
wait -= 1
|
78
|
+
return destination
|
@@ -17,7 +17,7 @@ def wait_for_UF2_windows(s_max: int = 10):
|
|
17
17
|
if s_max < 1:
|
18
18
|
s_max = 10
|
19
19
|
destination = ""
|
20
|
-
for _ in track(range(s_max), description="Waiting for mcu to mount as a drive", transient=True):
|
20
|
+
for _ in track(range(s_max), description="Waiting for mcu to mount as a drive", transient=True,refresh_per_second=2):
|
21
21
|
# log.info(f"Waiting for mcu to mount as a drive : {n} seconds left")
|
22
22
|
drives = [drive.device for drive in psutil.disk_partitions()]
|
23
23
|
for drive in drives:
|
mpflash/mpflash/list.py
CHANGED
@@ -1,88 +1,89 @@
|
|
1
1
|
from typing import List
|
2
2
|
|
3
|
-
from rich import
|
4
|
-
from rich.
|
5
|
-
from rich.table import Column, Table
|
3
|
+
from rich.progress import track
|
4
|
+
from rich.table import Table
|
6
5
|
|
7
6
|
from mpflash.mpremoteboard import MPRemoteBoard
|
7
|
+
from mpflash.vendor.versions import clean_version
|
8
8
|
|
9
|
-
from .config import config
|
10
9
|
from .logger import console
|
11
10
|
|
12
|
-
rp_spinner = SpinnerColumn(finished_text="✅")
|
13
|
-
rp_text = TextColumn("{task.description} {task.fields[device]}", table_column=Column())
|
14
|
-
rp_bar = BarColumn(bar_width=None, table_column=Column())
|
15
11
|
|
12
|
+
def show_mcus(
|
13
|
+
conn_mcus: List[MPRemoteBoard],
|
14
|
+
title: str = "Connected boards",
|
15
|
+
refresh: bool = True,
|
16
|
+
):
|
17
|
+
console.print(mcu_table(conn_mcus, title, refresh))
|
16
18
|
|
17
|
-
def list_mcus(bluetooth: bool = False):
|
18
|
-
"""
|
19
|
-
Retrieves information about connected microcontroller boards.
|
20
|
-
|
21
|
-
Returns:
|
22
|
-
List[MPRemoteBoard]: A list of MPRemoteBoard instances with board information.
|
23
|
-
Raises:
|
24
|
-
ConnectionError: If there is an error connecting to a board.
|
25
|
-
"""
|
26
|
-
conn_mcus = [MPRemoteBoard(sp) for sp in MPRemoteBoard.connected_boards(bluetooth) if sp not in config.ignore_ports]
|
27
19
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
progress.start_task(tsk_scan)
|
34
|
-
try:
|
35
|
-
for mcu in conn_mcus:
|
36
|
-
progress.update(tsk_scan, device=mcu.serialport.replace("/dev/", ""))
|
37
|
-
try:
|
38
|
-
mcu.get_mcu_info()
|
39
|
-
except ConnectionError as e:
|
40
|
-
print(f"Error: {e}")
|
41
|
-
continue
|
42
|
-
finally:
|
43
|
-
# transient
|
44
|
-
progress.stop_task(tsk_scan)
|
45
|
-
progress.tasks[tsk_scan].visible = False
|
46
|
-
return conn_mcus
|
20
|
+
def abbrv_family(family: str, is_wide: bool) -> str:
|
21
|
+
if not is_wide:
|
22
|
+
ABRV = {"micropython": "upy", "circuitpython": "cpy", "unknown": "?"}
|
23
|
+
return ABRV.get(family, family[:4])
|
24
|
+
return family
|
47
25
|
|
48
26
|
|
49
|
-
def
|
27
|
+
def mcu_table(
|
50
28
|
conn_mcus: List[MPRemoteBoard],
|
51
29
|
title: str = "Connected boards",
|
52
30
|
refresh: bool = True,
|
53
|
-
):
|
54
|
-
"""
|
31
|
+
):
|
32
|
+
"""
|
33
|
+
builds a rich table with the connected boards information
|
34
|
+
The columns of the table are adjusted to the terminal width
|
35
|
+
the columns are :
|
36
|
+
Narrow Wide
|
37
|
+
- Serial Yes Yes
|
38
|
+
- Family abbrv. Yes
|
39
|
+
- Port - yes
|
40
|
+
- Board Yes Yes BOARD_ID and Description
|
41
|
+
- CPU - Yes
|
42
|
+
- Version Yes Yes
|
43
|
+
- Build * * only if any of the mcus have a build
|
44
|
+
"""
|
55
45
|
table = Table(
|
56
46
|
title=title,
|
57
47
|
title_style="magenta",
|
58
48
|
header_style="bold magenta",
|
59
49
|
collapse_padding=True,
|
60
|
-
|
50
|
+
padding=(0, 0),
|
61
51
|
)
|
62
|
-
|
63
|
-
|
64
|
-
|
52
|
+
# check if the terminal is wide enough to show all columns or if we need to collapse some
|
53
|
+
is_wide = console.width > 99
|
54
|
+
needs_build = any(mcu.build for mcu in conn_mcus)
|
55
|
+
|
56
|
+
table.add_column("Serial" if is_wide else "Ser.", overflow="fold")
|
57
|
+
table.add_column("Family" if is_wide else "Fam.", overflow="crop", max_width=None if is_wide else 4)
|
58
|
+
if is_wide:
|
59
|
+
table.add_column("Port")
|
65
60
|
table.add_column("Board", overflow="fold")
|
66
61
|
# table.add_column("Variant") # TODO: add variant
|
67
|
-
|
68
|
-
|
69
|
-
table.add_column("
|
62
|
+
if is_wide:
|
63
|
+
table.add_column("CPU")
|
64
|
+
table.add_column("Version", overflow="fold", min_width=5, max_width=16)
|
65
|
+
if needs_build:
|
66
|
+
table.add_column("Build" if is_wide else "Bld", justify="right")
|
70
67
|
|
71
|
-
for mcu in track(conn_mcus, description="Updating board info", transient=True,
|
68
|
+
for mcu in track(conn_mcus, description="Updating board info", transient=True, refresh_per_second=2):
|
72
69
|
if refresh:
|
73
70
|
try:
|
74
71
|
mcu.get_mcu_info()
|
75
72
|
except ConnectionError:
|
76
73
|
continue
|
77
74
|
description = f"[italic bright_cyan]{mcu.description}" if mcu.description else ""
|
78
|
-
|
75
|
+
row = [
|
79
76
|
mcu.serialport.replace("/dev/", ""),
|
80
|
-
mcu.family,
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
mcu.
|
87
|
-
)
|
88
|
-
|
77
|
+
abbrv_family(mcu.family, is_wide),
|
78
|
+
]
|
79
|
+
if is_wide:
|
80
|
+
row.append(mcu.port)
|
81
|
+
row.append(f"{mcu.board}\n{description}".strip())
|
82
|
+
if is_wide:
|
83
|
+
row.append(mcu.cpu)
|
84
|
+
row.append(clean_version(mcu.version))
|
85
|
+
if needs_build:
|
86
|
+
row.append(mcu.build)
|
87
|
+
|
88
|
+
table.add_row(*row)
|
89
|
+
return table
|
@@ -4,53 +4,38 @@ that is included in the module.
|
|
4
4
|
|
5
5
|
"""
|
6
6
|
|
7
|
-
import json
|
8
7
|
from functools import lru_cache
|
9
|
-
from
|
10
|
-
from typing import List, Optional, Tuple, TypedDict, Union
|
8
|
+
from typing import List, Optional, Tuple
|
11
9
|
|
12
10
|
from mpflash.errors import MPFlashError
|
13
|
-
from mpflash.
|
11
|
+
from mpflash.mpboard_id.board import Board
|
12
|
+
from mpflash.mpboard_id.store import read_known_boardinfo
|
14
13
|
from mpflash.vendor.versions import clean_version
|
15
14
|
|
15
|
+
# KNOWN ports and boards are sourced from the micropython repo,
|
16
|
+
# this info is stored in the board_info.json file
|
16
17
|
|
17
|
-
# Board based on the dataclass Board but changed to TypedDict
|
18
|
-
# - source : get_boardnames.py
|
19
|
-
class Board(TypedDict):
|
20
|
-
"""MicroPython Board definition"""
|
21
18
|
|
22
|
-
|
23
|
-
port: str
|
24
|
-
board: str
|
25
|
-
board_name: str
|
26
|
-
mcu_name: str
|
27
|
-
path: Union[Path, str]
|
28
|
-
version: str
|
29
|
-
cpu: str
|
30
|
-
|
31
|
-
|
32
|
-
@lru_cache(maxsize=None)
|
33
|
-
def read_stored_boardinfo() -> List[Board]:
|
34
|
-
"""Reads the board_info.json file and returns the data as a list of Board objects"""
|
35
|
-
with open(Path(__file__).parent / "board_info.json", "r") as file:
|
36
|
-
return json.load(file)
|
37
|
-
|
38
|
-
|
39
|
-
def local_mp_ports() -> List[str]:
|
19
|
+
def get_known_ports() -> List[str]:
|
40
20
|
# TODO: Filter for Version
|
41
|
-
mp_boards =
|
21
|
+
mp_boards = read_known_boardinfo()
|
42
22
|
# select the unique ports from info
|
43
|
-
ports = set({board
|
23
|
+
ports = set({board.port for board in mp_boards if board.port})
|
44
24
|
return sorted(list(ports))
|
45
25
|
|
46
26
|
|
47
|
-
def
|
27
|
+
def get_known_boards_for_port(port: Optional[str] = "", versions: Optional[List[str]] = None) -> List[Board]:
|
48
28
|
"""
|
49
29
|
Returns a list of boards for the given port and version(s)
|
50
30
|
|
51
|
-
port
|
52
|
-
versions
|
53
|
-
|
31
|
+
port: The Micropython port to filter for
|
32
|
+
versions: Optional, The Micropython versions to filter for (actual versions required)
|
33
|
+
"""
|
34
|
+
mp_boards = read_known_boardinfo()
|
35
|
+
if versions:
|
36
|
+
preview_or_stable = "preview" in versions or "stable" in versions
|
37
|
+
else:
|
38
|
+
preview_or_stable = False
|
54
39
|
|
55
40
|
# filter for 'preview' as they are not in the board_info.json
|
56
41
|
# instead use stable version
|
@@ -62,9 +47,17 @@ def get_stored_boards_for_port(port: str, versions: Optional[List[str]] = None):
|
|
62
47
|
# make sure of the v prefix
|
63
48
|
versions = [clean_version(v) for v in versions]
|
64
49
|
# filter for the version(s)
|
65
|
-
mp_boards = [board for board in mp_boards if board
|
50
|
+
mp_boards = [board for board in mp_boards if board.version in versions]
|
51
|
+
if not mp_boards and preview_or_stable:
|
52
|
+
# nothing found - perhaps there is a newer version for which we do not have the board info yet
|
53
|
+
# use the latest known version from the board info
|
54
|
+
mp_boards = read_known_boardinfo()
|
55
|
+
last_known_version = sorted({b.version for b in mp_boards})[-1]
|
56
|
+
mp_boards = [board for board in mp_boards if board.version == last_known_version]
|
57
|
+
|
66
58
|
# filter for the port
|
67
|
-
|
59
|
+
if port:
|
60
|
+
mp_boards = [board for board in mp_boards if board.port == port]
|
68
61
|
return mp_boards
|
69
62
|
|
70
63
|
|
@@ -75,22 +68,22 @@ def known_stored_boards(port: str, versions: Optional[List[str]] = None) -> List
|
|
75
68
|
port : str : The Micropython port to filter for
|
76
69
|
versions : List[str] : The Micropython versions to filter for (actual versions required)
|
77
70
|
"""
|
78
|
-
mp_boards =
|
71
|
+
mp_boards = get_known_boards_for_port(port, versions)
|
79
72
|
|
80
|
-
boards = set({(f
|
73
|
+
boards = set({(f"{board.version} {board.description}", board.board_id) for board in mp_boards})
|
81
74
|
return sorted(list(boards))
|
82
75
|
|
83
76
|
|
84
77
|
@lru_cache(maxsize=20)
|
85
|
-
def
|
86
|
-
"""Find the board for the given
|
87
|
-
info =
|
78
|
+
def find_known_board(board_id: str) -> Board:
|
79
|
+
"""Find the board for the given BOARD_ID or 'board description' and return the board info as a Board object"""
|
80
|
+
info = read_known_boardinfo()
|
88
81
|
for board_info in info:
|
89
|
-
if board_id in (board_info
|
90
|
-
if
|
91
|
-
if " with " in board_info
|
92
|
-
board_info
|
82
|
+
if board_id in (board_info.board_id, board_info.description):
|
83
|
+
if not board_info.cpu:
|
84
|
+
if " with " in board_info.description:
|
85
|
+
board_info.cpu = board_info.description.split(" with ")[-1]
|
93
86
|
else:
|
94
|
-
board_info
|
87
|
+
board_info.cpu = board_info.port
|
95
88
|
return board_info
|
96
89
|
raise MPFlashError(f"Board {board_id} not found")
|