.PHONY: dev test pub clean

BUMP ?= patch
CUR := $(shell sed -n 's/^version = "\(.*\)"/\1/p' pyproject.toml | head -1)
NEW  = $(if $(V),$(V),$(shell echo $(CUR) | awk -F. '{ \
	if ("$(BUMP)"=="major") printf "%s.0.0",$$1+1; \
	else if ("$(BUMP)"=="minor") printf "%s.%s.0",$$1,$$2+1; \
	else printf "%s.%s.%s",$$1,$$2,$$3+1 }'))

dev:
	uv pip install -e .

test:
	uv run pytest

pub:
	@test -f .pypirc || (echo "Missing .pypirc" && exit 1)
	@echo "$(CUR) -> $(NEW)"
	sed -i 's/^version = "$(CUR)"/version = "$(NEW)"/' pyproject.toml
	rm -rf dist/
	uv run python -m build --sdist --wheel --outdir dist/
	uv run twine upload -r irohds --verbose --config .pypirc dist/*
	git add -A && git commit -m "v$(NEW)" && git tag "v$(NEW)" && git push origin main --tags

clean:
	rm -rf dist/ .venv/ *.egg-info/
