build: Add target to install libraries on esp8266

This commit is contained in:
Laborratte5 2024-05-04 11:55:21 +02:00
parent 53dee4d268
commit 5048b578ff
Signed by: Laborratte5
GPG key ID: 3A30072E35202C02
2 changed files with 34 additions and 3 deletions

2
.gitignore vendored
View file

@ -3,3 +3,5 @@
!main.py !main.py
.ipynb_checkpoints .ipynb_checkpoints
__pycache__ __pycache__
lib/
requirements.txt

View file

@ -19,6 +19,33 @@ src/%.mpy: src/%.py
$(MPYCROSS) $$f; \ $(MPYCROSS) $$f; \
done done
requirements.txt: poetry.lock
poetry export --without dev --output requirements.txt
lib/: requirements.txt
$(VENV) python -m pip install -r requirements.txt --target lib/
$(MAKE) compile_lib
$(MAKE) install_lib
compile_lib:
@for f in $(shell find lib/ -type f -regex ".+\.py"); do \
echo Compile $$f; \
$(MPYCROSS) $$f; \
done
install_lib: lib_tree
@for f in $(shell find lib/ -type f -regex ".+\.mpy"); do \
echo Uploading $$f; \
$(AMPY) put $$f $$f; \
done
AWK_SCRIPT = { for (i = 1; i < NF; i++) { for (j = 1; j <= i; j++) { printf "/%s",$$j } printf "\n" } }
lib_tree:
@for d in $(shell find lib/ -regex ".+\.mpy" | awk -F/ '$(AWK_SCRIPT)'); do \
echo Create $$d; \
$(AMPY) mkdir --exists-okay $$d; \
done
check: src/*.mpy check: src/*.mpy
$(VENV) python3 -m py_compile src/*.py $(VENV) python3 -m py_compile src/*.py
@ -28,9 +55,9 @@ erase_flash:
flash_esp: erase_flash flash_esp: erase_flash
$(ESP_TOOL) --baud 460800 write_flash --flash_size=detect 0 $(MICRO_PYTHON_FIRMWARE) $(ESP_TOOL) --baud 460800 write_flash --flash_size=detect 0 $(MICRO_PYTHON_FIRMWARE)
install: check $(JUPYTER_PYTHON_FILES) install: check lib/ $(JUPYTER_PYTHON_FILES)
$(AMPY) put src/main.py $(AMPY) put src/main.py
@for f in $(filter-out check,$?); do \ @for f in $(filter-out check lib/,$?); do \
echo Uploading $$f; \ echo Uploading $$f; \
$(AMPY) put $$f; \ $(AMPY) put $$f; \
done done
@ -57,9 +84,11 @@ clean:
rm -f src/*.pyc rm -f src/*.pyc
rm -f src/*.mpy rm -f src/*.mpy
rm -f $(JUPYTER_PYTHON_FILES) rm -f $(JUPYTER_PYTHON_FILES)
rm -r lib/
rm -f requirements.txt
env: env:
poetry install poetry install
$(VENV) python -m jupyter_micropython_kernel.install $(VENV) python -m jupyter_micropython_kernel.install
.PHONY: check erase_flash flash_esp install uninstall clean env .PHONY: check erase_flash flash_esp install uninstall clean env compile_lib install_lib lib_tree