summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 6d804a135402f30d27908d5109eef2609ff2af0b (plain)
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
# Development tasks. Everything runs through `uv`, so there is nothing to
# install first and no virtualenv to activate by hand.
#
#   make            list the targets
#   make test       run the suite on PYTHON (default: the minimum supported)
#   make lint       ruff check + format check, no files touched
#   make build      wheel + sdist into dist/
#
# PYTHON pins the interpreter uv resolves. It defaults to 3.9 — the minimum
# this package claims to support — because that is the version most likely to
# catch a syntax or stdlib assumption that a newer one silently accepts.
PYTHON ?= 3.9

# Every 3.x this package claims to support, for `make test-all`. Keep in sync
# with requires-python in pyproject.toml.
PYTHON_VERSIONS := 3.9 3.10 3.11 3.12 3.13 3.14

UV ?= uv
RUN := $(UV) run --python $(PYTHON) --with-editable .

.DEFAULT_GOAL := help
.PHONY: help test test-all lint format build clean check

help:
	@echo 'Targets:'
	@echo '  test       run the test suite (PYTHON=$(PYTHON))'
	@echo '  test-all   run it on every supported Python: $(PYTHON_VERSIONS)'
	@echo '  lint       ruff check + ruff format --check (read-only)'
	@echo '  format     apply ruff format and ruff check --fix (writes)'
	@echo '  build      build the wheel and sdist into dist/'
	@echo '  check      lint + test + build, in that order'
	@echo '  clean      remove build artefacts and caches'
	@echo
	@echo 'Override the interpreter with e.g. make test PYTHON=3.13'

test:
	$(RUN) python -m unittest discover -s tests -v

# Sequential, not parallel: uv may need to download an interpreter, and
# interleaved unittest output from six runs is unreadable when one fails.
# `set -e` inside the loop is what makes a failure on 3.10 stop the run instead
# of being masked by a later success.
test-all:
	@set -e; for v in $(PYTHON_VERSIONS); do \
		echo "==> Python $$v"; \
		$(UV) run --python $$v --with-editable . python -m unittest discover -s tests; \
	done

# Read-only by design, so it is safe in CI and in a pre-commit hook: it reports
# what `make format` would change without changing anything.
lint:
	$(UV)x ruff check .
	$(UV)x ruff format --check .

format:
	$(UV)x ruff format .
	$(UV)x ruff check --fix .

build:
	$(UV) build

# The order matters: lint is the fastest to fail, build the slowest, so a
# broken run reports the cheapest problem first.
check: lint test build

clean:
	rm -rf dist build .ruff_cache .venv
	find . -name '__pycache__' -type d -prune -exec rm -rf {} +
	find . -name '*.egg-info' -type d -prune -exec rm -rf {} +