|
| 1 | +# Local full check in one command — same intent as .github/workflows/ci.yml |
| 2 | +# Needs: https://github.com/astral-sh/uv, Rust (rustfmt, clippy), C toolchain (PyO3) |
| 3 | +# |
| 4 | +# All installs go into ./.venv (maturin develop --uv, uv run). Do NOT point package installs |
| 5 | +# at /usr/bin/python3 on Debian/Ubuntu (PEP 668 “externally managed”). |
| 6 | +# |
| 7 | +# To choose which *base* interpreter uv venv uses when creating .venv (only if missing): |
| 8 | +# make test PY_BOOTSTRAP=/usr/bin/python3.12 |
| 9 | +# rm -rf .venv && make test PY_BOOTSTRAP=... — recreate venv with another base |
| 10 | + |
| 11 | +SHELL := bash |
| 12 | +.SHELLFLAGS := -eu -o pipefail -c |
| 13 | + |
| 14 | +UV ?= uv |
| 15 | +ROOT := $(abspath .) |
| 16 | +export UV_PROJECT := $(ROOT) |
| 17 | + |
| 18 | +# Used only to *create* .venv; package installs use .venv, never the base interpreter. |
| 19 | +PY_BOOTSTRAP ?= $(shell command -v python3) |
| 20 | +VENV_PY := $(ROOT)/.venv/bin/python |
| 21 | +export UV_PYTHON := $(VENV_PY) |
| 22 | + |
| 23 | +# Dev speed: make test MATURIN_FLAGS= | same as CI release build: (default) --release |
| 24 | +MATURIN_FLAGS ?= --release |
| 25 | +RUFF_PATHS := oxyroute tests examples |
| 26 | + |
| 27 | +.PHONY: help all test lint fix sync develop wheel install pytest build \ |
| 28 | + _need-uv _need-python-bootstrap _ensure-venv |
| 29 | + |
| 30 | +help: |
| 31 | + @echo "make test — venv + uv sync + ruff (check) + ruff format --check + rustfmt (check) + clippy +" |
| 32 | + @echo " maturin develop --uv + pytest (isolated temp dir, like CI)" |
| 33 | + @echo "make lint — venv + sync + Python/Rust checks only (no maturin, no tests)" |
| 34 | + @echo "make fix — venv + sync + ruff format (write) + cargo fmt (not in make test)" |
| 35 | + @echo "make build / develop — venv + sync + maturin develop --uv (no linters, no tests)" |
| 36 | + @echo "make wheel — venv + build target/wheels/*.whl (packaging; no install to venv)" |
| 37 | + @echo " MATURIN_FLAGS= — debug build (drop --release )" |
| 38 | + @echo " PY_BOOTSTRAP= — base python3 to create .venv (default: which python3 )" |
| 39 | + |
| 40 | +all: test |
| 41 | + |
| 42 | +test: _need-uv _need-python-bootstrap _ensure-venv |
| 43 | + $(UV) sync --frozen --extra dev |
| 44 | + $(UV) run ruff check $(RUFF_PATHS) |
| 45 | + $(UV) run ruff format --check $(RUFF_PATHS) |
| 46 | + cargo fmt --all -- --check |
| 47 | + cargo clippy --all-targets -- -D warnings |
| 48 | + $(UV) run maturin develop --uv $(MATURIN_FLAGS) |
| 49 | + @_d=$$(mktemp -d); trap 'rm -rf "$$_d"' EXIT; \ |
| 50 | + (cd "$$_d" && UV_PROJECT="$(ROOT)" $(UV) run python -m pytest "$(ROOT)/tests" -v) |
| 51 | + @echo OK |
| 52 | + |
| 53 | +lint: _need-uv _need-python-bootstrap _ensure-venv |
| 54 | + $(UV) sync --frozen --extra dev |
| 55 | + $(UV) run ruff check $(RUFF_PATHS) |
| 56 | + $(UV) run ruff format --check $(RUFF_PATHS) |
| 57 | + cargo fmt --all -- --check |
| 58 | + cargo clippy --all-targets -- -D warnings |
| 59 | + |
| 60 | +fix: _need-uv _need-python-bootstrap _ensure-venv |
| 61 | + $(UV) sync --frozen --extra dev |
| 62 | + $(UV) run ruff format $(RUFF_PATHS) |
| 63 | + cargo fmt --all |
| 64 | + |
| 65 | +sync: _need-uv _need-python-bootstrap _ensure-venv |
| 66 | + $(UV) sync --frozen --extra dev |
| 67 | + |
| 68 | +develop: _need-uv sync |
| 69 | + $(UV) run maturin develop --uv $(MATURIN_FLAGS) |
| 70 | + |
| 71 | +# Release wheel in target/wheels/ (as in CI “build” job); does not install to venv |
| 72 | +wheel: _need-uv sync |
| 73 | + rm -f target/wheels/oxyroute-*.whl |
| 74 | + $(UV) run maturin build $(MATURIN_FLAGS) |
| 75 | + |
| 76 | +# Historical alias: same as develop |
| 77 | +build: develop |
| 78 | +install: develop |
| 79 | + |
| 80 | +pytest: _need-uv _need-python-bootstrap _ensure-venv |
| 81 | + $(UV) sync --frozen --extra dev |
| 82 | + @_d=$$(mktemp -d); trap 'rm -rf "$$_d"' EXIT; \ |
| 83 | + (cd "$$_d" && UV_PROJECT="$(ROOT)" $(UV) run python -m pytest "$(ROOT)/tests" -v) |
| 84 | + |
| 85 | +_need-uv: |
| 86 | + @command -v $(UV) >/dev/null 2>&1 || { \ |
| 87 | + echo "error: '$(UV)' not on PATH. Install: https://docs.astral.sh/uv/"; \ |
| 88 | + exit 1; \ |
| 89 | + } |
| 90 | + |
| 91 | +_need-python-bootstrap: |
| 92 | + @test -n "$(PY_BOOTSTRAP)" || { \ |
| 93 | + echo "error: no python3 on PATH (set PY_BOOTSTRAP=/path/to/python)" >&2; \ |
| 94 | + exit 1; \ |
| 95 | + } |
| 96 | + |
| 97 | +# Create .venv if missing. First run must not set UV_PYTHON to a non-existent .venv binary |
| 98 | +# or uv venv can get confused; clear it for this one line only. |
| 99 | +_ensure-venv: _need-uv _need-python-bootstrap |
| 100 | + @if [ -x "$(VENV_PY)" ]; then exit 0; fi |
| 101 | + @env -u UV_PYTHON $(UV) venv --python "$(PY_BOOTSTRAP)" "$(ROOT)/.venv" |
0 commit comments