-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
84 lines (66 loc) · 2.92 KB
/
Copy pathmakefile
File metadata and controls
84 lines (66 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# ScrollKit library — build, test, lint, and device deploy.
SRC_DIR := src
# Mounted CIRCUITPY drive (override on the command line if it mounts elsewhere).
CIRCUITPY := /Volumes/CIRCUITPY
PYTHON := python
PIP := python -m pip
# PYTHONSAFEPATH keeps the CWD off sys.path; PYTHONPATH=src exposes `scrollkit`.
PYTEST := PYTHONSAFEPATH=1 PYTHONPATH=$(SRC_DIR) $(PYTHON) -m pytest
.PHONY: all test test-unit test-all test-coverage lint lint-errors test-with-lint \
format clean mpy copy-to-circuitpy \
install-test-deps install-dev-deps install-lint-deps
all: test
# --- Testing ---------------------------------------------------------------
test: test-unit
test-unit:
$(PYTEST) test/unit -v
test-all:
$(PYTEST)
test-coverage:
$(PYTEST) --cov=scrollkit --cov-report=term --cov-report=html
# --- Linting / formatting --------------------------------------------------
lint:
@echo "Running Python linter (ruff)..."
$(PYTHON) -m ruff check $(SRC_DIR) test/ --fix
@echo "Linting complete!"
lint-errors:
@echo "Checking for critical errors..."
$(PYTHON) -m ruff check $(SRC_DIR) --select=E9,F63,F7,F82,F821 --no-fix
@echo "Critical error check complete!"
test-with-lint: lint-errors test
format:
$(PYTHON) -m ruff format $(SRC_DIR) test/
# --- Dependencies ----------------------------------------------------------
install-test-deps:
$(PIP) install pytest pytest-asyncio pytest-cov
install-dev-deps:
$(PIP) install pygame pillow numpy
install-lint-deps:
$(PIP) install ruff
# --- Device deploy ---------------------------------------------------------
# Copy the library to a connected MatrixPortal S3 (CIRCUITPY/lib/scrollkit).
# An application's own code.py/boot.py live in the app, not in this repo.
copy-to-circuitpy: lint-errors
@test -d "$(CIRCUITPY)" || { echo "CIRCUITPY not mounted at $(CIRCUITPY)"; exit 1; }
rsync -av --update --progress \
--exclude='__pycache__' --exclude='*.pyc' --exclude='.DS_Store' \
$(SRC_DIR)/scrollkit/ "$(CIRCUITPY)/lib/scrollkit/"
# Cross-compile scrollkit to .mpy (smaller RAM + faster boot on device).
# Requires mpy-cross matching your CircuitPython version: pip install mpy-cross
MPY_CROSS := mpy-cross
mpy:
@command -v $(MPY_CROSS) >/dev/null 2>&1 || { echo "mpy-cross not found. Install one matching your CircuitPython version: pip install mpy-cross"; exit 1; }
@echo "Compiling src/scrollkit -> build/scrollkit (.mpy)..."
@rm -rf build/scrollkit
@find src/scrollkit -name '*.py' | while read f; do \
out="build/$${f#src/}"; out="$${out%.py}.mpy"; \
mkdir -p "$$(dirname "$$out")"; \
$(MPY_CROSS) "$$f" -o "$$out" || exit 1; \
done
@echo "Done -> build/scrollkit/. Copy it to the device (e.g. CIRCUITPY/lib/scrollkit)."
# --- Housekeeping ----------------------------------------------------------
clean:
find . -type d -name "__pycache__" -exec rm -rf {} +
find . -type f -name "*.pyc" -delete
find . -type f -name ".DS_Store" -delete
rm -rf .pytest_cache htmlcov .coverage build