tee-timer/Makefile
Laborratte5 e5c6ff32f2
build: clear jupyter notebook outputs on clean task
- Clear jupyter notebook output on clean target
- Clear jupyter notebook run counter on clean target
- Fix: Deletion of lib/ if lib/ does not exist
2024-05-04 21:28:24 +02:00

93 lines
2.5 KiB
Makefile

VENV = poetry run
ESP_TOOL = $(VENV) esptool.py --port $(ESP_PORT)
MPYCROSS = $(VENV) mpy-cross
AMPY = $(VENV) ampy --port $(ESP_PORT)
JUPYTER_PYTHON_FILES = $(shell find src/*.ipynb | sed "s/ipynb/py/g")
# Downloaded from https://micropython.org/download/ESP8266_GENERIC/
MICRO_PYTHON_FIRMWARE = ESP8266_GENERIC-20240222-v1.22.2.bin
ESP_PORT = /dev/ttyUSB0
src/%.py: src/%.ipynb
$(VENV) jupyter nbconvert --to python $? \
--TagRemovePreprocessor.enabled=True \
--TagRemovePreprocessor.remove_cell_tags remove_cell
src/%.mpy: src/%.py
@for f in $(filter-out src/main.py,$?); do \
echo Compile $$f; \
$(MPYCROSS) $$f; \
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/
compile_lib: lib/
@for f in $(shell find lib/ -type f -regex ".+\.py"); do \
echo Compile $$f; \
$(MPYCROSS) $$f; \
done
install_lib: compile_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
$(VENV) python3 -m py_compile src/*.py
erase_flash:
$(ESP_TOOL) erase_flash
flash_esp: erase_flash
$(ESP_TOOL) --baud 460800 write_flash --flash_size=detect 0 $(MICRO_PYTHON_FIRMWARE)
install: check install_lib $(JUPYTER_PYTHON_FILES)
$(AMPY) put src/main.py
@for f in $(filter-out check install_lib,$?); do \
echo Uploading $$f; \
$(AMPY) put $$f; \
done
ifeq ($(MAKELEVEL),0)
uninstall:
@echo $(filter-out /boot.py,$(shell $(AMPY) ls --recursive))
for f in $(filter-out /boot.py,$(shell $(AMPY) ls --recursive)); do \
echo Deleting file $$f; \
$(AMPY) rm $$f; \
done
$(MAKE) uninstall
else
uninstall:
@echo $(filter-out /boot.py,$(shell $(AMPY) ls --recursive))
for f in $(filter-out /boot.py,$(shell $(AMPY) ls)); do \
echo Deleting directory $$f; \
$(AMPY) rmdir $$f; \
done
endif
clean:
rm -rf src/__pycache__
rm -f src/*.pyc
rm -f src/*.mpy
rm -f $(JUPYTER_PYTHON_FILES)
rm -rf lib/
rm -f requirements.txt
$(VENV) jupyter nbconvert --clear-output --inplace src/*.ipynb
env:
poetry install
$(VENV) python -m jupyter_micropython_kernel.install
.PHONY: check erase_flash flash_esp install uninstall clean env compile_lib install_lib lib_tree