Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
83 lines (69 loc) · 2.55 KB
/
Copy pathMakefile
File metadata and controls
83 lines (69 loc) · 2.55 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
# Python_educator - one command runs everything.
#
# make install dev tools, then lint, type-check, test and run
# make lint ruff check
# make format ruff format
# make types mypy --strict
# make test pytest
# make run execute every lesson, exercise and project
# make lesson-09 run one lesson by number
# make check lint + types + test + run (exactly what CI does)
# make clean remove caches and generated data files
#
# Nothing here is optional: the same checks run locally and in CI.
PY ?= python
.PHONY: all install lint format format-check types test run check clean help
.DEFAULT_GOAL := check
all: check
install:
$(PY) -m pip install --upgrade pip
$(PY) -m pip install -e ".[dev]"
lint:
@echo "== ruff check =="
@$(PY) -m ruff check .
format:
@$(PY) -m ruff format .
format-check:
@echo "== ruff format --check =="
@$(PY) -m ruff format --check .
types:
@echo "== mypy --strict =="
@$(PY) -m mypy .
test:
@echo "== pytest =="
@$(PY) -m pytest
# Every lesson, exercise and project must run standalone and exit 0.
# coursework/ is excluded: those are the author's original class files.
run:
@echo "== running every program =="
@failed=0; count=0; \
for f in $$(find lessons practice projects -name '*.py' \
! -name '__init__.py' ! -path '*/textkit/*' | sort); do \
count=$$((count+1)); \
( cd $$(dirname $$f) && $(PY) $$(basename $$f) >/dev/null 2>&1 ) \
|| { echo " FAIL $$f"; failed=1; }; \
done; \
if [ $$failed -eq 0 ]; then echo " all $$count programs exited 0"; \
else echo " some programs failed"; exit 1; fi
lesson-%:
@d=$$(echo lessons/$**/ | cut -d' ' -f1); \
f=$$(find $$d -maxdepth 1 -name '*.py' ! -name '__init__.py' | head -1); \
echo "== $$f =="; ( cd $$(dirname $$f) && $(PY) $$(basename $$f) )
check: lint format-check types test run
@echo ""
@echo " lint, types, tests and every program: all clean."
clean:
@rm -rf .pytest_cache .mypy_cache .ruff_cache
@find . -type d -name __pycache__ -prune -exec rm -rf {} + 2>/dev/null || true
@rm -f projects/02-todo-cli/todo.json projects/02-todo-cli/todo_demo.json
@rm -f lessons/15-files-and-context-managers/demo_*
@echo " cleaned"
help:
@echo "make check lint + types + tests + run everything (what CI does)"
@echo "make lint ruff check"
@echo "make format ruff format"
@echo "make types mypy --strict"
@echo "make test pytest"
@echo "make run execute every program"
@echo "make lesson-09 run lesson 09"
@echo "make clean remove caches and generated files"