micropython-stubber 1.17.5__py3-none-any.whl → 1.19.0__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 (74) hide show
  1. {micropython_stubber-1.17.5.dist-info → micropython_stubber-1.19.0.dist-info}/METADATA +7 -6
  2. {micropython_stubber-1.17.5.dist-info → micropython_stubber-1.19.0.dist-info}/RECORD +71 -52
  3. mpflash/README.md +22 -3
  4. mpflash/libusb_flash.ipynb +203 -0
  5. mpflash/mpflash/ask_input.py +234 -0
  6. mpflash/mpflash/cli_download.py +107 -0
  7. mpflash/mpflash/cli_flash.py +165 -0
  8. mpflash/mpflash/cli_group.py +41 -8
  9. mpflash/mpflash/cli_list.py +41 -0
  10. mpflash/mpflash/cli_main.py +13 -8
  11. mpflash/mpflash/common.py +33 -122
  12. mpflash/mpflash/config.py +9 -0
  13. mpflash/mpflash/{downloader.py → download.py} +112 -120
  14. mpflash/mpflash/downloaded.py +108 -0
  15. mpflash/mpflash/errors.py +5 -0
  16. mpflash/mpflash/flash.py +69 -0
  17. mpflash/mpflash/flash_esp.py +17 -23
  18. mpflash/mpflash/flash_stm32.py +16 -113
  19. mpflash/mpflash/flash_stm32_cube.py +111 -0
  20. mpflash/mpflash/flash_stm32_dfu.py +101 -0
  21. mpflash/mpflash/flash_uf2.py +8 -8
  22. mpflash/mpflash/flash_uf2_linux.py +25 -12
  23. mpflash/mpflash/flash_uf2_windows.py +24 -12
  24. mpflash/mpflash/list.py +34 -37
  25. mpflash/mpflash/logger.py +12 -13
  26. mpflash/mpflash/mpboard_id/__init__.py +96 -0
  27. mpflash/mpflash/mpboard_id/board_id.py +63 -0
  28. mpflash/mpflash/mpboard_id/board_info.csv +2213 -0
  29. mpflash/mpflash/mpboard_id/board_info.json +19910 -0
  30. mpflash/mpflash/mpremoteboard/__init__.py +208 -0
  31. mpflash/mpflash/mpremoteboard/mpy_fw_info.py +141 -0
  32. {stubber/bulk → mpflash/mpflash/mpremoteboard}/runner.py +22 -5
  33. mpflash/mpflash/vendor/dfu.py +164 -0
  34. mpflash/mpflash/vendor/pydfu.py +605 -0
  35. mpflash/mpflash/vendor/readme.md +3 -0
  36. mpflash/mpflash/vendor/versions.py +113 -0
  37. mpflash/mpflash/worklist.py +147 -0
  38. mpflash/poetry.lock +411 -595
  39. mpflash/pyproject.toml +24 -8
  40. mpflash/stm32_udev_rules.md +63 -0
  41. stubber/__init__.py +1 -1
  42. stubber/basicgit.py +1 -0
  43. stubber/board/createstubs.py +10 -4
  44. stubber/board/createstubs_db.py +11 -5
  45. stubber/board/createstubs_db_min.py +61 -58
  46. stubber/board/createstubs_db_mpy.mpy +0 -0
  47. stubber/board/createstubs_mem.py +11 -5
  48. stubber/board/createstubs_mem_min.py +56 -53
  49. stubber/board/createstubs_mem_mpy.mpy +0 -0
  50. stubber/board/createstubs_min.py +54 -51
  51. stubber/board/createstubs_mpy.mpy +0 -0
  52. stubber/bulk/mcu_stubber.py +9 -5
  53. stubber/codemod/_partials/db_main.py +14 -25
  54. stubber/codemod/_partials/lvgl_main.py +2 -2
  55. stubber/codemod/board.py +10 -3
  56. stubber/commands/clone_cmd.py +7 -7
  57. stubber/commands/config_cmd.py +3 -0
  58. stubber/freeze/get_frozen.py +0 -2
  59. stubber/publish/candidates.py +1 -1
  60. stubber/publish/package.py +1 -1
  61. stubber/publish/pathnames.py +1 -1
  62. stubber/publish/stubpackage.py +1 -0
  63. stubber/rst/lookup.py +1 -1
  64. stubber/tools/manifestfile.py +5 -3
  65. stubber/utils/config.py +26 -36
  66. stubber/utils/repos.py +2 -2
  67. stubber/utils/versions.py +1 -0
  68. mpflash/mpflash/flasher.py +0 -287
  69. stubber/bulk/board_id.py +0 -40
  70. stubber/bulk/mpremoteboard.py +0 -141
  71. {micropython_stubber-1.17.5.dist-info → micropython_stubber-1.19.0.dist-info}/LICENSE +0 -0
  72. {micropython_stubber-1.17.5.dist-info → micropython_stubber-1.19.0.dist-info}/WHEEL +0 -0
  73. {micropython_stubber-1.17.5.dist-info → micropython_stubber-1.19.0.dist-info}/entry_points.txt +0 -0
  74. /mpflash/mpflash/{uf2_boardid.py → flash_uf2_boardid.py} +0 -0
@@ -0,0 +1,113 @@
1
+ """
2
+ #############################################################
3
+ # Version handling copied from stubber/utils/versions.py
4
+ #############################################################
5
+ """
6
+
7
+ from functools import lru_cache
8
+
9
+ from loguru import logger as log
10
+ from packaging.version import parse
11
+
12
+ V_PREVIEW = "preview"
13
+ "Latest preview version"
14
+
15
+ SET_PREVIEW = {"preview", "latest", "master"}
16
+
17
+
18
+ def clean_version(
19
+ version: str,
20
+ *,
21
+ build: bool = False,
22
+ patch: bool = False,
23
+ commit: bool = False,
24
+ drop_v: bool = False,
25
+ flat: bool = False,
26
+ ):
27
+ "Clean up and transform the many flavours of versions"
28
+ # 'v1.13.0-103-gb137d064e' --> 'v1.13-103'
29
+ if version in {"", "-"}:
30
+ return version
31
+ if version.lower() == "stable":
32
+ _v = get_stable_mp_version()
33
+ if not _v:
34
+ log.warning("Could not determine the latest stable version")
35
+ return "stable"
36
+ version = _v
37
+ log.trace(f"Using latest stable version: {version}")
38
+ is_preview = "-preview" in version
39
+ nibbles = version.split("-")
40
+ ver_ = nibbles[0].lower().lstrip("v")
41
+ if not patch and ver_ >= "1.10.0" and ver_ < "1.20.0" and ver_.endswith(".0"):
42
+ # remove the last ".0" - but only for versions between 1.10 and 1.20 (because)
43
+ nibbles[0] = nibbles[0][:-2]
44
+ if len(nibbles) == 1:
45
+ version = nibbles[0]
46
+ elif build and not is_preview:
47
+ version = "-".join(nibbles) if commit else "-".join(nibbles[:-1])
48
+ else:
49
+ # version = "-".join((nibbles[0], LATEST))
50
+ # HACK: this is not always right, but good enough most of the time
51
+ if is_preview:
52
+ version = "-".join((nibbles[0], V_PREVIEW))
53
+ else:
54
+ version = V_PREVIEW
55
+ if flat:
56
+ version = version.strip().replace(".", "_").replace("-", "_")
57
+ else:
58
+ version = version.strip().replace("_preview", "-preview").replace("_", ".")
59
+
60
+ if drop_v:
61
+ version = version.lstrip("v")
62
+ elif not version.startswith("v") and version.lower() not in SET_PREVIEW:
63
+ version = "v" + version
64
+ if version in SET_PREVIEW:
65
+ version = V_PREVIEW
66
+ return version
67
+
68
+
69
+ @lru_cache(maxsize=10)
70
+ def micropython_versions(minver: str = "v1.20"):
71
+ """Get the list of micropython versions from github tags"""
72
+ try:
73
+ gh_client = GH_CLIENT
74
+ repo = gh_client.get_repo("micropython/micropython")
75
+ versions = [tag.name for tag in repo.get_tags() if parse(tag.name) >= parse(minver)]
76
+ except Exception:
77
+ versions = [
78
+ "v9.99.9-preview",
79
+ "v1.22.2",
80
+ "v1.22.1",
81
+ "v1.22.0",
82
+ "v1.21.1",
83
+ "v1.21.0",
84
+ "v1.20.0",
85
+ "v1.19.1",
86
+ "v1.19",
87
+ "v1.18",
88
+ "v1.17",
89
+ "v1.16",
90
+ "v1.15",
91
+ "v1.14",
92
+ "v1.13",
93
+ "v1.12",
94
+ "v1.11",
95
+ "v1.10",
96
+ ]
97
+ versions = [v for v in versions if parse(v) >= parse(minver)]
98
+ return sorted(versions)
99
+
100
+
101
+ def get_stable_mp_version() -> str:
102
+ # read the versions from the git tags
103
+ all_versions = micropython_versions(minver="v1.17")
104
+ return [v for v in all_versions if not v.endswith(V_PREVIEW)][-1]
105
+
106
+
107
+ def get_preview_mp_version() -> str:
108
+ # read the versions from the git tags
109
+ all_versions = micropython_versions(minver="v1.17")
110
+ return [v for v in all_versions if v.endswith(V_PREVIEW)][-1]
111
+
112
+
113
+ #############################################################
@@ -0,0 +1,147 @@
1
+ from pathlib import Path
2
+ from typing import Dict, List, Optional, Tuple
3
+
4
+ from loguru import logger as log
5
+
6
+ from mpflash.common import FWInfo
7
+ from mpflash.errors import MPFlashError
8
+
9
+ from .config import config
10
+ from .downloaded import find_downloaded_firmware
11
+ from .list import show_mcus
12
+ from .mpboard_id import find_stored_board
13
+ from .mpremoteboard import MPRemoteBoard
14
+
15
+ # #########################################################################################################
16
+ WorkList = List[Tuple[MPRemoteBoard, FWInfo]]
17
+ # #########################################################################################################
18
+
19
+
20
+ def auto_update(
21
+ conn_boards: List[MPRemoteBoard],
22
+ target_version: str,
23
+ fw_folder: Path,
24
+ *,
25
+ selector: Optional[Dict[str, str]] = None,
26
+ ) -> WorkList:
27
+ """Builds a list of boards to update based on the connected boards and the firmware available
28
+
29
+ Args:
30
+ conn_boards (List[MPRemoteBoard]): List of connected boards
31
+ target_version (str): Target firmware version
32
+ fw_folder (Path): Path to the firmware folder
33
+ selector (Optional[Dict[str, str]], optional): Selector for filtering firmware. Defaults to None.
34
+
35
+ Returns:
36
+ WorkList: List of boards and firmware information to update
37
+ """
38
+ if selector is None:
39
+ selector = {}
40
+ wl: WorkList = []
41
+ for mcu in conn_boards:
42
+ if mcu.family not in ("micropython", "unknown"):
43
+ log.warning(
44
+ f"Skipping flashing {mcu.family} {mcu.port} {mcu.board} on {mcu.serialport} as it is not a MicroPython firmware"
45
+ )
46
+ continue
47
+ board_firmwares = find_downloaded_firmware(
48
+ fw_folder=fw_folder,
49
+ board_id=mcu.board,
50
+ version=target_version,
51
+ port=mcu.port,
52
+ selector=selector,
53
+ )
54
+
55
+ if not board_firmwares:
56
+ log.error(f"No {target_version} firmware found for {mcu.board} on {mcu.serialport}.")
57
+ continue
58
+ if len(board_firmwares) > 1:
59
+ log.debug(f"Multiple {target_version} firmwares found for {mcu.board} on {mcu.serialport}.")
60
+
61
+ # just use the last firmware
62
+ fw_info = board_firmwares[-1]
63
+ log.info(f"Found {target_version} firmware {fw_info['filename']} for {mcu.board} on {mcu.serialport}.")
64
+ wl.append((mcu, fw_info))
65
+ return wl
66
+
67
+
68
+ def single_auto_worklist(
69
+ *,
70
+ serial_port: str,
71
+ version: str,
72
+ fw_folder: Path,
73
+ ) -> WorkList:
74
+ """Create a worklist for a single serial-port.
75
+
76
+ Args:
77
+ serial_port (str): Serial port of the board
78
+ version (str): Firmware version
79
+ fw_folder (Path): Path to the firmware folder
80
+
81
+ Returns:
82
+ WorkList: List of boards and firmware information to update
83
+ """
84
+ conn_boards = [MPRemoteBoard(serial_port)]
85
+ todo = auto_update(conn_boards, version, fw_folder) # type: ignore # List / list
86
+ show_mcus(conn_boards) # type: ignore
87
+ return todo
88
+
89
+
90
+ def full_auto_worklist(*, version: str, fw_folder: Path) -> WorkList:
91
+ """
92
+ Create a worklist for all connected micropython boards based on the information retrieved from the board.
93
+ This allows the firmware version of one or moae boards to be changed without needing to specify the port or board_id manually.
94
+
95
+ Args:
96
+ version (str): Firmware version
97
+ fw_folder (Path): Path to the firmware folder
98
+
99
+ Returns:
100
+ WorkList: List of boards and firmware information to update
101
+ """
102
+ try:
103
+ conn_boards = [
104
+ MPRemoteBoard(sp, update=True) for sp in MPRemoteBoard.connected_boards() if sp not in config.ignore_ports
105
+ ]
106
+ except ConnectionError as e:
107
+ log.error(f"Error connecting to boards: {e}")
108
+ return []
109
+ return auto_update(conn_boards, version, fw_folder) # type: ignore
110
+
111
+
112
+ def manual_worklist(
113
+ version: str,
114
+ fw_folder: Path,
115
+ serial_port: str,
116
+ board: str,
117
+ # port: str,
118
+ ) -> WorkList:
119
+ """Create a worklist for a single board specified manually.
120
+
121
+ Args:
122
+ version (str): Firmware version
123
+ fw_folder (Path): Path to the firmware folder
124
+ serial_port (str): Serial port of the board
125
+ board (str): Board name
126
+
127
+ Returns:
128
+ WorkList: List of boards and firmware information to update
129
+ """
130
+ mcu = MPRemoteBoard(serial_port)
131
+ # TODO : Find a way to avoid needing to specify the port
132
+ # Lookup the matching port and cpu in board_info based in the board name
133
+ try:
134
+ info = find_stored_board(board)
135
+ mcu.port = info["port"]
136
+ # need the CPU type for the esptool
137
+ mcu.cpu = info["cpu"]
138
+ except (LookupError, MPFlashError) as e:
139
+ log.error(f"Board {board} not found in board_info.json")
140
+ return []
141
+ mcu.board = board
142
+ firmwares = find_downloaded_firmware(fw_folder=fw_folder, board_id=board, version=version, port=mcu.port)
143
+ if not firmwares:
144
+ log.error(f"No firmware found for {mcu.port} {board} version {version}")
145
+ return []
146
+ # use the most recent matching firmware
147
+ return [(mcu, firmwares[-1])] # type: ignore