-include .env
export

.PHONY: install test lint format typecheck ci clean tag

# Install with dev dependencies
install:
	uv sync --extra dev

# Run tests
test:
	uv run pytest $(ARGS)

# Lint with ruff
lint:
	uv run ruff check src/ tests/
	uv run ruff format --check src/ tests/

# Format code
format:
	uv run ruff check --fix src/ tests/
	uv run ruff format src/ tests/

# Type check
typecheck:
	uv run basedpyright

# All CI checks
ci: lint typecheck test

# Tag a release from the version committed at HEAD
tag:
	@git diff --quiet HEAD -- pyproject.toml || \
		{ echo "pyproject.toml has uncommitted changes — commit the version bump first"; exit 1; }
	@VERSION=$$(git show HEAD:./pyproject.toml | python3 -c "import sys, tomllib; print(tomllib.load(sys.stdin.buffer)['project']['version'])") && \
	git tag "component-builder/v$$VERSION" && \
	echo "Tagged component-builder/v$$VERSION — release-pypi.yml fires on this scope only"

# Remove build artifacts
clean:
	rm -rf build/ dist/ *.egg-info src/*.egg-info
	find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
	find . -type f -name "*.pyc" -delete 2>/dev/null || true
