mpbuild 0.9__tar.gz → 1.0.0__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 (38) hide show
  1. mpbuild-1.0.0/.github/workflows/test.yml +69 -0
  2. {mpbuild-0.9 → mpbuild-1.0.0}/.gitignore +6 -0
  3. mpbuild-1.0.0/.pre-commit-config.yaml +32 -0
  4. {mpbuild-0.9 → mpbuild-1.0.0}/PKG-INFO +60 -1
  5. {mpbuild-0.9 → mpbuild-1.0.0}/README.md +58 -0
  6. mpbuild-1.0.0/docs/mpbuild_interactive_screenshot.png +0 -0
  7. {mpbuild-0.9 → mpbuild-1.0.0}/pyproject.toml +22 -1
  8. {mpbuild-0.9 → mpbuild-1.0.0}/src/mpbuild/__init__.py +5 -4
  9. {mpbuild-0.9 → mpbuild-1.0.0}/src/mpbuild/__main__.py +1 -1
  10. {mpbuild-0.9 → mpbuild-1.0.0}/src/mpbuild/board_database.py +11 -20
  11. mpbuild-1.0.0/src/mpbuild/build.py +438 -0
  12. {mpbuild-0.9 → mpbuild-1.0.0}/src/mpbuild/check_images.py +11 -21
  13. {mpbuild-0.9 → mpbuild-1.0.0}/src/mpbuild/cli.py +55 -20
  14. {mpbuild-0.9 → mpbuild-1.0.0}/src/mpbuild/find_boards.py +2 -2
  15. mpbuild-1.0.0/src/mpbuild/interactive.py +316 -0
  16. mpbuild-1.0.0/src/mpbuild/interactive.tcss +66 -0
  17. {mpbuild-0.9 → mpbuild-1.0.0}/src/mpbuild/list_boards.py +6 -9
  18. mpbuild-1.0.0/tests/__init__.py +0 -0
  19. mpbuild-1.0.0/tests/conftest.py +79 -0
  20. mpbuild-1.0.0/tests/test_board_database.py +318 -0
  21. mpbuild-1.0.0/tests/test_build_container.py +148 -0
  22. mpbuild-1.0.0/tests/test_cli.py +273 -0
  23. mpbuild-1.0.0/tests/test_detect_idf_version.py +165 -0
  24. mpbuild-1.0.0/tests/test_docker_build_cmd.py +185 -0
  25. mpbuild-1.0.0/tests/test_find_boards.py +59 -0
  26. mpbuild-1.0.0/tests/test_interactive.py +386 -0
  27. mpbuild-1.0.0/tests/test_worktrees.py +74 -0
  28. mpbuild-1.0.0/uv.lock +505 -0
  29. mpbuild-0.9/.pre-commit-config.yaml +0 -20
  30. mpbuild-0.9/src/mpbuild/build.py +0 -217
  31. mpbuild-0.9/src/mpbuild/interactive.py +0 -273
  32. mpbuild-0.9/uv.lock +0 -260
  33. {mpbuild-0.9 → mpbuild-1.0.0}/.python-version +0 -0
  34. {mpbuild-0.9 → mpbuild-1.0.0}/LICENSE +0 -0
  35. {mpbuild-0.9 → mpbuild-1.0.0}/requirements-dev.lock +0 -0
  36. {mpbuild-0.9 → mpbuild-1.0.0}/requirements.lock +0 -0
  37. {mpbuild-0.9 → mpbuild-1.0.0}/src/mpbuild/completions.py +0 -0
  38. {mpbuild-0.9 → mpbuild-1.0.0}/src/mpbuild/py.typed +0 -0
