mpbuild 0.7__tar.gz → 0.9__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.
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mpbuild
3
- Version: 0.7
3
+ Version: 0.9
4
4
  Summary: Build MicroPython firmware with ease!
5
5
  Author-email: Matt Trentini <matt.trentini@gmail.com>
6
6
  License-File: LICENSE
7
- Requires-Python: >=3.9
7
+ Requires-Python: >=3.12
8
8
  Requires-Dist: rich>=13.7.1
9
9
  Requires-Dist: typer>=0.12.3
10
10
  Description-Content-Type: text/markdown
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mpbuild"
3
- version = "0.7"
3
+ version = "0.9"
4
4
  description = "Build MicroPython firmware with ease!"
5
5
  authors = [
6
6
  { name = "Matt Trentini", email = "matt.trentini@gmail.com" }
@@ -10,7 +10,7 @@ dependencies = [
10
10
  "rich>=13.7.1",
11
11
  ]
12
12
  readme = "README.md"
13
- requires-python = ">= 3.9"
13
+ requires-python = ">= 3.12"
14
14
 
15
15
  [project.scripts]
16
16
  mpbuild = "mpbuild.__main__:main"
@@ -34,10 +34,10 @@ provides a way to browse it's data.
34
34
 
35
35
  from __future__ import annotations
36
36
 
37
- from pathlib import Path
38
37
  import json
39
38
  from dataclasses import dataclass, field
40
39
  from glob import glob
40
+ from pathlib import Path
41
41
 
42
42
 
43
43
  class MpbuildMpyDirectoryException(Exception):
@@ -110,12 +110,12 @@ class Board:
110
110
  board = Board(
111
111
  name=filename_json.parent.name,
112
112
  variants=[],
113
- url=board_json["url"],
114
- mcu=board_json["mcu"],
115
- product=board_json["product"],
116
- vendor=board_json["vendor"],
117
- images=board_json["images"],
118
- deploy=board_json["deploy"],
113
+ url=board_json.get("url", "http://micropython.org"),
114
+ mcu=board_json.get("mcu", ""),
115
+ product=board_json.get("product", ""),
116
+ vendor=board_json.get("vendor", ""),
117
+ images=board_json.get("images", []),
118
+ deploy=board_json.get("deploy", []),
119
119
  physical_board=True,
120
120
  port=port,
121
121
  )
@@ -159,6 +159,9 @@ class Board:
159
159
  for v in self.variants:
160
160
  if v.name == variant:
161
161
  return v
162
+ print(
163
+ f"Variant '{variant}' not found for board '{self.name}': Valid variants are: {[v.name for v in self.variants]}"
164
+ )
162
165
 
163
166
  return None
164
167
 
@@ -239,7 +242,6 @@ class Database:
239
242
  port = Port(
240
243
  name=special_port_name,
241
244
  directory=path,
242
- boards={special_port_name: board},
243
245
  )
244
246
  board = Board(
245
247
  name=special_port_name,
@@ -253,10 +255,10 @@ class Database:
253
255
  physical_board=False,
254
256
  port=port,
255
257
  )
258
+ port.boards = {special_port_name: board}
256
259
  board.variants = [
257
260
  Variant(name=v, text="", board=board) for v in variant_names
258
261
  ]
259
-
260
262
  self.ports[special_port_name] = port
261
263
  self.boards[board.name] = board
262
264
 
@@ -269,3 +271,32 @@ class Database:
269
271
  raise MpbuildMpyDirectoryException(
270
272
  f"Directory does not point to the top of a micropython repo: {directory}"
271
273
  )
274
+
275
+ @staticmethod
276
+ def check_board_json(
277
+ board_json: dict, board_name: str, port_name: str
278
+ ) -> list[str]:
279
+ """
280
+ Checks a board.json file for missing or invalid keys.
281
+ Returns a list of issues found.
282
+ """
283
+ issues = []
284
+ required_keys = ["mcu", "product", "vendor", "images", "deploy"]
285
+
286
+ for key in required_keys:
287
+ if key not in board_json:
288
+ issues.append(f"{port_name}/{board_name}: Missing required key '{key}'")
289
+
290
+ if "url" not in board_json:
291
+ issues.append(f"{port_name}/{board_name}: Missing URL key")
292
+
293
+ if "variants" in board_json and not isinstance(board_json["variants"], dict):
294
+ issues.append(f"{port_name}/{board_name}: 'variants' is not a dictionary")
295
+
296
+ if "images" in board_json and not isinstance(board_json["images"], list):
297
+ issues.append(f"{port_name}/{board_name}: 'images' is not a list")
298
+
299
+ if "deploy" in board_json and not isinstance(board_json["deploy"], list):
300
+ issues.append(f"{port_name}/{board_name}: 'deploy' is not a list")
301
+
302
+ return issues
@@ -4,6 +4,8 @@ from typing import Optional, List
4
4
  from pathlib import Path
5
5
  import multiprocessing
6
6
  import subprocess
7
+ import sys
8
+ import glob
7
9
 
8
10
  from rich import print
9
11
  from rich.panel import Panel
@@ -20,7 +22,8 @@ BUILD_CONTAINERS = {
20
22
  "mimxrt": ARM_BUILD_CONTAINER,
21
23
  "renesas-ra": ARM_BUILD_CONTAINER,
22
24
  "samd": ARM_BUILD_CONTAINER,
23
- "esp32": "espressif/idf",
25
+ "psoc6": "ifxmakers/mpy-mtb-ci",
26
+ "esp32": "espressif/idf:v5.4.1",
24
27
  "esp8266": "larsks/esp-open-sdk",
25
28
  "unix": "gcc:12-bookworm", # Special, doesn't have boards
26
29
  }
@@ -54,8 +57,6 @@ def get_build_container(board: Board, variant: Optional[str] = None) -> str:
54
57
  raise MpbuildNotSupportedException(f"{board.name}-{variant}") from e
55
58
 
56
59
 
57
- IDF_DEFAULT = "v5.2.2"
58
-
59
60
  nprocs = multiprocessing.cpu_count()
60
61
 
61
62
 
@@ -65,7 +66,6 @@ def docker_build_cmd(
65
66
  extra_args: List[str] = [],
66
67
  do_clean: bool = False,
67
68
  build_container_override: str | None = None,
68
- idf: str = IDF_DEFAULT,
69
69
  docker_interactive: bool = True,
70
70
  ) -> str:
71
71
  """
@@ -87,11 +87,6 @@ def docker_build_cmd(
87
87
  else get_build_container(board=board, variant=variant)
88
88
  )
89
89
 
90
- if port.name == "esp32" and not build_container_override:
91
- if not idf:
92
- idf = IDF_DEFAULT
93
- build_container += f":{idf}"
94
-
95
90
  variant_param = "BOARD_VARIANT" if board.physical_board else "VARIANT"
96
91
  variant_cmd = "" if variant is None else f" {variant_param}={variant}"
97
92
 
@@ -99,9 +94,8 @@ def docker_build_cmd(
99
94
 
100
95
  make_mpy_cross_cmd = "make -C mpy-cross && "
101
96
  update_submodules_cmd = (
102
- f"make -C ports/{port.name} submodules BOARD={board.name}{variant_cmd} && "
97
+ f"make -C ports/{port.name} BOARD={board.name}{variant_cmd} submodules && "
103
98
  )
104
-
105
99
  uid, gid = os.getuid(), os.getgid()
106
100
 
107
101
  if do_clean:
@@ -111,19 +105,28 @@ def docker_build_cmd(
111
105
  make_mpy_cross_cmd = ""
112
106
  update_submodules_cmd = ""
113
107
 
114
- home = os.environ["HOME"]
115
108
  mpy_dir = str(port.directory_repo)
116
109
 
110
+ # Dynamically find all ttyACM and ttyUSB devices
111
+ tty_devices = []
112
+ for pattern in ["/dev/ttyACM*", "/dev/ttyUSB*"]:
113
+ tty_devices.extend(glob.glob(pattern))
114
+
115
+ # Build device flags
116
+ device_flags = ""
117
+ if os.path.exists("/dev/bus/usb/") and os.listdir("/dev/bus/usb/"):
118
+ device_flags += "--device /dev/bus/usb/ " # USB access
119
+ for device in tty_devices:
120
+ device_flags += f"--device {device} "
121
+
117
122
  # fmt: off
118
123
  build_cmd = (
119
124
  f"docker run --rm "
120
125
  f"{'-it ' if docker_interactive else ''}"
121
- f"-v /sys/bus:/sys/bus " # provides access to USB for deploy
122
- f"-v /dev:/dev " # provides access to USB for deploy
123
- f"--net=host --privileged " # provides access to USB for deploy
126
+ f"{device_flags}" # provides access to USB and serial devices for deploy
124
127
  f"-v {mpy_dir}:{mpy_dir} -w {mpy_dir} " # mount micropython dir with same path so elf/map paths match host
125
128
  f"--user {uid}:{gid} " # match running user id so generated files aren't owned by root
126
- f"-v {home}:{home} -e HOME={home} " # when changing user id to one not present in container this ensures home is writable
129
+ f"-e HOME=/tmp " # set HOME to /tmp for container
127
130
  f"{build_container} "
128
131
  f'bash -c "'
129
132
  f"git config --global --add safe.directory '*' 2> /dev/null;"
@@ -141,7 +144,6 @@ def build_board(
141
144
  variant: Optional[str] = None,
142
145
  extra_args: List[str] = [],
143
146
  build_container_override: Optional[str] = None,
144
- idf: Optional[str] = IDF_DEFAULT,
145
147
  mpy_dir: str | Path | None = None,
146
148
  ) -> None:
147
149
  """
@@ -170,10 +172,6 @@ def build_board(
170
172
  print(f"Sorry, builds are not supported for the {port} port at this time")
171
173
  raise SystemExit()
172
174
 
173
- if port != "esp32" and idf != IDF_DEFAULT:
174
- print("An IDF version can only be specified for ESP32 builds")
175
- raise SystemExit()
176
-
177
175
  do_clean = bool(extra_args and extra_args[0].strip() == "clean")
178
176
  build_cmd = docker_build_cmd(
179
177
  board=_board,
@@ -181,7 +179,7 @@ def build_board(
181
179
  extra_args=extra_args,
182
180
  do_clean=do_clean,
183
181
  build_container_override=build_container_override,
184
- idf=idf,
182
+ docker_interactive=sys.stdin.isatty(),
185
183
  )
186
184
 
187
185
  title = "Build" if do_clean else "Clean"
@@ -209,13 +207,11 @@ def build_board(
209
207
  def clean_board(
210
208
  board: str,
211
209
  variant: Optional[str] = None,
212
- idf: Optional[str] = IDF_DEFAULT,
213
210
  mpy_dir: Optional[str] = None,
214
211
  ) -> None:
215
212
  build_board(
216
213
  board=board,
217
214
  variant=variant,
218
215
  mpy_dir=mpy_dir,
219
- idf=idf,
220
216
  extra_args=["clean"],
221
217
  )
@@ -1,4 +1,5 @@
1
1
  from . import board_database
2
+ import json
2
3
 
3
4
  from urllib.request import Request, urlopen
4
5
  from urllib.error import HTTPError
@@ -9,47 +10,64 @@ from rich.panel import Panel
9
10
  from rich.table import Table
10
11
 
11
12
 
12
- def check_images(verbose: bool = False, mpy_dir: str = None) -> None:
13
+ def check_boards(verbose: bool = False, mpy_dir: str = None) -> None:
13
14
  db = board_database(mpy_dir)
14
- # TODO(mst) A minor improvement: Should count the number of images in all
15
- # the boards for each port (this assumes one per board).
16
15
  num_boards = len(db.boards)
17
16
 
18
- # no_images = [("stm32", "fooobar"), ("rp2", "PICO")] # []
19
- # image_not_found = [("stm32", "fooobar", "https://raw.githubusercontent.com/micropython/micropython-media/main/boards/VK_RA6M5/VK-RA6M5.jpg"),
20
- # ("stm32", "fooobar", "https://raw.githubusercontent.com/micropython/micropython-media/main/boards/VK_RA6M5/VK-RA6M5.jpg"),
21
- # ("rp2", "PICO", "https://raw.githubusercontent.com/micropython/micropython-media/main/boards/VK_RA6M5/VK-RA6M5.jpg")] # []
22
- # image_too_large = [("esp32", "GENERIC", "https://raw.githubusercontent.com/micropython/micropython-media/main/boards/VK_RA6M5/VK-RA6M5.jpg", 500_000),
23
- # ("rp2", "PICO", "https://raw.githubusercontent.com/micropython/micropython-media/main/boards/VK_RA6M5/VK-RA6M5.jpg", 400_000)] # []
17
+ # Lists to store issues
24
18
  no_images = []
25
19
  image_not_found = []
26
20
  image_too_large = []
21
+ board_json_issues = []
27
22
 
28
23
  base_url = (
29
24
  r"https://raw.githubusercontent.com/micropython/micropython-media/main/boards"
30
25
  )
26
+
31
27
  with Progress(transient=True) as progress:
32
- task1 = progress.add_task("[cyan]Checking images...", total=num_boards)
28
+ task1 = progress.add_task("[cyan]Checking boards...", total=num_boards)
29
+
30
+ # Check each board
33
31
  for _board in db.boards.values():
32
+ if _board.physical_board:
33
+ # Check board.json file format
34
+ json_path = _board.directory / "board.json"
35
+ try:
36
+ if json_path.exists():
37
+ with open(json_path) as f:
38
+ board_json = json.load(f)
39
+ # Check for issues in board.json
40
+ issues = db.check_board_json(
41
+ board_json, _board.name, _board.port.name
42
+ )
43
+ board_json_issues.extend(issues)
44
+ except (json.JSONDecodeError, IOError) as e:
45
+ board_json_issues.append(
46
+ f"{_board.port.name}/{_board.name}: Error reading board.json: {str(e)}"
47
+ )
48
+
49
+ # Check images
34
50
  image_list = _board.images
35
51
  if len(image_list) == 0:
36
- # No images specified in build.json (should be at least one)
52
+ # No images specified in board.json (should be at least one)
37
53
  no_images.append((_board.port.name, _board.name))
54
+
38
55
  for image in image_list:
39
56
  # Check each image listed in board.json
40
57
  image_url = f"{base_url}/{_board.name}/{image}"
41
58
  req = Request(image_url, method="HEAD")
42
59
  try:
43
60
  f = urlopen(req)
61
+ if f.status == 200:
62
+ # Check size < ~500KB
63
+ image_size = int(f.headers["Content-Length"])
64
+ if image_size > 500_000:
65
+ image_too_large.append(
66
+ (_board.port.name, _board.name, image_url, image_size)
67
+ )
44
68
  except HTTPError:
45
69
  image_not_found.append((_board.port.name, _board.name, image_url))
46
- if f.status == 200:
47
- # Check size < ~500KB
48
- image_size = int(f.headers["Content-Length"])
49
- if image_size > 500_000:
50
- image_too_large.append(
51
- (_board.port.name, _board.name, image_url, image_size)
52
- )
70
+
53
71
  progress.update(task1, advance=1)
54
72
 
55
73
  # Display output
@@ -57,7 +75,8 @@ def check_images(verbose: bool = False, mpy_dir: str = None) -> None:
57
75
  grid.add_column()
58
76
  grid.add_column()
59
77
  grid.add_column()
60
- grid.add_row(
78
+
79
+ first_row = [
61
80
  Panel(
62
81
  "\n".join([f"{p}/[bright_white]{b}[/]" for p, b in no_images]),
63
82
  title="No images",
@@ -83,5 +102,23 @@ def check_images(verbose: bool = False, mpy_dir: str = None) -> None:
83
102
  title="Too large",
84
103
  subtitle="Image > 500KB",
85
104
  ),
86
- )
105
+ ]
106
+
107
+ grid.add_row(*first_row)
108
+
109
+ # Add board.json issues panel if there are any
110
+ if board_json_issues:
111
+ json_panel = Panel(
112
+ "\n".join(board_json_issues),
113
+ title="board.json issues",
114
+ subtitle="Missing or invalid keys",
115
+ )
116
+ grid.add_row(json_panel)
117
+
87
118
  print(grid)
119
+
120
+
121
+ # Backwards compatibility
122
+ def check_images(verbose: bool = False, mpy_dir: str = None) -> None:
123
+ """Legacy function, redirects to check_boards"""
124
+ check_boards(verbose, mpy_dir)
@@ -4,9 +4,9 @@ from typing_extensions import Annotated
4
4
  import typer
5
5
 
6
6
  from . import __app_name__, __version__, OutputFormat
7
- from .build import build_board, clean_board, IDF_DEFAULT
7
+ from .build import build_board, clean_board
8
8
  from .list_boards import print_boards
9
- from .check_images import check_images
9
+ from .check_images import check_boards
10
10
  from .completions import list_ports, list_boards, list_variants_for_board
11
11
 
12
12
  app = typer.Typer(chain=True, context_settings={"help_option_names": ["-h", "--help"]})
@@ -42,10 +42,6 @@ def build(
42
42
  Optional[str],
43
43
  typer.Argument(help="Board variant", autocompletion=_complete_variant),
44
44
  ] = None,
45
- idf: Annotated[
46
- Optional[str],
47
- typer.Option(help="esp32 port only: select IDF version to build with"),
48
- ] = IDF_DEFAULT,
49
45
  extra_args: Annotated[
50
46
  Optional[List[str]], typer.Argument(help="additional arguments to pass to make")
51
47
  ] = None,
@@ -57,7 +53,9 @@ def build(
57
53
  """
58
54
  Build a MicroPython board.
59
55
  """
60
- build_board(board, variant, extra_args or [], build_container, idf)
56
+ if variant == "":
57
+ variant = None
58
+ build_board(board, variant, extra_args or [], build_container)
61
59
 
62
60
 
63
61
  @app.command()
@@ -88,14 +86,25 @@ def list_boards_and_variants(
88
86
  print_boards(port, fmt)
89
87
 
90
88
 
91
- @app.command("check_images")
89
+ @app.command("check_boards")
90
+ def board_check(
91
+ verbose: Annotated[bool, typer.Option(help="More verbose output")] = False,
92
+ ) -> None:
93
+ """
94
+ Check boards for issues with board.json files and images
95
+ """
96
+ check_boards(verbose)
97
+
98
+
99
+ # Keep old command for backwards compatibility
100
+ @app.command("check_images", hidden=True)
92
101
  def image_check(
93
102
  verbose: Annotated[bool, typer.Option(help="More verbose output")] = False,
94
103
  ) -> None:
95
104
  """
96
- Check images
105
+ Check images (deprecated, use check_boards instead)
97
106
  """
98
- check_images(verbose)
107
+ check_boards(verbose)
99
108
 
100
109
 
101
110
  def _version_callback(value: bool) -> None: