# Default recipe - shows available commands.
default:
    @just --list

min_python_version := "3.10"
max_python_version := "3.12"

# In CI, pin installs to versions published before this date for reproducibility.
ci_cutoff := if env_var_or_default("CI", "") != "" { "--exclude-newer 2026-03-06" } else { "" }

# Install uv package manager for Python.
install-uv:
    curl -LsSf https://astral.sh/uv/install.sh | sh

# Install dependencies with minimal Python version and lowest direct resolution.
install-minimal:
    uv sync --python={{min_python_version}} --resolution=lowest-direct {{ci_cutoff}}

# Install dependencies with minimal Python version, lowest direct resolution, and all extras.
install-minimal-extras:
    uv sync --python={{min_python_version}} --resolution=lowest-direct --all-extras {{ci_cutoff}}

# Install dependencies with maximal Python version and all extras.
install:
    uv sync --python={{max_python_version}} --all-extras --no-dev {{ci_cutoff}}

# Install development dependencies with maximal Python version and all extras.
install-dev:
    uv sync --python={{max_python_version}} --all-extras {{ci_cutoff}}

# Run tests using pytest, report skipped and failed tests. You can pass any pytest args
# to this recipe to override the default (`-ra`), e.g. `just test -vv` for verbose 
# output.
test *args="-ra":
    pytest {{args}} tests

# Apply license headers to all source files.
license-headers:
    licenseheaders -t dev/licenseheader_lionelpeer.tmpl -d . -x scripts/*

# Run code formatter and apply license headers.
format: license-headers
    ruff format .

# Check formatting without applying changes.
format-check: license-headers
    # uv.lock is excluded because --exclude-newer writes the cutoff date into it in CI.
    git diff --exit-code -- ':!uv.lock'
    ruff format --check .

# Run linter with auto-fix.
lint-fix:
    ruff check --fix .

# Run linter without auto-fix.
lint:
    ruff check .

# Run type checker.
typecheck:
    mypy src tests

# Run static checks: format check, license header check, lint, and typecheck (no tests).
static-checks: format-check lint typecheck

# Run all checks: lint, typecheck, and tests.
all-checks: lint typecheck test

# Build documentation using mkdocs.
build-docs:
    mkdocs build

# Deploy versioned docs via mike (VERSION and ALIAS are required args).
deploy-docs VERSION ALIAS:
    mike deploy --push --update-aliases {{VERSION}} {{ALIAS}}
    mike set-default --push latest

# Deploy main branch docs snapshot.
deploy-docs-main:
    mike deploy --push main

# Serve live documentation using mkdocs.
serve-docs:
    mkdocs serve -a localhost:8008

# Clean up cache files
clean:
    find . -type d -name "__pycache__" -exec rm -rf {} +
    find . -type d -name ".pytest_cache" -exec rm -rf {} +
    find . -type f -name "*.pyc" -delete

# Compiled model cleanup.
clean-models:
    find server -type f \( -name "*.onnx" -o -name "*.plan" \) -delete
    