micropython-stubber 1.20.5__py3-none-any.whl → 1.20.6__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 (152) hide show
  1. {micropython_stubber-1.20.5.dist-info → micropython_stubber-1.20.6.dist-info}/LICENSE +30 -30
  2. {micropython_stubber-1.20.5.dist-info → micropython_stubber-1.20.6.dist-info}/METADATA +1 -1
  3. micropython_stubber-1.20.6.dist-info/RECORD +159 -0
  4. mpflash/README.md +184 -184
  5. mpflash/libusb_flash.ipynb +203 -203
  6. mpflash/mpflash/add_firmware.py +98 -98
  7. mpflash/mpflash/ask_input.py +236 -236
  8. mpflash/mpflash/bootloader/__init__.py +37 -36
  9. mpflash/mpflash/bootloader/manual.py +102 -102
  10. mpflash/mpflash/bootloader/micropython.py +10 -10
  11. mpflash/mpflash/bootloader/touch1200.py +45 -45
  12. mpflash/mpflash/cli_download.py +129 -129
  13. mpflash/mpflash/cli_flash.py +219 -219
  14. mpflash/mpflash/cli_group.py +98 -98
  15. mpflash/mpflash/cli_list.py +81 -81
  16. mpflash/mpflash/cli_main.py +41 -41
  17. mpflash/mpflash/common.py +164 -164
  18. mpflash/mpflash/config.py +47 -47
  19. mpflash/mpflash/connected.py +74 -74
  20. mpflash/mpflash/download.py +360 -360
  21. mpflash/mpflash/downloaded.py +129 -129
  22. mpflash/mpflash/errors.py +9 -9
  23. mpflash/mpflash/flash.py +52 -52
  24. mpflash/mpflash/flash_esp.py +59 -59
  25. mpflash/mpflash/flash_stm32.py +24 -24
  26. mpflash/mpflash/flash_stm32_cube.py +111 -111
  27. mpflash/mpflash/flash_stm32_dfu.py +101 -101
  28. mpflash/mpflash/flash_uf2.py +67 -67
  29. mpflash/mpflash/flash_uf2_boardid.py +15 -15
  30. mpflash/mpflash/flash_uf2_linux.py +123 -123
  31. mpflash/mpflash/flash_uf2_macos.py +34 -34
  32. mpflash/mpflash/flash_uf2_windows.py +34 -34
  33. mpflash/mpflash/list.py +89 -89
  34. mpflash/mpflash/logger.py +41 -41
  35. mpflash/mpflash/mpboard_id/__init__.py +93 -93
  36. mpflash/mpflash/mpboard_id/add_boards.py +255 -255
  37. mpflash/mpflash/mpboard_id/board.py +37 -37
  38. mpflash/mpflash/mpboard_id/board_id.py +86 -86
  39. mpflash/mpflash/mpboard_id/store.py +43 -43
  40. mpflash/mpflash/mpremoteboard/__init__.py +221 -221
  41. mpflash/mpflash/mpremoteboard/mpy_fw_info.py +141 -141
  42. mpflash/mpflash/mpremoteboard/runner.py +140 -140
  43. mpflash/mpflash/uf2disk.py +12 -12
  44. mpflash/mpflash/vendor/basicgit.py +288 -288
  45. mpflash/mpflash/vendor/click_aliases.py +91 -91
  46. mpflash/mpflash/vendor/dfu.py +165 -165
  47. mpflash/mpflash/vendor/pydfu.py +605 -605
  48. mpflash/mpflash/vendor/readme.md +2 -2
  49. mpflash/mpflash/vendor/versions.py +119 -117
  50. mpflash/mpflash/worklist.py +170 -170
  51. mpflash/poetry.lock +1588 -1588
  52. mpflash/pyproject.toml +60 -60
  53. mpflash/stm32_udev_rules.md +62 -62
  54. stubber/__init__.py +3 -3
  55. stubber/basicgit.py +294 -288
  56. stubber/board/board_info.csv +193 -193
  57. stubber/board/boot.py +34 -34
  58. stubber/board/createstubs.py +986 -986
  59. stubber/board/createstubs_db.py +825 -825
  60. stubber/board/createstubs_db_min.py +331 -331
  61. stubber/board/createstubs_db_mpy.mpy +0 -0
  62. stubber/board/createstubs_lvgl.py +741 -741
  63. stubber/board/createstubs_lvgl_min.py +741 -741
  64. stubber/board/createstubs_mem.py +766 -766
  65. stubber/board/createstubs_mem_min.py +306 -306
  66. stubber/board/createstubs_mem_mpy.mpy +0 -0
  67. stubber/board/createstubs_min.py +294 -294
  68. stubber/board/createstubs_mpy.mpy +0 -0
  69. stubber/board/fw_info.py +141 -141
  70. stubber/board/info.py +183 -183
  71. stubber/board/main.py +19 -19
  72. stubber/board/modulelist.txt +247 -247
  73. stubber/board/pyrightconfig.json +34 -34
  74. stubber/bulk/mcu_stubber.py +454 -454
  75. stubber/codemod/_partials/__init__.py +48 -48
  76. stubber/codemod/_partials/db_main.py +147 -147
  77. stubber/codemod/_partials/lvgl_main.py +77 -77
  78. stubber/codemod/_partials/modules_reader.py +80 -80
  79. stubber/codemod/add_comment.py +53 -53
  80. stubber/codemod/add_method.py +65 -65
  81. stubber/codemod/board.py +317 -317
  82. stubber/codemod/enrich.py +145 -145
  83. stubber/codemod/merge_docstub.py +284 -284
  84. stubber/codemod/modify_list.py +54 -54
  85. stubber/codemod/utils.py +57 -57
  86. stubber/commands/build_cmd.py +94 -94
  87. stubber/commands/cli.py +51 -51
  88. stubber/commands/clone_cmd.py +66 -66
  89. stubber/commands/config_cmd.py +29 -29
  90. stubber/commands/enrich_folder_cmd.py +70 -70
  91. stubber/commands/get_core_cmd.py +69 -69
  92. stubber/commands/get_docstubs_cmd.py +87 -87
  93. stubber/commands/get_frozen_cmd.py +112 -112
  94. stubber/commands/get_mcu_cmd.py +56 -56
  95. stubber/commands/merge_cmd.py +66 -66
  96. stubber/commands/publish_cmd.py +119 -119
  97. stubber/commands/stub_cmd.py +30 -30
  98. stubber/commands/switch_cmd.py +54 -54
  99. stubber/commands/variants_cmd.py +48 -48
  100. stubber/cst_transformer.py +178 -178
  101. stubber/data/board_info.csv +193 -193
  102. stubber/data/board_info.json +1729 -1729
  103. stubber/data/micropython_tags.csv +15 -15
  104. stubber/data/requirements-core-micropython.txt +38 -38
  105. stubber/data/requirements-core-pycopy.txt +39 -39
  106. stubber/downloader.py +36 -36
  107. stubber/freeze/common.py +68 -68
  108. stubber/freeze/freeze_folder.py +69 -69
  109. stubber/freeze/freeze_manifest_2.py +113 -113
  110. stubber/freeze/get_frozen.py +127 -127
  111. stubber/get_cpython.py +101 -101
  112. stubber/get_lobo.py +59 -59
  113. stubber/minify.py +418 -418
  114. stubber/publish/bump.py +86 -86
  115. stubber/publish/candidates.py +262 -262
  116. stubber/publish/database.py +18 -18
  117. stubber/publish/defaults.py +45 -45
  118. stubber/publish/enums.py +24 -24
  119. stubber/publish/helpers.py +29 -29
  120. stubber/publish/merge_docstubs.py +130 -130
  121. stubber/publish/missing_class_methods.py +49 -49
  122. stubber/publish/package.py +146 -146
  123. stubber/publish/pathnames.py +51 -51
  124. stubber/publish/publish.py +120 -120
  125. stubber/publish/pypi.py +38 -38
  126. stubber/publish/stubpackage.py +1029 -1029
  127. stubber/rst/__init__.py +9 -9
  128. stubber/rst/classsort.py +77 -77
  129. stubber/rst/lookup.py +530 -530
  130. stubber/rst/output_dict.py +401 -401
  131. stubber/rst/reader.py +822 -822
  132. stubber/rst/report_return.py +69 -69
  133. stubber/rst/rst_utils.py +540 -540
  134. stubber/stubber.py +38 -38
  135. stubber/stubs_from_docs.py +90 -90
  136. stubber/tools/manifestfile.py +610 -610
  137. stubber/tools/readme.md +5 -5
  138. stubber/update_fallback.py +117 -117
  139. stubber/update_module_list.py +123 -123
  140. stubber/utils/__init__.py +5 -5
  141. stubber/utils/config.py +127 -127
  142. stubber/utils/makeversionhdr.py +54 -54
  143. stubber/utils/manifest.py +92 -92
  144. stubber/utils/post.py +79 -79
  145. stubber/utils/repos.py +157 -154
  146. stubber/utils/stubmaker.py +139 -139
  147. stubber/utils/typed_config_toml.py +77 -77
  148. stubber/utils/versions.py +128 -120
  149. stubber/variants.py +106 -106
  150. micropython_stubber-1.20.5.dist-info/RECORD +0 -159
  151. {micropython_stubber-1.20.5.dist-info → micropython_stubber-1.20.6.dist-info}/WHEEL +0 -0
  152. {micropython_stubber-1.20.5.dist-info → micropython_stubber-1.20.6.dist-info}/entry_points.txt +0 -0
