# Justfile for andalus
set shell := ["cmd.exe", "/c"]

# Show available commands
list:
    @just --list

# Type check the project with ty
type-check:
    uv run --python=3.12 ty check .

# Type check with concise output (one diagnostic per line)
type-check-concise:
    uv run --python=3.12 ty check --output-format=concise .

# Type check in watch mode (rechecks on file changes)
type-check-watch:
    uv run --python=3.12 ty check --watch .

# Define a local temp directory for pytest to avoid Windows PermissionErrors
pytest_temp := "C:/Users/dhouben/Documents/andalus_tmp"

# Run all the formatting, linting, and testing commands
qa:
    uv run --python=3.12 ruff format .
    uv run --python=3.12 ruff check . --fix
    uv run --python=3.12 ruff check --select I --fix .
    uv run --python=3.12 ty check --output-format=concise .
    uv run --python=3.12 pytest . --basetemp={{pytest_temp}}

# Run all the tests for all the supported Python versions
testall:
    uv run --python=3.10 pytest --basetemp={{pytest_temp}}
    uv run --python=3.11 pytest --basetemp={{pytest_temp}}
    uv run --python=3.12 pytest --basetemp={{pytest_temp}}

# Run all the tests, but allow for arguments to be passed
test *ARGS:
    @echo "Running with arg: {{ARGS}}"
    uv run --python=3.12 pytest --basetemp={{pytest_temp}} {{ARGS}}

# Run all the tests, but on failure, drop into the debugger
pdb *ARGS:
    @echo "Running with arg: {{ARGS}}"
    uv run --python=3.12 pytest --pdb --maxfail=10 {{ARGS}}

# Run tests with coverage across all supported Python versions
coverage:
    uv run --python=3.12 coverage run -m pytest
    # uv run --python=3.13 coverage run -m pytest
    # uv run --python=3.14 coverage run -m pytest
    uv run --python=3.12 coverage combine
    uv run --python=3.12 coverage report
    uv run --python=3.12 coverage html

# Serve docs locally with live reload
docs-serve:
    -lsof -ti :8000 | xargs kill
    uv run --group docs sphinx-autobuild docs/source docs/_build/html --port 8000 --open-browser

# Build docs (strict mode, fails on warnings)
docs-build:
    uv run --group docs sphinx-build -W --keep-going -b html docs/source docs/_build/html

# Build the project, useful for checking that packaging is correct
build:
    rm -rf build
    rm -rf dist
    uv build

VERSION := `grep -m1 '^version' pyproject.toml | sed -E 's/version = "(.*)"/\1/'`

# Print the current version of the project
version:
    @echo "Current version is {{VERSION}}"

# Tag the current version in git and put to github
tag:
    echo "Tagging version v{{VERSION}}"
    git tag -a v{{VERSION}} -m "Creating version v{{VERSION}}"
    git push origin v{{VERSION}}

# remove all build, test, coverage and Python artifacts
clean:
	clean-build
	clean-pyc
	clean-test

# remove build artifacts
clean-build:
	rm -fr build/
	rm -fr dist/
	rm -fr .eggs/
	find . -name '*.egg-info' -exec rm -fr {} +
	find . -name '*.egg' -exec rm -f {} +

# remove Python file artifacts
clean-pyc:
	find . -name '*.pyc' -exec rm -f {} +
	find . -name '*.pyo' -exec rm -f {} +
	find . -name '*~' -exec rm -f {} +
	find . -name '__pycache__' -exec rm -fr {} +

# remove test and coverage artifacts
clean-test:
	rm -f .coverage
	rm -f .coverage.*
	rm -fr htmlcov/
	rm -fr .pytest_cache

# Publish to PyPI (manual alternative to GitHub Actions)
publish:
    uv build
    uv publish