@@ -0,0 +1,69 @@
1
+ name: test
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ concurrency:
10
+ group: ${{ github.workflow }}-${{ github.ref }}
11
+ cancel-in-progress: true
12
+
13
+ jobs:
14
+ test:
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Install uv
20
+ uses: astral-sh/setup-uv@v6
21
+ with:
22
+ python-version: "3.12"
23
+ enable-cache: true
24
+
25
+ - name: Install dev dependencies
26
+ run: uv sync --group dev
27
+
28
+ - name: Run tests
29
+ run: uv run pytest --cov=mpbuild --cov-report=term-missing
30
+
31
+ lint:
32
+ runs-on: ubuntu-latest
33
+ steps:
34
+ - uses: actions/checkout@v4
35
+
36
+ - name: Install uv
37
+ uses: astral-sh/setup-uv@v6
38
+ with:
39
+ python-version: "3.12"
40
+ enable-cache: true
41
+
42
+ - name: Install dev dependencies
43
+ run: uv sync --group dev
44
+
45
+ - name: Ruff lint
46
+ run: uv run ruff check
47
+
48
+ - name: Ruff format check
49
+ run: uv run ruff format --check
50
+
51
+ typecheck:
52
+ runs-on: ubuntu-latest
53
+ # ty is in active development; warn-only initially. Drop continue-on-error
54
+ # once we trust the output and want it gating merges.
55
+ continue-on-error: true
56
+ steps:
57
+ - uses: actions/checkout@v4
58
+
59
+ - name: Install uv
60
+ uses: astral-sh/setup-uv@v6
61
+ with:
62
+ python-version: "3.12"
63
+ enable-cache: true
64
+
65
+ - name: Install dev dependencies
66
+ run: uv sync --group dev
67
+
68
+ - name: ty check
69
+ run: uv run ty check
@@ -8,3 +8,9 @@ wheels/
8
8
 
9
9
  # venv
10
10
  .venv
11
+
12
+ # test artifacts
13
+ .coverage
14
+ .coverage.*
15
+ htmlcov/
16
+ .pytest_cache/
@@ -0,0 +1,32 @@
1
+ # See https://pre-commit.com for more information
2
+ # See https://pre-commit.com/hooks.html for more hooks
3
+ repos:
4
+ - repo: https://github.com/pre-commit/pre-commit-hooks
5
+ rev: v5.0.0
6
+ hooks:
7
+ - id: trailing-whitespace
8
+ - id: end-of-file-fixer
9
+ - id: check-yaml
10
+ - id: check-added-large-files
11
+
12
+ - repo: https://github.com/astral-sh/ruff-pre-commit
13
+ # Ruff version. Keep in sync with the ruff entry in pyproject.toml's dev group.
14
+ rev: v0.15.12
15
+ hooks:
16
+ # Run the linter.
17
+ - id: ruff-check
18
+ args: [ --fix ]
19
+ # Run the formatter.
20
+ - id: ruff-format
21
+
22
+ # ty (Astral type checker) is invoked via the local uv environment because
23
+ # astral-sh/ty-pre-commit does not yet exist. Switch to the upstream hook
24
+ # repo when it ships.
25
+ - repo: local
26
+ hooks:
27
+ - id: ty
28
+ name: ty
29
+ entry: uv run ty check
30
+ language: system
31
+ pass_filenames: false
32
+ types: [python]
@@ -1,11 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mpbuild
3
- Version: 0.9
3
+ Version: 1.0.0
4
4
  Summary: Build MicroPython firmware with ease!
5
5
  Author-email: Matt Trentini <matt.trentini@gmail.com>
6
6
  License-File: LICENSE
7
7
  Requires-Python: >=3.12
8
8
  Requires-Dist: rich>=13.7.1
9
+ Requires-Dist: textual>=8.2.4
9
10
  Requires-Dist: typer>=0.12.3
10
11
  Description-Content-Type: text/markdown
11
12
 
@@ -24,11 +25,13 @@ Build MicroPython firmware with ease!
24
25
  ## Table of Contents
25
26
 
