# shellforge Makefile

.PHONY: help install install-system install-dev dev-setup test test-coverage lint lint-fix lint-check lint-strict lint-strict-fix clean build

# Default target
help:
	@echo "shellforge Development Commands"
	@echo ""
	@echo "Installation:"
	@echo "  make install          Install shellforge in development mode"
	@echo "  make install-system   Install shellforge system-wide"
	@echo "  make install-dev      Install with dev dependencies (ruff, pytest)"
	@echo "  make dev-setup        Create venv and install for local development"
	@echo ""
	@echo "Testing:"
	@echo "  make test             Run all tests"
	@echo "  make test-coverage    Run tests with coverage report"
	@echo ""
	@echo "Code Quality:"
	@echo "  make lint             Run linters (ruff, mypy) - read-only"
	@echo "  make lint-fix         Run linters with auto-fix"
	@echo "  make lint-fix UNSAFE_FIXES=1  Run linters with unsafe auto-fix"
	@echo "  make lint-strict      Run strict linters for high quality standards"
	@echo "  make lint-strict-fix  Run strict linters with auto-fix"
	@echo "  make lint-strict-fix UNSAFE_FIXES=1  Strict with unsafe auto-fix"
	@echo ""
	@echo "Build & Clean:"
	@echo "  make build            Build package"
	@echo "  make clean            Clean build artifacts and caches"

# Installation
install:
	uv pip install -e .

install-system:
	uv pip install -e . --system

install-dev:
	uv pip install -e ".[dev]"

dev-setup:
	@echo "Creating Python virtual environment in .venv (if missing)..."
	uv venv
	@echo "Syncing project dependencies..."
	uv sync
	@echo "Installing shellforge in editable mode with dev dependencies..."
	uv pip install -e ".[dev]"
	@echo ""
	@echo "Local development environment is ready."
	@echo "To use 'shellforge', activate the virtual environment:"
	@echo "  source .venv/bin/activate"
	@echo "Then run:"
	@echo "  shellforge --help"

# Testing
test:
	uv run pytest -v

test-coverage:
	uv run pytest -v --cov=src/shellforge --cov-report=html --cov-report=term-missing

# Code Quality
LINT_DIRS = src/shellforge tests
LINT_DIRS_CORE = src/shellforge
UNSAFE_FIXES ?=
UNSAFE_FLAG = $(if $(UNSAFE_FIXES),--unsafe-fixes,)

# lint-check: read-only lint check (no auto-fix)
lint-check:
	@echo "Running lint checks only (no auto-fix)..."
	@echo "Running ruff check..."
	uv run ruff check $(LINT_DIRS) --diff
	@echo "Running ruff format check..."
	uv run ruff format $(LINT_DIRS) --check
	@echo "Running mypy..."
	uv run mypy $(LINT_DIRS_CORE) --ignore-missing-imports || echo "Type check completed"

lint: lint-check

# lint-fix: auto-fix + format
lint-fix:
	@echo "Running lint with auto-fix..."
	@echo "Running ruff check with auto-fix..."
	uv run ruff check $(LINT_DIRS) --fix $(UNSAFE_FLAG)
	@echo "Running ruff format..."
	uv run ruff format $(LINT_DIRS)
	@echo "Running mypy..."
	uv run mypy $(LINT_DIRS_CORE) --ignore-missing-imports || echo "Type check completed"

# lint-strict: strict lint check (all rules)
lint-strict:
	@echo "Running strict lint checks..."
	@echo "Running ruff with all rules..."
	uv run ruff check $(LINT_DIRS) --select ALL --ignore E501,D100,D101,D102,D103,D104,D105,D106,D107,COM812 --output-format=full
	@echo "Running mypy with strict settings..."
	uv run mypy $(LINT_DIRS_CORE) --strict --ignore-missing-imports || echo "Type check completed"

# lint-strict-fix: strict lint with auto-fix
lint-strict-fix:
	@echo "Running strict lint with auto-fix..."
	@echo "Running ruff check with all rules and auto-fix..."
	uv run ruff check $(LINT_DIRS) --select ALL --ignore E501,D100,D101,D102,D103,D104,D105,D106,D107,COM812 --fix $(UNSAFE_FLAG)
	@echo "Running ruff format..."
	uv run ruff format $(LINT_DIRS)
	@echo "Running mypy with strict settings..."
	uv run mypy $(LINT_DIRS_CORE) --strict --ignore-missing-imports || echo "Type check completed"
	@echo "Strict lint with auto-fix completed!"

# Build
build:
	uv build

# Clean
clean:
	@echo "Cleaning build artifacts..."
	rm -rf build/
	rm -rf dist/
	rm -rf *.egg-info
	rm -rf src/*.egg-info
	rm -rf .pytest_cache/
	rm -rf .coverage
	rm -rf htmlcov/
	rm -rf .mypy_cache/
	rm -rf .ruff_cache/
	find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
	find . -type f -name "*.pyc" -delete 2>/dev/null || true

# Version
version:
	@grep version pyproject.toml | head -1 | cut -d'"' -f2
