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.
Files changed (60) hide show
  1. {micropython_stubber-1.20.0.dist-info → micropython_stubber-1.20.2.dist-info}/METADATA +6 -6
  2. {micropython_stubber-1.20.0.dist-info → micropython_stubber-1.20.2.dist-info}/RECORD +58 -51
  3. mpflash/README.md +54 -35
  4. mpflash/libusb_flash.ipynb +203 -203
  5. mpflash/mpflash/add_firmware.py +98 -0
  6. mpflash/mpflash/ask_input.py +106 -114
  7. mpflash/mpflash/cli_download.py +58 -37
  8. mpflash/mpflash/cli_flash.py +77 -35
  9. mpflash/mpflash/cli_group.py +14 -12
  10. mpflash/mpflash/cli_list.py +40 -4
  11. mpflash/mpflash/cli_main.py +20 -8
  12. mpflash/mpflash/common.py +125 -12
  13. mpflash/mpflash/config.py +2 -0
  14. mpflash/mpflash/connected.py +74 -0
  15. mpflash/mpflash/download.py +67 -50
  16. mpflash/mpflash/downloaded.py +9 -9
  17. mpflash/mpflash/flash.py +2 -2
  18. mpflash/mpflash/flash_esp.py +2 -2
  19. mpflash/mpflash/flash_uf2.py +16 -8
  20. mpflash/mpflash/flash_uf2_linux.py +5 -16
  21. mpflash/mpflash/flash_uf2_macos.py +78 -0
  22. mpflash/mpflash/flash_uf2_windows.py +1 -1
  23. mpflash/mpflash/list.py +58 -57
  24. mpflash/mpflash/mpboard_id/__init__.py +37 -44
  25. mpflash/mpflash/mpboard_id/add_boards.py +255 -0
  26. mpflash/mpflash/mpboard_id/board.py +37 -0
  27. mpflash/mpflash/mpboard_id/board_id.py +50 -43
  28. mpflash/mpflash/mpboard_id/board_info.zip +0 -0
  29. mpflash/mpflash/mpboard_id/store.py +42 -0
  30. mpflash/mpflash/mpremoteboard/__init__.py +18 -6
  31. mpflash/mpflash/mpremoteboard/runner.py +12 -12
  32. mpflash/mpflash/uf2disk.py +12 -0
  33. mpflash/mpflash/vendor/basicgit.py +288 -0
  34. mpflash/mpflash/vendor/dfu.py +1 -0
  35. mpflash/mpflash/vendor/versions.py +7 -3
  36. mpflash/mpflash/worklist.py +71 -48
  37. mpflash/poetry.lock +163 -137
  38. mpflash/pyproject.toml +18 -15
  39. stubber/__init__.py +1 -1
  40. stubber/board/createstubs.py +4 -3
  41. stubber/board/createstubs_db.py +5 -7
  42. stubber/board/createstubs_db_min.py +1 -1
  43. stubber/board/createstubs_db_mpy.mpy +0 -0
  44. stubber/board/createstubs_mem.py +6 -7
  45. stubber/board/createstubs_mem_min.py +1 -1
  46. stubber/board/createstubs_mem_mpy.mpy +0 -0
  47. stubber/board/createstubs_min.py +2 -2
  48. stubber/board/createstubs_mpy.mpy +0 -0
  49. stubber/board/modulelist.txt +1 -0
  50. stubber/commands/get_core_cmd.py +7 -6
  51. stubber/commands/get_docstubs_cmd.py +8 -3
  52. stubber/commands/get_frozen_cmd.py +5 -2
  53. stubber/publish/publish.py +18 -7
  54. stubber/utils/makeversionhdr.py +3 -2
  55. stubber/utils/versions.py +2 -1
  56. mpflash/mpflash/mpboard_id/board_info.csv +0 -2213
  57. mpflash/mpflash/mpboard_id/board_info.json +0 -19910
  58. {micropython_stubber-1.20.0.dist-info → micropython_stubber-1.20.2.dist-info}/LICENSE +0 -0
  59. {micropython_stubber-1.20.0.dist-info → micropython_stubber-1.20.2.dist-info}/WHEEL +0 -0
  60. {micropython_stubber-1.20.0.dist-info → micropython_stubber-1.20.2.dist-info}/entry_points.txt +0 -0