26
27
  - [Usage](#usage)
28
+ - [Interactive mode](#interactive-mode)
27
29
  - [Advanced Usage](#advanced-usage)
28
30
  - [Use as a Module](#use-as-a-module)
29
31
  - [Installation](#installation)
30
32
  - [Prerequisites](#prerequisites)
31
33
  - [Examples](#examples)
34
+ - [Testing](#testing)
32
35
  - [Related links](#related-links)
33
36
 
34
37
  ## Usage
@@ -53,6 +56,12 @@ Remove build artifacts:
53
56
  mpbuild clean BOARD [VARIANT]
54
57
  ```
55
58
 
59
+ Clean and then build a board (rebuild from scratch):
60
+
61
+ ```bash
62
+ mpbuild rebuild BOARD [VARIANT]
63
+ ```
64
+
56
65
  List the available boards, optionally filter by the port name.
57
66
 
58
67
  Displays the board names (as a clickable link), variants and number of boards per port:
@@ -61,6 +70,34 @@ Displays the board names (as a clickable link), variants and number of boards pe
61
70
  mpbuild list [PORT]
62
71
  ```
63
72
 
73
+ ## Interactive mode
74
+
75
+ For exploring boards and triggering builds without typing the names, **mpbuild** ships with a Textual TUI:
76
+
77
+ ```bash
78
+ mpbuild --interactive # or `mpbuild -i`
79
+ ```
80
+
81
+ ![Interactive TUI screenshot](docs/mpbuild_interactive_screenshot.png)
82
+
83
+ The left pane shows every port and board found in the MicroPython tree. Selecting a board fills the right pane with its metadata, reveals a variant dropdown if the board has variants, and enables the Build / Rebuild / Clean buttons. The bottom-right log streams docker output as the build runs.
84
+
85
+ Key bindings:
86
+
87
+ | Key | Action |
88
+ |---|---|
89
+ | `↑` / `↓` | Navigate the tree |
90
+ | `→` | Expand the current branch |
91
+ | `←` | Collapse the current branch (or, on a leaf, collapse the parent) |
92
+ | `Enter` | Select |
93
+ | `b` | Build the selected board |
94
+ | `r` | Rebuild the selected board (clean then build) |
95
+ | `c` | Clean the selected board |
96
+ | `s` | Stop the running build |
97
+ | `q` | Quit |
98
+
99
+ Clicking **Build**, **Rebuild**, or **Clean** while a build is already running terminates the running container before starting the new one. **Stop** is enabled only while a build is actually streaming.
100
+
64
101
  ## Advanced Usage
65
102
 
66
103
  Validate the state of all images referenced in board definitions:
@@ -140,3 +177,25 @@ $ mpbuild list rp2
140
177
  ├── W5500_EVB_PICO
141
178
  └── WEACTSTUDIO FLASH_2M, FLASH_4M, FLASH_8M
142
179
  ```
180
+
181
+ ## Testing
182
+
183
+ The test suite uses [pytest](https://docs.pytest.org/). Dev dependencies are declared in the `dev` group of `pyproject.toml`.
184
+
185
+ Install dev dependencies:
186
+
187
+ ```bash
188
+ uv sync --group dev
189
+ ```
190
+
191
+ Run the tests:
192
+
193
+ ```bash
194
+ uv run pytest
195
+ ```
196
+
197
+ Run with coverage:
198
+
199
+ ```bash
200
+ uv run pytest --cov=mpbuild --cov-report=term-missing
201
+ ```
@@ -13,11 +13,13 @@ Build MicroPython firmware with ease!
13
13
  ## Table of Contents
14
14
 
15
15
  - [Usage](#usage)
16
+ - [Interactive mode](#interactive-mode)
16
17
  - [Advanced Usage](#advanced-usage)
17
18
  - [Use as a Module](#use-as-a-module)
18
19
  - [Installation](#installation)
19
20
  - [Prerequisites](#prerequisites)
20
21
  - [Examples](#examples)
22
+ - [Testing](#testing)
21
23
  - [Related links](#related-links)
22
24
 
23
25
  ## Usage
@@ -42,6 +44,12 @@ Remove build artifacts:
42
44
  mpbuild clean BOARD [VARIANT]
43
45
  ```
44
46
 
47
+ Clean and then build a board (rebuild from scratch):
48
+
49
+ ```bash
50
+ mpbuild rebuild BOARD [VARIANT]
51
+ ```
52
+
45
53
  List the available boards, optionally filter by the port name.
46
54
 
47
55
  Displays the board names (as a clickable link), variants and number of boards per port:
@@ -50,6 +58,34 @@ Displays the board names (as a clickable link), variants and number of boards pe
50
58
  mpbuild list [PORT]
51
59
  ```
52
60
 
61
+ ## Interactive mode
62
+
63
+ For exploring boards and triggering builds without typing the names, **mpbuild** ships with a Textual TUI:
64
+
65
+ ```bash
66
+ mpbuild --interactive # or `mpbuild -i`
67
+ ```
68
+
69
+ ![Interactive TUI screenshot](docs/mpbuild_interactive_screenshot.png)
70
+
71
+ The left pane shows every port and board found in the MicroPython tree. Selecting a board fills the right pane with its metadata, reveals a variant dropdown if the board has variants, and enables the Build / Rebuild / Clean buttons. The bottom-right log streams docker output as the build runs.
72
+
73
+ Key bindings:
74
+
75
+ | Key | Action |
76
+ |---|---|
77
+ | `↑` / `↓` | Navigate the tree |
78
+ | `→` | Expand the current branch |
79
+ | `←` | Collapse the current branch (or, on a leaf, collapse the parent) |
80
+ | `Enter` | Select |
81
+ | `b` | Build the selected board |
82
+ | `r` | Rebuild the selected board (clean then build) |
83
+ | `c` | Clean the selected board |
84
+ | `s` | Stop the running build |
85
+ | `q` | Quit |
86
+
87
+ Clicking **Build**, **Rebuild**, or **Clean** while a build is already running terminates the running container before starting the new one. **Stop** is enabled only while a build is actually streaming.
88
+
53
89
  ## Advanced Usage
54
90
 
55
91
  Validate the state of all images referenced in board definitions:
@@ -129,3 +165,25 @@ $ mpbuild list rp2
129
165
  ├── W5500_EVB_PICO
130
166
  └── WEACTSTUDIO FLASH_2M, FLASH_4M, FLASH_8M
131
167
  ```
168
+
169
+ ## Testing
170
+
171
+ The test suite uses [pytest](https://docs.pytest.org/). Dev dependencies are declared in the `dev` group of `pyproject.toml`.
172
+
173
+ Install dev dependencies:
174
+
175
+ ```bash
176
+ uv sync --group dev
177
+ ```
178
+
179
+ Run the tests:
180
+
181
+ ```bash
182
+ uv run pytest
183
+ ```
184
+
185
+ Run with coverage:
186
+
187
+ ```bash
188
+ uv run pytest --cov=mpbuild --cov-report=term-missing
189
+ ```
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mpbuild"
3
- version = "0.9"
3
+ version = "1.0.0"
4
4
  description = "Build MicroPython firmware with ease!"
5
5
  authors = [
6
6
  { name = "Matt Trentini", email = "matt.trentini@gmail.com" }
@@ -8,6 +8,7 @@ authors = [
8
8
  dependencies = [
9
9
  "typer>=0.12.3",
10
10
  "rich>=13.7.1",
11
+ "textual>=8.2.4",
11
12
  ]
12
13
  readme = "README.md"
13
14
  requires-python = ">= 3.12"
@@ -33,4 +34,24 @@ packages = ["src/mpbuild"]
33
34
  [dependency-groups]
34
35
  dev = [
35
36
  "pre-commit>=4.0.1",
37
+ "pytest>=8",
38
+ "pytest-asyncio>=0.24",
39
+ "pytest-cov>=5",
40
+ "ruff>=0.13",
41
+ "ty>=0.0.32",
36
42
  ]
43
+
44
+ [tool.pytest.ini_options]
45
+ testpaths = ["tests"]
46
+ addopts = "-ra"
47
+
48
+ [tool.coverage.run]
49
+ source = ["src/mpbuild"]
50
+ omit = ["src/mpbuild/__main__.py"]
51
+
52
+ [tool.ruff]
53
+ line-length = 100
54
+ target-version = "py312"
55
+
56
+ [tool.ruff.lint]
57
+ select = ["E", "F", "I", "UP", "B"]
@@ -1,11 +1,12 @@
1
1
  __app_name__ = "mpbuild"
2
- __version__ = "0.1.0"
2
+ __version__ = "1.0.0"
3
3
 
4
- from enum import Enum
4
+ from enum import StrEnum
5
5
  from functools import cache
6
6
  from pathlib import Path
7
- from .find_boards import find_mpy_root
7
+
8
8
  from .board_database import Database
9
+ from .find_boards import find_mpy_root
9
10
 
10
11
 
11
12
  @cache
@@ -16,6 +17,6 @@ def board_database(mpy_dir: Path | None = None, port: str | None = None) -> Data
16
17
  return Database(mpy_dir, port)
17
18
 
18
19
 
19
- class OutputFormat(str, Enum):
20
+ class OutputFormat(StrEnum):
20
21
  rich = "rich"
21
22
  text = "text"
@@ -1,4 +1,4 @@
1
- from . import cli, __app_name__
1
+ from . import __app_name__, cli
2
2
 
3
3
 
4
4
  def main():
@@ -120,12 +120,7 @@ class Board:
120
120
  port=port,
121
121
  )
122
122
  board.variants.extend(
123
- sorted(
124
- [
125
- Variant(*v, board=board)
126
- for v in board_json.get("variants", {}).items()
127
- ]
128
- )
123
+ sorted([Variant(*v, board=board) for v in board_json.get("variants", {}).items()])
129
124
  )
130
125
  return board
131
126
 
@@ -143,11 +138,11 @@ class Board:
143
138
  return directory_
144
139
 
145
140
  @property
146
- def deploy_filename(self) -> Path:
141
+ def deploy_filename(self) -> Path | None:
147
142
  """
148
- Returns the filename of the deploy-markdown.
143
+ Returns the filename of the deploy-markdown, or None.
149
144
  """
150
- return self.directory / self.deploy[0]
145
+ return self.directory / self.deploy[0] if self.deploy else None
151
146
 
152
147
  # TODO(mst): Update Variant to allow comparisons to strings. This method can
153
148
  # then be removed.
@@ -160,7 +155,8 @@ class Board:
160
155
  if v.name == variant:
161
156
  return v
162
157
  print(
163
- f"Variant '{variant}' not found for board '{self.name}': Valid variants are: {[v.name for v in self.variants]}"
158
+ f"Variant '{variant}' not found for board '{self.name}': "
159
+ f"Valid variants are: {[v.name for v in self.variants]}"
164
160
  )
165
161
 
166
162
  return None
@@ -207,7 +203,8 @@ class Database:
207
203
  def __post_init__(self) -> None:
208
204
  if not (self.mpy_root_directory / "ports").is_dir():
209
205
  raise ValueError(
210
- f"'mpy_root_directory' should point to the top of a MicroPython repo: {self.mpy_root_directory}"
206
+ "'mpy_root_directory' should point to the top of a MicroPython "
207
+ f"repo: {self.mpy_root_directory}"
211
208
  )
212
209
 
213
210
  # Take care to avoid using Path.glob! Performance was 15x slower.
@@ -236,9 +233,7 @@ class Database:
236
233
  if self.port_filter and self.port_filter != special_port_name:
237
234
  continue
238
235
  path = self.mpy_root_directory / "ports" / special_port_name
239
- variant_names = [
240
- var.name for var in path.glob("variants/*") if var.is_dir()
241
- ]
236
+ variant_names = [var.name for var in path.glob("variants/*") if var.is_dir()]
242
237
  port = Port(
243
238
  name=special_port_name,
244
239
  directory=path,
@@ -256,9 +251,7 @@ class Database:
256
251
  port=port,
257
252
  )
258
253
  port.boards = {special_port_name: board}
259
- board.variants = [
260
- Variant(name=v, text="", board=board) for v in variant_names
261
- ]
254
+ board.variants = [Variant(name=v, text="", board=board) for v in variant_names]
262
255
  self.ports[special_port_name] = port
263
256
  self.boards[board.name] = board
264
257
 
@@ -273,9 +266,7 @@ class Database:
273
266
  )
274
267
 
275
268
  @staticmethod
276
- def check_board_json(
277
- board_json: dict, board_name: str, port_name: str
278
- ) -> list[str]:
269
+ def check_board_json(board_json: dict, board_name: str, port_name: str) -> list[str]:
279
270
  """
280
271
  Checks a board.json file for missing or invalid keys.
281
272
  Returns a list of issues found.