# =============================
# Adapted from:
# 	https://github.com/ashleve/lightning-hydra-template
# =============================

# Declare all targets as phony (not actual files)
.PHONY: help clean format git-sync test-full install install-dev install-cuda install-examples install-docs install-all clean-env remake-lockfile

# Default target - show help when just running 'make'
.DEFAULT_GOAL := help

help:  ## Show help
	@grep -E '^[.a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

clean: ## Clean autogenerated files
	rm -rf dist
	find . -type f -name "*.DS_Store" -ls -delete
	find . | grep -E "(__pycache__|\.pyc|\.pyo)" | xargs rm -rf
	find . | grep -E ".pytest_cache" | xargs rm -rf
	find . | grep -E ".ipynb_checkpoints" | xargs rm -rf
	rm -f .coverage

format: ## Run pre-commit hooks
	uv run pre-commit run -a

git-sync: ## Merge changes from main branch to your current branch
	git pull
	git pull origin main

test-full: ## Run all tests
	uv run pytest

install: ## Install dependencies from `pyproject.toml`
	uv sync

install-dev: ## Install development dependencies from `pyproject.toml`
	uv sync --extra dev

install-cuda: ## Install dependencies with CUDA support
	uv sync --extra cu12

install-examples: ## Install examples dependencies from `pyproject.toml`
	uv sync --extra examples

install-docs: ## Install docs dependencies from `pyproject.toml`
	uv sync --extra docs

install-all: ## Install all dependencies from `pyproject.toml`
	uv sync --all-extras

clean-env: ## Remove virtual environment and lockfile
	rm -rf .venv uv.lock
	@echo "🗑️  Removed .venv and uv.lock"

remake-lockfile: clean-env ## Recreate lockfile and environment from scratch
	uv sync --extra dev --extra examples --extra docs
	@echo "✅ Fresh environment created with new lockfile"