@@ -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.extend(iter(reader))
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["filename"])
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["filename"])
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["preview"]]
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["version"] == version]
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["port"] == port]
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["board"] == board_id]
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["variant"] == board_id]
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["filename"].endswith(selector[port])]
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["filename"] # type: ignore
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['version']}")
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":
@@ -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 find_stored_board
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 = find_stored_board(mcu.board)["cpu"]
25
+ mcu.cpu = find_known_board(mcu.board).cpu
26
26
 
27
27
  cmds: List[List[str]] = []
28
28
  if erase:
@@ -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 .flash_uf2_linux import dismount_uf2, wait_for_UF2_linux
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 Lunix :
31
- pmount and pumount are used to mount and unmount the drive
32
- as this is not done automatically by the OS in headless mode.
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", "darwin"]:
58
- dismount_uf2()
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 dismount_uf2():
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(range(s_max), description="Waiting for mcu to mount as a drive", transient=True):
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 print
4
- from rich.progress import BarColumn, Progress, SpinnerColumn, TextColumn, TimeElapsedColumn, track
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
- # a lot of boilerplate to show a progress bar with the comport currenlty scanned
29
- with Progress(rp_spinner, rp_text, rp_bar, TimeElapsedColumn()) as progress:
30
- tsk_scan = progress.add_task("[green]Scanning", visible=False, total=None)
31
- progress.tasks[tsk_scan].fields["device"] = "..."
32
- progress.tasks[tsk_scan].visible = True
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 show_mcus(
27
+ def mcu_table(
50
28
  conn_mcus: List[MPRemoteBoard],
51
29
  title: str = "Connected boards",
52
30
  refresh: bool = True,
53
- ): # sourcery skip: extract-duplicate-method
54
- """Show the list of connected boards in a nice table"""
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
- width=110,
50
+ padding=(0, 0),
61
51
  )
62
- table.add_column("Serial", overflow="fold")
63
- table.add_column("Family")
64
- table.add_column("Port")
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
- table.add_column("CPU")
68
- table.add_column("Version")
69
- table.add_column("build", justify="right")
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, update_period=0.1):
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
- table.add_row(
75
+ row = [
79
76
  mcu.serialport.replace("/dev/", ""),
80
- mcu.family,
81
- mcu.port,
82
- f"{mcu.board}\n{description}".strip(),
83
- # mcu.variant,
84
- mcu.cpu,
85
- mcu.version,
86
- mcu.build,
87
- )
88
- console.print(table)
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 pathlib import Path
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.common import PORT_FWTYPES
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
- description: str
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 = read_stored_boardinfo()
21
+ mp_boards = read_known_boardinfo()
42
22
  # select the unique ports from info
43
- ports = set({board["port"] for board in mp_boards if board["port"] in PORT_FWTYPES.keys()})
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 get_stored_boards_for_port(port: str, versions: Optional[List[str]] = None):
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 : str : The Micropython port to filter for
52
- versions : List[str] : The Micropython versions to filter for (actual versions required)"""
53
- mp_boards = read_stored_boardinfo()
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["version"] in versions]
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
- mp_boards = [board for board in mp_boards if board["port"] == port]
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 = get_stored_boards_for_port(port, versions)
71
+ mp_boards = get_known_boards_for_port(port, versions)
79
72
 
80
- boards = set({(f'{board["version"]} {board["description"]}', board["board"]) for board in mp_boards})
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 find_stored_board(board_id: str) -> Board:
86
- """Find the board for the given board_ID or 'board description' and return the board info as a Board object"""
87
- info = read_stored_boardinfo()
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["board"], board_info["description"]):
90
- if "cpu" not in board_info or not board_info["cpu"]:
91
- if " with " in board_info["description"]:
92
- board_info["cpu"] = board_info["description"].split(" with ")[-1]
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["cpu"] = board_info["port"]
87
+ board_info.cpu = board_info.port
95
88
  return board_info
96
89
  raise MPFlashError(f"Board {board_id} not found")