Update build process to use mpy-cross

This commit is contained in:
Kai Vogelgesang 2025-07-07 15:51:37 +02:00
parent 6aa2d756c6
commit d1199575ff
Signed by: kai
GPG Key ID: 3FC8578CC818A9EB
4 changed files with 57 additions and 7 deletions

1
pico/.gitignore vendored
View File

@ -1,3 +1,4 @@
build
.venv
typings
src/secret.py

View File

@ -1,6 +1,27 @@
SRC_DIR := src
BUILD_DIR := build
SRC_FILES := $(wildcard $(SRC_DIR)/*.py) $(wildcard $(SRC_DIR)/**/*.py)
BUILD_FILES := $(patsubst $(SRC_DIR)/%.py,$(BUILD_DIR)/%.mpy, $(SRC_FILES))
$(BUILD_DIR)/%.mpy: $(SRC_DIR)/%.py
@mkdir -p `dirname $@`
mpy-cross $< -o $@
.PHONY: build
build: $(BUILD_FILES)
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
.PHONY: deploy
deploy:
mpremote fs cp src/* :
deploy: $(BUILD_FILES)
mpremote fs cp -r $(BUILD_DIR)/* :
.PHONY: purge
purge:
mpremote run purge.py
.PHONY: run
run: deploy

View File

@ -1,6 +1,20 @@
# Setup:
```
$ python -m venv .venv
$ source .venv/bin/activate
$ pip install -U micropython-rp2-pico_w-stubs --no-user --target typings
```
1. Set up the virtual environment:
```
$ python -m venv .venv
$ source .venv/bin/activate
```
2. Install the type stubs:
```
$ pip install -U micropython-rp2-pico_w-stubs --no-user --target typings
```
3. Ensure `mpy-cross` is available:
```
$ git clone https://github.com/micropython/micropython.git /tmp/micropython
$ pushd /tmp/micropython/mpy-cross
$ make
$ mv build/mpy-cross ~/.local/bin/
$ popd
```

14
pico/purge.py Normal file
View File

@ -0,0 +1,14 @@
import os
def rm(p: str, cwd: str = "/"):
path = cwd+p
print(f"rm {path=}")
try:
os.unlink(path)
except OSError:
for f in os.listdir(path): # pyright: ignore[reportAny]
rm(f, path+"/") # pyright: ignore[reportAny]
os.unlink(path)
for f in os.listdir(): # pyright: ignore[reportAny]
rm(f) # pyright: ignore[reportAny]