mpflash 0.8.1__tar.gz → 0.8.1b1__tar.gz

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 (47) hide show
  1. {mpflash-0.8.1 → mpflash-0.8.1b1}/PKG-INFO +1 -1
  2. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/download.py +10 -31
  3. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/flash_uf2.py +4 -6
  4. mpflash-0.8.1b1/mpflash/flash_uf2_macos.py +37 -0
  5. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/flash_uf2_windows.py +4 -4
  6. {mpflash-0.8.1 → mpflash-0.8.1b1}/pyproject.toml +1 -1
  7. mpflash-0.8.1/mpflash/flash_uf2_macos.py +0 -78
  8. {mpflash-0.8.1 → mpflash-0.8.1b1}/LICENSE +0 -0
  9. {mpflash-0.8.1 → mpflash-0.8.1b1}/README.md +0 -0
  10. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/__init__.py +0 -0
  11. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/add_firmware.py +0 -0
  12. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/ask_input.py +0 -0
  13. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/cli_download.py +0 -0
  14. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/cli_flash.py +0 -0
  15. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/cli_group.py +0 -0
  16. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/cli_list.py +0 -0
  17. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/cli_main.py +0 -0
  18. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/common.py +0 -0
  19. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/config.py +0 -0
  20. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/connected.py +0 -0
  21. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/downloaded.py +0 -0
  22. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/errors.py +0 -0
  23. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/flash.py +0 -0
  24. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/flash_esp.py +0 -0
  25. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/flash_stm32.py +0 -0
  26. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/flash_stm32_cube.py +0 -0
  27. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/flash_stm32_dfu.py +0 -0
  28. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/flash_uf2_boardid.py +0 -0
  29. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/flash_uf2_linux.py +0 -0
  30. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/list.py +0 -0
  31. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/logger.py +0 -0
  32. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/mpboard_id/__init__.py +0 -0
  33. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/mpboard_id/add_boards.py +0 -0
  34. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/mpboard_id/board.py +0 -0
  35. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/mpboard_id/board_id.py +0 -0
  36. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/mpboard_id/board_info.zip +0 -0
  37. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/mpboard_id/store.py +0 -0
  38. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/mpremoteboard/__init__.py +0 -0
  39. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/mpremoteboard/mpy_fw_info.py +0 -0
  40. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/mpremoteboard/runner.py +0 -0
  41. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/uf2disk.py +0 -0
  42. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/vendor/basicgit.py +0 -0
  43. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/vendor/dfu.py +0 -0
  44. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/vendor/pydfu.py +0 -0
  45. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/vendor/readme.md +0 -0
  46. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/vendor/versions.py +0 -0
  47. {mpflash-0.8.1 → mpflash-0.8.1b1}/mpflash/worklist.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mpflash
3
- Version: 0.8.1
3
+ Version: 0.8.1b1
4
4
  Summary: Flash and download tool for MicroPython firmwares
5
5
  Home-page: https://github.com/Josverl/micropython-stubber/blob/main/src/mpflash/README.md
6
6
  License: MIT
@@ -32,18 +32,8 @@ MICROPYTHON_ORG_URL = "https://micropython.org/"
32
32
  # Regexes to remove dates and hashes in the filename that just get in the way
33
33
  RE_DATE = r"(-\d{8}-)"
34
34
  RE_HASH = r"(.g[0-9a-f]+\.)"
35
- # regex to extract the version and the build from the firmware filename
36
- # group 1 is the version, group 2 is the build
37
- RE_VERSION_PREVIEW = r"v([\d\.]+)-?(?:preview\.)?(\d+)?\."
38
- # 'RPI_PICO_W-v1.23.uf2'
39
- # 'RPI_PICO_W-v1.23.0.uf2'
40
- # 'RPI_PICO_W-v1.23.0-406.uf2'
41
- # 'RPI_PICO_W-v1.23.0-preview.406.uf2'
42
- # 'RPI_PICO_W-v1.23.0-preview.4.uf2'
43
- # 'RPI_PICO_W-v1.23.0.uf2'
44
- # 'https://micropython.org/resources/firmware/RPI_PICO_W-20240531-v1.24.0-preview.10.gc1a6b95bf.uf2'
45
- # 'https://micropython.org/resources/firmware/RPI_PICO_W-20240531-v1.24.0-preview.10.uf2'
46
- # 'RPI_PICO_W-v1.24.0-preview.10.gc1a6b95bf.uf2'
35
+ # regex to extract the version from the firmware filename
36
+ RE_VERSION_PREVIEW = r"(\d+\.\d+(\.\d+)?(-\w+.\d+)?)"
47
37
 