@@ -1,3 +1,3 @@
1
- These modules are vendored from the following repositories:
2
-
1
+ These modules are vendored from the following repositories:
2
+
3
3
  micropython/micropython
@@ -1,117 +1,119 @@
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
- from mpflash.common import GH_CLIENT
13
-
14
- V_PREVIEW = "preview"
15
- "Latest preview version"
16
-
17
- SET_PREVIEW = {"preview", "latest", "master"}
18
-
19
-
20
- def clean_version(
21
- version: str,
22
- *,
23
- build: bool = False,
24
- patch: bool = False,
25
- commit: bool = False,
26
- drop_v: bool = False,
27
- flat: bool = False,
28
- ):
29
- "Clean up and transform the many flavours of versions"
30
- # 'v1.13.0-103-gb137d064e' --> 'v1.13-103'
31
- if version in {"", "-"}:
32
- return version
33
- if version.lower() == "stable":
34
- _v = get_stable_mp_version()
35
- if not _v:
36
- log.warning("Could not determine the latest stable version")
37
- return "stable"
38
- version = _v
39
- log.trace(f"Using latest stable version: {version}")
40
- is_preview = "-preview" in version
41
- nibbles = version.split("-")
42
- ver_ = nibbles[0].lower().lstrip("v")
43
- if not patch and ver_ >= "1.10.0" and ver_ < "1.20.0" and ver_.endswith(".0"):
44
- # remove the last ".0" - but only for versions between 1.10 and 1.20 (because)
45
- nibbles[0] = nibbles[0][:-2]
46
- if len(nibbles) == 1:
47
- version = nibbles[0]
48
- elif build and not is_preview:
49
- version = "-".join(nibbles) if commit else "-".join(nibbles[:-1])
50
- else:
51
- # version = "-".join((nibbles[0], LATEST))
52
- # HACK: this is not always right, but good enough most of the time
53
- if is_preview:
54
- version = "-".join((nibbles[0], V_PREVIEW))
55
- else:
56
- version = V_PREVIEW
57
- if flat:
58
- version = version.strip().replace(".", "_").replace("-", "_")
59
- else:
60
- version = version.strip().replace("_preview", "-preview").replace("_", ".")
61
-
62
- if drop_v:
63
- version = version.lstrip("v")
64
- elif not version.startswith("v") and version.lower() not in SET_PREVIEW:
65
- version = "v" + version
66
- if version in SET_PREVIEW:
67
- version = V_PREVIEW
68
- return version
69
-
70
-
71
- @lru_cache(maxsize=10)
72
- def micropython_versions(minver: str = "v1.20", reverse: bool = False):
73
- """Get the list of micropython versions from github tags"""
74
- try:
75
- gh_client = GH_CLIENT
76
- repo = gh_client.get_repo("micropython/micropython")
77
- versions = [tag.name for tag in repo.get_tags()]
78
- except Exception:
79
- versions = [
80
- "v9.99.9-preview",
81
- "v1.22.2",
82
- "v1.22.1",
83
- "v1.22.0",
84
- "v1.21.1",
85
- "v1.21.0",
86
- "v1.20.0",
87
- "v1.19.1",
88
- "v1.19",
89
- "v1.18",
90
- "v1.17",
91
- "v1.16",
92
- "v1.15",
93
- "v1.14",
94
- "v1.13",
95
- "v1.12",
96
- "v1.11",
97
- "v1.10",
98
- ]
99
- versions = [v for v in versions if parse(v) >= parse(minver)]
100
- # remove all but the most recent (preview) version
101
- versions = versions[:1] + [v for v in versions if "preview" not in v]
102
- return sorted(versions)
103
-
104
-
105
- def get_stable_mp_version() -> str:
106
- # read the versions from the git tags
107
- all_versions = micropython_versions(minver="v1.17")
108
- return [v for v in all_versions if not v.endswith(V_PREVIEW)][-1]
109
-
110
-
111
- def get_preview_mp_version() -> str:
112
- # read the versions from the git tags
113
- all_versions = micropython_versions(minver="v1.17")
114
- return [v for v in all_versions if v.endswith(V_PREVIEW)][-1]
115
-
116
-
117
- #############################################################
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
+ from mpflash.common import GH_CLIENT
13
+ OLDEST_VERSION = "1.16"
14
+ "This is the oldest MicroPython version to build the stubs on"
15
+
16
+ V_PREVIEW = "preview"
17
+ "Latest preview version"
18
+
19
+ SET_PREVIEW = {"preview", "latest", "master"}
20
+
21
+
22
+ def clean_version(
23
+ version: str,
24
+ *,
25
+ build: bool = False,
26
+ patch: bool = False,
27
+ commit: bool = False,
28
+ drop_v: bool = False,
29
+ flat: bool = False,
30
+ ):
31
+ "Clean up and transform the many flavours of versions"
32
+ # 'v1.13.0-103-gb137d064e' --> 'v1.13-103'
33
+ if version in {"", "-"}:
34
+ return version
35
+ if version.lower() == "stable":
36
+ _v = get_stable_mp_version()
37
+ if not _v:
38
+ log.warning("Could not determine the latest stable version")
39
+ return "stable"
40
+ version = _v
41
+ log.trace(f"Using latest stable version: {version}")
42
+ is_preview = "-preview" in version
43
+ nibbles = version.split("-")
44
+ ver_ = nibbles[0].lower().lstrip("v")
45
+ if not patch and ver_ >= "1.10.0" and ver_ < "1.20.0" and ver_.endswith(".0"):
46
+ # remove the last ".0" - but only for versions between 1.10 and 1.20 (because)
47
+ nibbles[0] = nibbles[0][:-2]
48
+ if len(nibbles) == 1:
49
+ version = nibbles[0]
50
+ elif build and not is_preview:
51
+ version = "-".join(nibbles) if commit else "-".join(nibbles[:-1])
52
+ else:
53
+ # version = "-".join((nibbles[0], LATEST))
54
+ # HACK: this is not always right, but good enough most of the time
55
+ if is_preview:
56
+ version = "-".join((nibbles[0], V_PREVIEW))
57
+ else:
58
+ version = V_PREVIEW
59
+ if flat:
60
+ version = version.strip().replace(".", "_").replace("-", "_")
61
+ else:
62
+ version = version.strip().replace("_preview", "-preview").replace("_", ".")
63
+
64
+ if drop_v:
65
+ version = version.lstrip("v")
66
+ elif not version.startswith("v") and version.lower() not in SET_PREVIEW:
67
+ version = "v" + version
68
+ if version in SET_PREVIEW:
69
+ version = V_PREVIEW
70
+ return version
71
+
72
+
73
+ @lru_cache(maxsize=10)
74
+ def micropython_versions(minver: str = "v1.20", reverse: bool = False):
75
+ """Get the list of micropython versions from github tags"""
76
+ try:
77
+ gh_client = GH_CLIENT
78
+ repo = gh_client.get_repo("micropython/micropython")
79
+ versions = [tag.name for tag in repo.get_tags() if parse(tag.name) >= parse(minver)]
80
+ # Only keep the last preview
81
+ versions = [v for v in versions if not v.endswith(V_PREVIEW) or v == versions[-1]]
82
+ except Exception:
83
+ versions = [
84
+ "v9.99.9-preview",
85
+ "v1.22.2",
86
+ "v1.22.1",
87
+ "v1.22.0",
88
+ "v1.21.1",
89
+ "v1.21.0",
90
+ "v1.20.0",
91
+ "v1.19.1",
92
+ "v1.19",
93
+ "v1.18",
94
+ "v1.17",
95
+ "v1.16",
96
+ "v1.15",
97
+ "v1.14",
98
+ "v1.13",
99
+ "v1.12",
100
+ "v1.11",
101
+ "v1.10",
102
+ ]
103
+ versions = [v for v in versions if parse(v) >= parse(minver)]
104
+ # remove all but the most recent (preview) version
105
+ versions = versions[:1] + [v for v in versions if "preview" not in v]
106
+ return sorted(versions, reverse=reverse)
107
+
108
+
109
+ def get_stable_mp_version() -> str:
110
+ # read the versions from the git tags
111
+ all_versions = micropython_versions(minver=OLDEST_VERSION)
112
+ return [v for v in all_versions if not v.endswith(V_PREVIEW)][-1]
113
+
114
+
115
+ def get_preview_mp_version() -> str:
116
+ # read the versions from the git tags
117
+ all_versions = micropython_versions(minver=OLDEST_VERSION)
118
+ return [v for v in all_versions if v.endswith(V_PREVIEW)][-1]
119
+
@@ -1,170 +1,170 @@
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, filtered_comports
7
- from mpflash.errors import MPFlashError
8
-
9
- from .downloaded import find_downloaded_firmware
10
- from .list import show_mcus
11
- from .mpboard_id import find_known_board
12
- from .mpremoteboard import MPRemoteBoard
13
-
14
- # #########################################################################################################
15
- WorkList = List[Tuple[MPRemoteBoard, FWInfo]]
16
- # #########################################################################################################
17
-
18
-
19
- def auto_update(
20
- conn_boards: List[MPRemoteBoard],
21
- target_version: str,
22
- fw_folder: Path,
23
- *,
24
- selector: Optional[Dict[str, str]] = None,
25
- ) -> WorkList:
26
- """Builds a list of boards to update based on the connected boards and the firmwares available locally in the firmware folder.
27
-
28
- Args:
29
- conn_boards (List[MPRemoteBoard]): List of connected boards
30
- target_version (str): Target firmware version
31
- fw_folder (Path): Path to the firmware folder
32
- selector (Optional[Dict[str, str]], optional): Selector for filtering firmware. Defaults to None.
33
-
34
- Returns:
35
- WorkList: List of boards and firmware information to update
36
- """
37
- if selector is None:
38
- selector = {}
39
- wl: WorkList = []
40
- for mcu in conn_boards:
41
- if mcu.family not in ("micropython", "unknown"):
42
- log.warning(
43
- f"Skipping flashing {mcu.family} {mcu.port} {mcu.board} on {mcu.serialport} as it is not a MicroPython firmware"
44
- )
45
- continue
46
- board_firmwares = find_downloaded_firmware(
47
- fw_folder=fw_folder,
48
- board_id=mcu.board,
49
- version=target_version,
50
- port=mcu.port,
51
- selector=selector,
52
- )
53
-
54
- if not board_firmwares:
55
- log.error(f"No {target_version} firmware found for {mcu.board} on {mcu.serialport}.")
56
- continue
57
- if len(board_firmwares) > 1:
58
- log.debug(f"Multiple {target_version} firmwares found for {mcu.board} on {mcu.serialport}.")
59
-
60
- # just use the last firmware
61
- fw_info = board_firmwares[-1]
62
- log.info(f"Found {target_version} firmware {fw_info.filename} for {mcu.board} on {mcu.serialport}.")
63
- wl.append((mcu, fw_info))
64
- return wl
65
-
66
-
67
- def manual_worklist(
68
- serial: str,
69
- *,
70
- board_id: str,
71
- version: str,
72
- fw_folder: Path,
73
- ) -> WorkList:
74
- """Create a worklist for a single board specified manually.
75
-
76
- Args:
77
- serial (str): Serial port of the board
78
- board (str): Board_ID
79
- version (str): Firmware version
80
- fw_folder (Path): Path to the firmware folder
81
-
82
- Returns:
83
- WorkList: List of boards and firmware information to update
84
- """
85
- log.trace(f"Manual updating {serial} to {board_id} {version}")
86
- mcu = MPRemoteBoard(serial)
87
- # Lookup the matching port and cpu in board_info based in the board name
88
- try:
89
- info = find_known_board(board_id)
90
- mcu.port = info.port
91
- # need the CPU type for the esptool
92
- mcu.cpu = info.cpu
93
- except (LookupError, MPFlashError) as e:
94
- log.error(f"Board {board_id} not found in board_info.zip")
95
- log.exception(e)
96
- return []
97
- mcu.board = board_id
98
- firmwares = find_downloaded_firmware(fw_folder=fw_folder, board_id=board_id, version=version, port=mcu.port)
99
- if not firmwares:
100
- log.error(f"No firmware found for {mcu.port} {board_id} version {version}")
101
- return []
102
- # use the most recent matching firmware
103
- return [(mcu, firmwares[-1])] # type: ignore
104
-
105
-
106
- def single_auto_worklist(
107
- serial: str,
108
- *,
109
- version: str,
110
- fw_folder: Path,
111
- ) -> WorkList:
112
- """Create a worklist for a single serial-port.
113
-
114
- Args:
115
- serial_port (str): Serial port of the board
116
- version (str): Firmware version
117
- fw_folder (Path): Path to the firmware folder
118
-
119
- Returns:
120
- WorkList: List of boards and firmware information to update
121
- """
122
- log.trace(f"Auto updating {serial} to {version}")
123
- conn_boards = [MPRemoteBoard(serial)]
124
- todo = auto_update(conn_boards, version, fw_folder) # type: ignore # List / list
125
- show_mcus(conn_boards) # type: ignore
126
- return todo
127
-
128
-
129
- def full_auto_worklist(
130
- all_boards: List[MPRemoteBoard], *, include: List[str], ignore: List[str], version: str, fw_folder: Path
131
- ) -> WorkList:
132
- """
133
- Create a worklist for all connected micropython boards based on the information retrieved from the board.
134
- This allows the firmware version of one or moae boards to be changed without needing to specify the port or board_id manually.
135
-
136
- Args:
137
- version (str): Firmware version
138
- fw_folder (Path): Path to the firmware folder
139
-
140
- Returns:
141
- WorkList: List of boards and firmware information to update
142
- """
143
- log.trace(f"Auto updating all boards to {version}")
144
- if selected_boards := filter_boards(all_boards, include=include, ignore=ignore):
145
- return auto_update(selected_boards, version, fw_folder)
146
- else:
147
- return []
148
-
149
-
150
- def filter_boards(
151
- all_boards: List[MPRemoteBoard],
152
- *,
153
- include: List[str],
154
- ignore: List[str],
155
- ):
156
- try:
157
- comports = [
158
- p.device
159
- for p in filtered_comports(
160
- ignore=ignore,
161
- include=include,
162
- bluetooth=False,
163
- )
164
- ]
165
- selected_boards = [b for b in all_boards if b.serialport in comports]
166
- # [MPRemoteBoard(port.device, update=True) for port in comports]
167
- except ConnectionError as e:
168
- log.error(f"Error connecting to boards: {e}")
169
- return []
170
- return selected_boards # type: ignore
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, filtered_comports
7
+ from mpflash.errors import MPFlashError
8
+
9
+ from .downloaded import find_downloaded_firmware
10
+ from .list import show_mcus
11
+ from .mpboard_id import find_known_board
12
+ from .mpremoteboard import MPRemoteBoard
13
+
14
+ # #########################################################################################################
15
+ WorkList = List[Tuple[MPRemoteBoard, FWInfo]]
16
+ # #########################################################################################################
17
+
18
+
19
+ def auto_update(
20
+ conn_boards: List[MPRemoteBoard],
21
+ target_version: str,
22
+ fw_folder: Path,
23
+ *,
24
+ selector: Optional[Dict[str, str]] = None,
25
+ ) -> WorkList:
26
+ """Builds a list of boards to update based on the connected boards and the firmwares available locally in the firmware folder.
27
+
28
+ Args:
29
+ conn_boards (List[MPRemoteBoard]): List of connected boards
30
+ target_version (str): Target firmware version
31
+ fw_folder (Path): Path to the firmware folder
32
+ selector (Optional[Dict[str, str]], optional): Selector for filtering firmware. Defaults to None.
33
+
34
+ Returns:
35
+ WorkList: List of boards and firmware information to update
36
+ """
37
+ if selector is None:
38
+ selector = {}
39
+ wl: WorkList = []
40
+ for mcu in conn_boards:
41
+ if mcu.family not in ("micropython", "unknown"):
42
+ log.warning(
43
+ f"Skipping flashing {mcu.family} {mcu.port} {mcu.board} on {mcu.serialport} as it is not a MicroPython firmware"
44
+ )
45
+ continue
46
+ board_firmwares = find_downloaded_firmware(
47
+ fw_folder=fw_folder,
48
+ board_id=mcu.board,
49
+ version=target_version,
50
+ port=mcu.port,
51
+ selector=selector,
52
+ )
53
+
54
+ if not board_firmwares:
55
+ log.error(f"No {target_version} firmware found for {mcu.board} on {mcu.serialport}.")
56
+ continue
57
+ if len(board_firmwares) > 1:
58
+ log.debug(f"Multiple {target_version} firmwares found for {mcu.board} on {mcu.serialport}.")
59
+
60
+ # just use the last firmware
61
+ fw_info = board_firmwares[-1]
62
+ log.info(f"Found {target_version} firmware {fw_info.filename} for {mcu.board} on {mcu.serialport}.")
63
+ wl.append((mcu, fw_info))
64
+ return wl
65
+
66
+
67
+ def manual_worklist(
68
+ serial: str,
69
+ *,
70
+ board_id: str,
71
+ version: str,
72
+ fw_folder: Path,
73
+ ) -> WorkList:
74
+ """Create a worklist for a single board specified manually.
75
+
76
+ Args:
77
+ serial (str): Serial port of the board
78
+ board (str): Board_ID
79
+ version (str): Firmware version
80
+ fw_folder (Path): Path to the firmware folder
81
+
82
+ Returns:
83
+ WorkList: List of boards and firmware information to update
84
+ """
85
+ log.trace(f"Manual updating {serial} to {board_id} {version}")
86
+ mcu = MPRemoteBoard(serial)
87
+ # Lookup the matching port and cpu in board_info based in the board name
88
+ try:
89
+ info = find_known_board(board_id)
90
+ mcu.port = info.port
91
+ # need the CPU type for the esptool
92
+ mcu.cpu = info.cpu
93
+ except (LookupError, MPFlashError) as e:
94
+ log.error(f"Board {board_id} not found in board_info.zip")
95
+ log.exception(e)
96
+ return []
97
+ mcu.board = board_id
98
+ firmwares = find_downloaded_firmware(fw_folder=fw_folder, board_id=board_id, version=version, port=mcu.port)
99
+ if not firmwares:
100
+ log.error(f"No firmware found for {mcu.port} {board_id} version {version}")
101
+ return []
102
+ # use the most recent matching firmware
103
+ return [(mcu, firmwares[-1])] # type: ignore
104
+
105
+
106
+ def single_auto_worklist(
107
+ serial: str,
108
+ *,
109
+ version: str,
110
+ fw_folder: Path,
111
+ ) -> WorkList:
112
+ """Create a worklist for a single serial-port.
113
+
114
+ Args:
115
+ serial_port (str): Serial port of the board
116
+ version (str): Firmware version
117
+ fw_folder (Path): Path to the firmware folder
118
+
119
+ Returns:
120
+ WorkList: List of boards and firmware information to update
121
+ """
122
+ log.trace(f"Auto updating {serial} to {version}")
123
+ conn_boards = [MPRemoteBoard(serial)]
124
+ todo = auto_update(conn_boards, version, fw_folder) # type: ignore # List / list
125
+ show_mcus(conn_boards) # type: ignore
126
+ return todo
127
+
128
+
129
+ def full_auto_worklist(
130
+ all_boards: List[MPRemoteBoard], *, include: List[str], ignore: List[str], version: str, fw_folder: Path
131
+ ) -> WorkList:
132
+ """
133
+ Create a worklist for all connected micropython boards based on the information retrieved from the board.
134
+ This allows the firmware version of one or moae boards to be changed without needing to specify the port or board_id manually.
135
+
136
+ Args:
137
+ version (str): Firmware version
138
+ fw_folder (Path): Path to the firmware folder
139
+
140
+ Returns:
141
+ WorkList: List of boards and firmware information to update
142
+ """
143
+ log.trace(f"Auto updating all boards to {version}")
144
+ if selected_boards := filter_boards(all_boards, include=include, ignore=ignore):
145
+ return auto_update(selected_boards, version, fw_folder)
146
+ else:
147
+ return []
148
+
149
+
150
+ def filter_boards(
151
+ all_boards: List[MPRemoteBoard],
152
+ *,
153
+ include: List[str],
154
+ ignore: List[str],
155
+ ):
156
+ try:
157
+ comports = [
158
+ p.device
159
+ for p in filtered_comports(
160
+ ignore=ignore,
161
+ include=include,
162
+ bluetooth=False,
163
+ )
164
+ ]
165
+ selected_boards = [b for b in all_boards if b.serialport in comports]
166
+ # [MPRemoteBoard(port.device, update=True) for port in comports]
167
+ except ConnectionError as e:
168
+ log.error(f"Error connecting to boards: {e}")
169
+ return []
170
+ return selected_boards # type: ignore