set shell := ["bash", "-euo", "pipefail", "-c"]

default: quality-check

sync:
    uv sync --locked --all-groups --no-sources

init: sync
    uv run --no-sources prek install

format:
    uv run --no-sources ruff format .
    uv run --no-sources ruff check --fix .

quality-check *paths:
    #!/usr/bin/env bash
    set -euo pipefail
    if (( $# == 0 )); then
        lint_targets=(.)
        type_targets=(src)
    else
        lint_targets=("$@")
        type_targets=("$@")
    fi
    printf '[1/3] ruff lint\n'
    uv run --no-sources ruff check "${lint_targets[@]}" &
    ruff_pid=$!
    printf '[2/3] mypy\n'
    uv run --no-sources mypy "${type_targets[@]}" &
    mypy_pid=$!
    printf '[3/3] ty\n'
    uv run --no-sources ty check "${type_targets[@]}" &
    ty_pid=$!

    status=0
    wait "$ruff_pid" || status=1
    wait "$mypy_pid" || status=1
    wait "$ty_pid" || status=1
    exit "$status"

precommit:
    @printf '=== src checks ===\n'
    @uv run --no-sources prek run --all-files --group src
    @printf '\n=== general ===\n'
    @uv run --no-sources prek run --all-files --group general

test:
    uv run --no-sources pytest -v
