mpflash 0.2.2__py3-none-any.whl → 0.2.2.post2__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.
mpflash/cli_group.py CHANGED
@@ -40,11 +40,11 @@ def cb_ignore(ctx, param, value):
40
40
  "--ignore",
41
41
  "-i",
42
42
  is_eager=True,
43
- help="Serial port(s) to ignore. Defaults to MPTOOL_IGNORE.",
43
+ help="Serial port(s) to ignore. Defaults to MPFLASH_IGNORE.",
44
44
  callback=cb_ignore,
45
45
  multiple=True,
46
46
  default=[],
47
- envvar="MPTOOL_IGNORE",
47
+ envvar="MPFLASH_IGNORE",
48
48
  show_default=True,
49
49
  metavar="SERIALPORT",
50
50
  )
mpflash/cli_main.py CHANGED
@@ -14,7 +14,7 @@ def mpflash():
14
14
  # cli.add_command(flash_board)
15
15
  # cli.add_command(list_boards)
16
16
  # cli.add_command(download)
17
- cli() # auto_envvar_prefix='MPTOOL')
17
+ cli(auto_envvar_prefix="MPFLASH")
18
18
 
19
19
 
20
20
  if __name__ == "__main__":
mpflash/common.py CHANGED
@@ -1,6 +1,7 @@
1
1
  from pathlib import Path
2
2
  from typing import Dict, Union
3
3
 
4
+ import platformdirs
4
5
  from github import Github
5
6
  from loguru import logger as log
6
7
  from packaging.version import parse
@@ -12,11 +13,11 @@ PORT_FWTYPES = {
12
13
  "rp2": ".uf2",
13
14
  "samd": ".uf2",
14
15
  "mimxrt": ".hex",
15
- "nrf": ".hex",
16
+ "nrf": ".uf2",
16
17
  "renesas-ra": ".hex",
17
18
  }
18
19
 
19
- DEFAULT_FW_PATH = Path.cwd() / "firmware"
20
+ DEFAULT_FW_PATH = platformdirs.user_downloads_path() / "firmware"
20
21
  # DEFAULT_FW_PATH = Path.home() / "mp_firmware"
21
22
 
22
23
  FWInfo = Dict[str, Union[str, bool]]
@@ -87,9 +88,7 @@ def micropython_versions(minver: str = "v1.9.2"):
87
88
  g = Github()
88
89
  _ = 1 / 0
89
90
  repo = g.get_repo("micropython/micropython")
90
- versions = [
91
- tag.name for tag in repo.get_tags() if parse(tag.name) >= parse(minver)
92
- ]
91
+ versions = [tag.name for tag in repo.get_tags() if parse(tag.name) >= parse(minver)]
93
92
  except Exception:
94
93
  versions = [
95
94
  "v9.99.9-preview",
mpflash/downloader.py CHANGED
@@ -18,7 +18,7 @@ from loguru import logger as log
18
18
  from rich.progress import track
19
19
 
20
20
  from .cli_group import cli
21
- from .common import PORT_FWTYPES, clean_version
21
+ from .common import DEFAULT_FW_PATH, PORT_FWTYPES, clean_version
22
22
 
23
23
  MICROPYTHON_ORG_URL = "https://micropython.org/"
24
24
 
@@ -40,6 +40,7 @@ DEFAULT_BOARDS = [
40
40
  "ARDUINO_NANO_RP2040_CONNECT",
41
41
  "PIMORONI_PICOLIPO_16MB",
42
42
  "SEEED_WIO_TERMINAL",
43
+ "PARTICLE_XENON",
43
44
  ]
44
45
 
45
46
 
@@ -77,9 +78,7 @@ def firmware_list(board_url: str, base_url: str, ext: str) -> List[str]:
77
78
  tags = soup.findAll(
78
79
  "a",
79
80
  recursive=True,
80
- attrs={
81
- "href": re.compile(r"^/resources/firmware/.*\." + ext.lstrip(".") + "$")
82
- },
81
+ attrs={"href": re.compile(r"^/resources/firmware/.*\." + ext.lstrip(".") + "$")},
83
82
  )
84
83
  if "?" in base_url:
85
84
  base_url = base_url.split("?")[0]
@@ -94,9 +93,7 @@ FirmwareInfo = Dict[str, str]
94
93
  # boards we are interested in ( this avoids getting a lot of boards we don't care about)
95
94
  # The first run takes ~60 seconds to run for 4 ports , all boards
96
95
  # so it makes sense to cache the results and skip boards as soon as possible
97
- def get_boards(
98
- fw_types: Dict[str, str], board_list: List[str], clean: bool
99
- ) -> List[FirmwareInfo]:
96
+ def get_boards(fw_types: Dict[str, str], board_list: List[str], clean: bool) -> List[FirmwareInfo]:
100
97
  board_urls: List[FirmwareInfo] = []
101
98
  for port in fw_types:
102
99
  download_page_url = f"{MICROPYTHON_ORG_URL}download/?port={port}"
@@ -107,9 +104,7 @@ def get_boards(
107
104
  for board in _urls:
108
105
  board["port"] = port
109
106
 
110
- for board in track(
111
- _urls, description="Checking download pages", transient=True
112
- ):
107
+ for board in track(_urls, description=f"Checking {port} download pages", transient=True):
113
108
  # add a board to the list for each firmware found
114
109
  firmwares = firmware_list(board["url"], MICROPYTHON_ORG_URL, fw_types[port])
115
110
  for _url in firmwares:
@@ -130,11 +125,7 @@ def get_boards(
130
125
  # remove hash from firmware name
131
126
  fname = re.sub(RE_HASH, ".", fname)
132
127
  board["filename"] = fname
133
- board["variant"] = (
134
- board["filename"].split("-v")[0]
135
- if "-v" in board["filename"]
136
- else ""
137
- )
128
+ board["variant"] = board["filename"].split("-v")[0] if "-v" in board["filename"] else ""
138
129
  board_urls.append(board.copy())
139
130
  return board_urls
140
131
 
@@ -171,9 +162,7 @@ def download_firmwares(
171
162
 
172
163
  firmware_folder.mkdir(exist_ok=True)
173
164
 
174
- with open(
175
- firmware_folder / "firmware.jsonl", "a", encoding="utf-8", buffering=1
176
- ) as f_jsonl:
165
+ with open(firmware_folder / "firmware.jsonl", "a", encoding="utf-8", buffering=1) as f_jsonl:
177
166
  for board in unique_boards:
178
167
  filename = firmware_folder / board["port"] / board["filename"]
179
168
  filename.parent.mkdir(exist_ok=True)
@@ -197,21 +186,16 @@ def download_firmwares(
197
186
  log.info(f"Downloaded {downloaded} firmwares, skipped {skipped} existing files.")
198
187
 
199
188
 
200
- def get_firmware_list(
201
- board_list: List[str], version_list: List[str], preview: bool, clean: bool
202
- ):
189
+ def get_firmware_list(board_list: List[str], version_list: List[str], preview: bool, clean: bool):
203
190
  log.trace("Checking MicroPython download pages")
204
191
 
205
- board_urls = sorted(
206
- get_boards(PORT_FWTYPES, board_list, clean), key=key_fw_variant_ver
207
- )
192
+ board_urls = sorted(get_boards(PORT_FWTYPES, board_list, clean), key=key_fw_variant_ver)
208
193
 
209
194
  log.debug(f"Total {len(board_urls)} firmwares")
210
195
  relevant = [
211
196
  board
212
197
  for board in board_urls
213
- if board["board"] in board_list
214
- and (board["version"] in version_list or board["preview"] and preview)
198
+ if board["board"] in board_list and (board["version"] in version_list or board["preview"] and preview)
215
199
  # and b["port"] in ["esp32", "rp2"]
216
200
  ]
217
201
  log.debug(f"Matching firmwares: {len(relevant)}")
@@ -233,7 +217,7 @@ def get_firmware_list(
233
217
  "--destination",
234
218
  "-d",
235
219
  type=click.Path(file_okay=False, dir_okay=True, path_type=Path),
236
- default="./firmware",
220
+ default=DEFAULT_FW_PATH,
237
221
  show_default=True,
238
222
  help="The folder to download the firmware to.",
239
223
  )
@@ -267,19 +251,13 @@ def get_firmware_list(
267
251
  help="""Force download of firmware even if it already exists.""",
268
252
  show_default=True,
269
253
  )
270
- def download(
271
- destination: Path, boards: List[str], versions: List[str], force: bool, clean: bool
272
- ):
254
+ def download(destination: Path, boards: List[str], versions: List[str], force: bool, clean: bool):
273
255
  versions = list(versions)
274
256
  # preview is not a version, it is an option to include preview versions
275
257
  preview = "preview" in versions
276
258
  versions = [v for v in versions if v != "preview"]
277
259
 
278
260
  boards = list(boards) or DEFAULT_BOARDS
279
- versions = [
280
- clean_version(v, drop_v=True) for v in versions
281
- ] # remove leading v from version
261
+ versions = [clean_version(v, drop_v=True) for v in versions] # remove leading v from version
282
262
  destination.mkdir(exist_ok=True)
283
- download_firmwares(
284
- destination, boards, versions, preview=preview, force=force, clean=clean
285
- )
263
+ download_firmwares(destination, boards, versions, preview=preview, force=force, clean=clean)
mpflash/flasher.py CHANGED
@@ -104,9 +104,7 @@ def auto_update(conn_boards: List[MPRemoteBoard], target_version: str, fw_folder
104
104
  wl: WorkList = []
105
105
  for mcu in conn_boards:
106
106
  if mcu.family != "micropython":
107
- log.warning(
108
- f"Skipping {mcu.board} on {mcu.serialport} as it is not a micropython board"
109
- )
107
+ log.warning(f"Skipping {mcu.board} on {mcu.serialport} as it is not a micropython board")
110
108
  continue
111
109
  board_firmwares = find_firmware(
112
110
  fw_folder=fw_folder,
@@ -117,19 +115,13 @@ def auto_update(conn_boards: List[MPRemoteBoard], target_version: str, fw_folder
117
115
  )
118
116
 
119
117
  if not board_firmwares:
120
- log.error(
121
- f"No {target_version} firmware found for {mcu.board} on {mcu.serialport}."
122
- )
118
+ log.error(f"No {target_version} firmware found for {mcu.board} on {mcu.serialport}.")
123
119
  continue
124
120
  if len(board_firmwares) > 1:
125
- log.debug(
126
- f"Multiple {target_version} firmwares found for {mcu.board} on {mcu.serialport}."
127
- )
121
+ log.debug(f"Multiple {target_version} firmwares found for {mcu.board} on {mcu.serialport}.")
128
122
  # just use the last firmware
129
123
  fw_info = board_firmwares[-1]
130
- log.info(
131
- f"Found {target_version} firmware {fw_info['filename']} for {mcu.board} on {mcu.serialport}."
132
- )
124
+ log.info(f"Found {target_version} firmware {fw_info['filename']} for {mcu.board} on {mcu.serialport}.")
133
125
  wl.append((mcu, fw_info))
134
126
  return wl
135
127
 
@@ -148,7 +140,7 @@ def auto_update(conn_boards: List[MPRemoteBoard], target_version: str, fw_folder
148
140
  "-f",
149
141
  "fw_folder",
150
142
  type=click.Path(exists=True, file_okay=False, dir_okay=True, path_type=Path),
151
- default="./firmware",
143
+ default=DEFAULT_FW_PATH,
152
144
  show_default=True,
153
145
  help="The folder to retrieve the firmware from.",
154
146
  )
@@ -233,9 +225,7 @@ def flash_board(
233
225
  if serial_port == "auto":
234
226
  # update all connected boards
235
227
  conn_boards = [
236
- MPRemoteBoard(sp)
237
- for sp in MPRemoteBoard.connected_boards()
238
- if sp not in config.ignore_ports
228
+ MPRemoteBoard(sp) for sp in MPRemoteBoard.connected_boards() if sp not in config.ignore_ports
239
229
  ]
240
230
  else:
241
231
  # just this serial port
@@ -247,9 +237,7 @@ def flash_board(
247
237
  for mcu, fw_info in todo:
248
238
  fw_file = fw_folder / fw_info["filename"] # type: ignore
249
239
  if not fw_file.exists():
250
- log.error(
251
- f"File {fw_file} does not exist, skipping {mcu.board} on {mcu.serialport}"
252
- )
240
+ log.error(f"File {fw_file} does not exist, skipping {mcu.board} on {mcu.serialport}")
253
241
  continue
254
242
  log.info(f"Updating {mcu.board} on {mcu.serialport} to {fw_info['version']}")
255
243
 
@@ -269,12 +257,13 @@ def flash_board(
269
257
 
270
258
  if flashed:
271
259
  log.info(f"Flashed {len(flashed)} boards")
272
- conn_boards = [
273
- MPRemoteBoard(sp)
274
- for sp in MPRemoteBoard.connected_boards()
275
- if sp not in config.ignore_ports
276
- ]
277
- show_boards(conn_boards, title="Connected boards after flashing")
260
+ # conn_boards = [
261
+ # MPRemoteBoard(sp)
262
+ # for sp in MPRemoteBoard.connected_boards()
263
+ # if sp not in config.ignore_ports
264
+ # ]
265
+
266
+ show_boards(flashed, title="Connected boards after flashing")
278
267
 
279
268
 
280
269
  # TODO:
mpflash/list.py CHANGED
@@ -24,11 +24,7 @@ from .config import config
24
24
  help="""Output in json format""",
25
25
  )
26
26
  def list_boards(as_json: bool):
27
- conn_boards = [
28
- MPRemoteBoard(sp)
29
- for sp in MPRemoteBoard.connected_boards()
30
- if sp not in config.ignore_ports
31
- ]
27
+ conn_boards = [MPRemoteBoard(sp) for sp in MPRemoteBoard.connected_boards() if sp not in config.ignore_ports]
32
28
 
33
29
  for mcu in track(conn_boards, description="Getting board info"):
34
30
  try:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mpflash
3
- Version: 0.2.2
3
+ Version: 0.2.2.post2
4
4
  Summary: Download and flashing tool for MicroPython firmwares
5
5
  Home-page: https://github.com/Josverl/micropython-stubber/blob/main/src/mpflash/README.md
6
6
  License: MIT
@@ -23,6 +23,7 @@ Requires-Dist: esptool (>=4.7.0,<5.0.0)
23
23
  Requires-Dist: jsonlines (>=4.0.0,<5.0.0)
24
24
  Requires-Dist: loguru (>=0.7.2,<0.8.0)
25
25
  Requires-Dist: micropython-stubber (>=1.17.4)
26
+ Requires-Dist: platformdirs (>=4.2.0,<5.0.0)
26
27
  Requires-Dist: psutil (>=5.9.8,<6.0.0)
27
28
  Requires-Dist: pygithub (>=2.1.1,<3.0.0)
28
29
  Requires-Dist: requests (>=2.31.0,<3.0.0)
@@ -76,9 +77,12 @@ This will download the latest stable version of the MicroPython firmware for the
76
77
  The stable version (default) is determined based on the most recent published release,
77
78
  other optionse are `--version preview` and `--version x.y.z` to download the latest preview or version x.y.z respectively.
78
79
 
80
+ by default the firmware will be downloaded to Downloads in a `firmware` folder in your, but you can specify a different directory using the `--dir` option.
81
+
82
+ ```bash
79
83
  The directory structure will be something like this:
80
84
  ```
81
- firmware
85
+ Downloads/firmware
82
86
  | firmware.jsonl
83
87
  +---esp8266
84
88
  | ESP8266_GENERIC-FLASH_1M-v1.22.2.bin
@@ -0,0 +1,20 @@
1
+ mpflash/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ mpflash/cli_group.py,sha256=oWgZlUoXY_Wc9-XMXxuxH3F0TevYNafsFWpRtT_WiiU,1228
3
+ mpflash/cli_main.py,sha256=nLFfR-ti_stLVvgwDRsNXgaQ43gQVZUOz_xvRERPuy0,494
4
+ mpflash/common.py,sha256=RBNfbojPKLK3_cxLFIvtHWy8UZUbBxN0ogBN0nliVR4,3896
5
+ mpflash/config.py,sha256=R_sYZ_UwzIc9H2vhwIU5RSDhpcV3fHIX83FEURWOd5E,160
6
+ mpflash/downloader.py,sha256=QVtgocj4b-c9ZunzEZnsyhEZu_Lbk8Hk-43qWBMJ0AI,9783
7
+ mpflash/flash_esp.py,sha256=XffVg1BKzaQo4pzSJdUoHmHa7h4s4gBlNQR50ahGJ1E,2301
8
+ mpflash/flash_stm32.py,sha256=Pn1y9rKw48D0khucT8yU3NjFkHQ9YYTvwco9ir4MmpQ,3742
9
+ mpflash/flash_uf2.py,sha256=8rZRqdi3Rtp8UsHxKgmoMfZ1yBXZbMFXcOeyVVMmX5w,2029
10
+ mpflash/flash_uf2_linux.py,sha256=wXtpqFan6x5k8h2bwwLqwY-LKbpyTg7n2SbD4eb6yH0,4012
11
+ mpflash/flash_uf2_windows.py,sha256=AiFg5jrSyEMX2QxC2sgfn8GekKBw-fPkIi8emlU7Z7o,711
12
+ mpflash/flasher.py,sha256=J7-bsrfQ0MPEKrnUx47q0OqAS61roLBaETu4nv4MfMU,9400
13
+ mpflash/list.py,sha256=7GpZEK7fh6GCzgUdRLHGp8FMEeCbLstV-2u3ohaRYsc,1970
14
+ mpflash/logger.py,sha256=FvGQSR2l4O9nmJV0rKbyoeJDd7fbY2vKQTmPEED0h6s,1048
15
+ mpflash/uf2_boardid.py,sha256=WZKucGu_hJ8ymb236uuZbiR6pD6AA_l4LA-7LwtQhq8,414
16
+ mpflash-0.2.2.post2.dist-info/entry_points.txt,sha256=Jk_visOhYOsZIcSP2Ms9hKqfKy1iorR-6dYltSoWCpY,52
17
+ mpflash-0.2.2.post2.dist-info/LICENSE,sha256=mWpNhsIxWzetYNnTpr4eb3HtgsxGIC8KcYWxXEcxQvE,1077
18
+ mpflash-0.2.2.post2.dist-info/METADATA,sha256=_Dem1zESHqzvSoy3kpmUnuJ8Doz5tqY90B9hLeQ2iv8,12786
19
+ mpflash-0.2.2.post2.dist-info/WHEEL,sha256=d2fvjOD7sXsVzChCqf0Ty0JbHKBaLYwDbGQDwQTnJ50,88
20
+ mpflash-0.2.2.post2.dist-info/RECORD,,
@@ -1,20 +0,0 @@
1
- mpflash/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- mpflash/cli_group.py,sha256=FuSJwE0z1lvnT1TMFs8Ejsps3UUzxyI-xdzYOa_HA3A,1226
3
- mpflash/cli_main.py,sha256=fAh_gUrn2Tvo5PkFjiCNy0FX_KYlRY6y627WG0t1MGE,498
4
- mpflash/common.py,sha256=bW1_JY5904cm6luUlMQmzgYXk7ukrDyMaxwovOyfHes,3875
5
- mpflash/config.py,sha256=R_sYZ_UwzIc9H2vhwIU5RSDhpcV3fHIX83FEURWOd5E,160
6
- mpflash/downloader.py,sha256=OsOTNjv-91RQc2quD8ptUzI1-pJhHekE8jARdg-1rhk,9961
7
- mpflash/flash_esp.py,sha256=XffVg1BKzaQo4pzSJdUoHmHa7h4s4gBlNQR50ahGJ1E,2301
8
- mpflash/flash_stm32.py,sha256=Pn1y9rKw48D0khucT8yU3NjFkHQ9YYTvwco9ir4MmpQ,3742
9
- mpflash/flash_uf2.py,sha256=8rZRqdi3Rtp8UsHxKgmoMfZ1yBXZbMFXcOeyVVMmX5w,2029
10
- mpflash/flash_uf2_linux.py,sha256=wXtpqFan6x5k8h2bwwLqwY-LKbpyTg7n2SbD4eb6yH0,4012
11
- mpflash/flash_uf2_windows.py,sha256=AiFg5jrSyEMX2QxC2sgfn8GekKBw-fPkIi8emlU7Z7o,711
12
- mpflash/flasher.py,sha256=_N-CYZZZ401kxZ45CDgl1XDj3lqdMPHjhpbn82ow2Kc,9575
13
- mpflash/list.py,sha256=shFNDyEnmqqDjiJ4WSpJLTkDO_6H3fvYBeJKzfGFJMw,2004
14
- mpflash/logger.py,sha256=FvGQSR2l4O9nmJV0rKbyoeJDd7fbY2vKQTmPEED0h6s,1048
15
- mpflash/uf2_boardid.py,sha256=WZKucGu_hJ8ymb236uuZbiR6pD6AA_l4LA-7LwtQhq8,414
16
- mpflash-0.2.2.dist-info/entry_points.txt,sha256=Jk_visOhYOsZIcSP2Ms9hKqfKy1iorR-6dYltSoWCpY,52
17
- mpflash-0.2.2.dist-info/LICENSE,sha256=mWpNhsIxWzetYNnTpr4eb3HtgsxGIC8KcYWxXEcxQvE,1077
18
- mpflash-0.2.2.dist-info/METADATA,sha256=eq_XOtT3s1qrapRnQohULy9OTyMgEBaBFdOesxKeheU,12558
19
- mpflash-0.2.2.dist-info/WHEEL,sha256=d2fvjOD7sXsVzChCqf0Ty0JbHKBaLYwDbGQDwQTnJ50,88
20
- mpflash-0.2.2.dist-info/RECORD,,