PYTHON ?= python3.12
VENV := .venv
PIP := $(VENV)/bin/pip
PY := $(VENV)/bin/python

.PHONY: venv lint build patch release clean clean-all shell

venv: $(VENV)/bin/activate ## Create virtualenv and upgrade pip

$(VENV)/bin/activate:
	$(PYTHON) -m venv $(VENV)
	$(PIP) install --upgrade pip

lint: venv ## Lint with ruff (installs dev deps editable)
	$(PIP) install -e ".[dev]"
	$(PY) -m ruff check src

build: lint ## Build wheel and sdist
	$(PIP) install build
	$(PY) -m build

patch: venv ## Bump patch version in pyproject.toml
	$(PY) scripts/bump_version.py patch

release: build ## Bump patch version and upload to PyPI
	$(PIP) install twine
	$(PY) scripts/bump_version.py patch
	$(PY) -m build
	$(PY) -m twine upload dist/*

shell: venv ## Open a shell with the virtualenv activated
	@exec $(SHELL) -c "source $(VENV)/bin/activate && exec $(SHELL)"

clean: ## Remove build artifacts (keeps .venv)
	rm -rf build dist *.egg-info .ruff_cache

clean-all: clean ## Remove build artifacts and virtualenv
	rm -rf $(VENV)
