|
| 1 | +# Justfile for python-qrcode |
| 2 | +# Modern development commands using uv |
| 3 | + |
| 4 | +# Default recipe - show available commands |
| 5 | +default: |
| 6 | + @just --list |
| 7 | + |
| 8 | +# Run tests |
| 9 | +# Usage: |
| 10 | +# just test -> run all test matrices + coverage |
| 11 | +# just test quick -> quick test with current Python (no coverage) |
| 12 | +# just test [3.10|3.11|...] -> run specific python version (all variants) |
| 13 | +# just test [3.10|...] [pil|png|none] -> run specific python and variant |
| 14 | +test *ARGS='': |
| 15 | + #!/usr/bin/env bash |
| 16 | + set -euo pipefail |
| 17 | + |
| 18 | + ARGS=( {{ ARGS }} ) |
| 19 | + |
| 20 | + if [ ${#ARGS[@]} -eq 0 ]; then |
| 21 | + # No args: run all |
| 22 | + echo "Running all test environments..." |
| 23 | + just _test-matrix |
| 24 | + just _coverage-report |
| 25 | + elif [ ${#ARGS[@]} -eq 1 ]; then |
| 26 | + ARG="${ARGS[0]}" |
| 27 | + if [ "$ARG" = "quick" ]; then |
| 28 | + uv run --quiet --group dev pytest -q |
| 29 | + elif [[ "$ARG" =~ ^3\.[0-9]+$ ]]; then |
| 30 | + # Run all variants for this python version |
| 31 | + just _test-env "$ARG" pil |
| 32 | + just _test-env "$ARG" png |
| 33 | + just _test-env "$ARG" none |
| 34 | + else |
| 35 | + echo "Unknown argument: $ARG" |
| 36 | + exit 1 |
| 37 | + fi |
| 38 | + elif [ ${#ARGS[@]} -eq 2 ]; then |
| 39 | + just _test-env "${ARGS[0]}" "${ARGS[1]}" |
| 40 | + else |
| 41 | + echo "Usage: just test [quick | PYTHON_VER | PYTHON_VER VARIANT]" |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | + |
| 45 | +# Run all test environments (internal) |
| 46 | +_test-matrix: |
| 47 | + #!/usr/bin/env bash |
| 48 | + set -e |
| 49 | + echo "Cleaning old coverage files..." |
| 50 | + rm -rf .coverage* htmlcov |
| 51 | + for py in 3.10 3.11 3.12 3.13 3.14; do |
| 52 | + just _test-env $py pil |
| 53 | + just _test-env $py png |
| 54 | + just _test-env $py none |
| 55 | + done |
| 56 | + |
| 57 | +# Run a specific test environment (internal) |
| 58 | +_test-env PYTHON VARIANT: |
| 59 | + @printf "Testing: Python %-5s - %-5s " "{{ PYTHON }}" "{{ VARIANT }}" |
| 60 | + @if [ "{{ VARIANT }}" = "pil" ]; then \ |
| 61 | + uv run --quiet --python {{ PYTHON }} --extra pil --group dev coverage run -m pytest -q; \ |
| 62 | + elif [ "{{ VARIANT }}" = "png" ]; then \ |
| 63 | + uv run --quiet --python {{ PYTHON }} --extra png --group dev coverage run -m pytest -q; \ |
| 64 | + elif [ "{{ VARIANT }}" = "none" ]; then \ |
| 65 | + uv run --quiet --python {{ PYTHON }} --group dev coverage run -m pytest -q; \ |
| 66 | + else \ |
| 67 | + echo "Unknown variant: {{ VARIANT }}"; exit 1; \ |
| 68 | + fi |
| 69 | + @echo "✓" |
| 70 | + |
| 71 | +# Generate coverage report (internal) |
| 72 | +_coverage-report: |
| 73 | + @uv run --quiet --group dev coverage combine --quiet .coverage* 2>/dev/null || true |
| 74 | + @echo "" |
| 75 | + @echo "Test coverage:" |
| 76 | + @uv run --quiet --group dev coverage report -m |
| 77 | + @uv run --quiet --group dev coverage html |
| 78 | + @echo "Coverage report saved to htmlcov/index.html" |
| 79 | + |
| 80 | +# Run all checks (format, lint, tests) |
| 81 | +check: |
| 82 | + @echo "Running all checks..." |
| 83 | + @echo "→ Formatting..." |
| 84 | + @uv run --quiet ruff format --check qrcode |
| 85 | + @echo "→ Linting..." |
| 86 | + @uv run --quiet ruff check qrcode |
| 87 | + @echo "→ Testing..." |
| 88 | + @just test |
0 commit comments