48
38
 
49
39
  # use functools.lru_cache to avoid needing to download pages multiple times
@@ -108,7 +98,6 @@ def board_firmware_urls(board_url: str, base_url: str, ext: str) -> List[str]:
108
98
  # The first run takes ~60 seconds to run for 4 ports , all boards
109
99
  # so it makes sense to cache the results and skip boards as soon as possible
110
100
  def get_boards(ports: List[str], boards: List[str], clean: bool) -> List[FWInfo]:
111
- # sourcery skip: use-getitem-for-re-match-groups
112
101
  """
113
102
  Retrieves a list of firmware information for the specified ports and boards.
114
103
 
@@ -157,15 +146,13 @@ def get_boards(ports: List[str], boards: List[str], clean: bool) -> List[FWInfo]
157
146
  # board["firmware"] = _url
158
147
  # board["preview"] = "preview" in _url # type: ignore
159
148
  if ver_match := re.search(RE_VERSION_PREVIEW, _url):
160
- fw_info.version = ver_match.group(1)
161
- fw_info.build = ver_match.group(2) or "0"
162
- fw_info.preview = fw_info.build != "0"
163
- # # else:
164
- # # board.$1= ""
165
- # if "preview." in fw_info.version:
166
- # fw_info.build = fw_info.version.split("preview.")[-1]
149
+ fw_info.version = ver_match[1]
167
150
  # else:
168
- # fw_info.build = "0"
151
+ # board.$1= ""
152
+ if "preview." in fw_info.version:
153
+ fw_info.build = fw_info.version.split("preview.")[-1]
154
+ else:
155
+ fw_info.build = "0"
169
156
 
170
157
  fw_info.ext = Path(fw_info.firmware).suffix
171
158
  fw_info.variant = fw_info.filename.split("-v")[0] if "-v" in fw_info.filename else ""
@@ -204,11 +191,6 @@ def download_firmwares(
204
191
  # relevant
205
192
 
206
193
  log.info(f"Found {len(unique_boards)} relevant unique firmwares")
207
- if not unique_boards:
208
- log.error("No relevant firmwares could be found on https://micropython.org/download")
209
- log.info(f"{versions=} {ports=} {boards=}")
210
- log.info("Please check the website for the latest firmware files or try the preview version.")
211
- return 0
212
194
 
213
195
  firmware_folder.mkdir(exist_ok=True)
214
196
 
@@ -256,15 +238,12 @@ def get_firmware_list(ports: List[str], boards: List[str], versions: List[str],
256
238
  board_urls = sorted(get_boards(ports, boards, clean), key=key_fw_ver_pre_ext_bld)
257
239
 
258
240
  log.debug(f"Total {len(board_urls)} firmwares")
259
-
260
241
  relevant = [
261
242
  board
262
243
  for board in board_urls
263
- if board.version in versions and board.build == "0" and board.board in boards and not board.preview
244
+ if board.board in boards and (board.version in versions or board.preview and preview)
245
+ # and b["port"] in ["esp32", "rp2"]
264
246
  ]
265
-
266
- if preview:
267
- relevant.extend([board for board in board_urls if board.board in boards and board.preview])
268
247
  log.debug(f"Matching firmwares: {len(relevant)}")
269
248
  # select the unique boards
270
249
  unique_boards: List[FWInfo] = []
@@ -14,7 +14,7 @@ from rich.progress import track
14
14
  from mpflash.mpremoteboard import MPRemoteBoard
15
15
 
16
16
  from .common import PORT_FWTYPES
17
- from .config import config
17
+ from .flash_uf2_boardid import get_board_id
18
18
  from .flash_uf2_linux import dismount_uf2_linux, wait_for_UF2_linux
19
19
  from .flash_uf2_macos import wait_for_UF2_macos
20
20
  from .flash_uf2_windows import wait_for_UF2_windows
@@ -45,11 +45,7 @@ def flash_uf2(mcu: MPRemoteBoard, fw_file: Path, erase: bool) -> Optional[MPRemo
45
45
  destination = wait_for_UF2_windows()
46
46
  elif sys.platform == "darwin":
47
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()
48
+ destination = wait_for_UF2_macos()
53
49
  else:
54
50
  log.warning(f"OS {sys.platform} not tested/supported")
55
51
  return None
@@ -59,6 +55,8 @@ def flash_uf2(mcu: MPRemoteBoard, fw_file: Path, erase: bool) -> Optional[MPRemo
59
55
  return None
60
56
 
61
57
  log.info("Board is in bootloader mode")
58
+ board_id = get_board_id(destination) # type: ignore
59
+ log.info(f"Board ID: {board_id}")
62
60
  log.info(f"Copying {fw_file} to {destination}.")
63
61
  shutil.copy(fw_file, destination)
64
62
  log.success("Done copying, resetting the board and wait for it to restart")
@@ -0,0 +1,37 @@
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
+ from typing import Optional
10
+
11
+ from loguru import logger as log
12
+ from rich.progress import track
13
+
14
+ from .flash_uf2_boardid import get_board_id
15
+
16
+
17
+ def wait_for_UF2_macos(s_max: int = 10) -> Optional[Path]:
18
+ """Wait for the MCU to mount as a drive"""
19
+ if s_max < 1:
20
+ s_max = 10
21
+ destination = None
22
+ for _ in track(
23
+ range(s_max), description="Waiting for mcu to mount as a drive", transient=True, refresh_per_second=2
24
+ ):
25
+ # log.info(f"Waiting for mcu to mount as a drive : {n} seconds left")
26
+ vol_mounts = Path("/Volumes").iterdir()
27
+ for vol in vol_mounts:
28
+ try:
29
+ if Path(vol, "INFO_UF2.TXT").exists():
30
+ destination = Path(vol)
31
+ break
32
+ except OSError:
33
+ pass
34
+ if destination:
35
+ break
36
+ time.sleep(1)
37
+ return destination
@@ -5,25 +5,25 @@ from __future__ import annotations
5
5
 
6
6
  import time
7
7
  from pathlib import Path
8
+ from typing import Optional
8
9
 
9
10
  import psutil
10
11
  from rich.progress import track
11
12
 
12
- from .flash_uf2_boardid import get_board_id
13
13
 
14
14
 
15
- def wait_for_UF2_windows(s_max: int = 10):
15
+
16
+ def wait_for_UF2_windows(s_max: int = 10) -> Optional[Path]:
16
17
  """Wait for the MCU to mount as a drive"""
17
18
  if s_max < 1:
18
19
  s_max = 10
19
- destination = ""
20
+ destination = None
20
21
  for _ in track(range(s_max), description="Waiting for mcu to mount as a drive", transient=True,refresh_per_second=2):
21
22
  # log.info(f"Waiting for mcu to mount as a drive : {n} seconds left")
22
23
  drives = [drive.device for drive in psutil.disk_partitions()]
23
24
  for drive in drives:
24
25
  try:
25
26
  if Path(drive, "INFO_UF2.TXT").exists():
26
- board_id = get_board_id(Path(drive)) # type: ignore
27
27
  destination = Path(drive)
28
28
  break
29
29
  except OSError:
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "mpflash"
3
- version = "0.8.1"
3
+ version = "0.8.1b1"
4
4
  description = "Flash and download tool for MicroPython firmwares"
5
5
  authors = ["Jos Verlinde <jos_verlinde@hotmail.com>"]
6
6
  license = "MIT"
@@ -1,78 +0,0 @@
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes