# Tastytrade MCP — development tasks.
#
#   Run from this directory:   make build
#   …or from the repo root:    make -C mcp/tastytrade build
#   Override interpreter:      make build PYTHON=/path/to/python

PYTHON ?= ../../venv/bin/python
PIP    = $(PYTHON) -m pip

# Pulled from pyproject.toml so the publish/release echoes stay accurate.
NAME    := $(shell grep '^name' pyproject.toml | sed 's/.*"\(.*\)".*/\1/')
VERSION := $(shell grep '^version' pyproject.toml | sed 's/.*"\(.*\)".*/\1/')

.PHONY: help install test clean build publish bump release

help: ## Show available targets
	@grep -hE '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) | awk 'BEGIN{FS=":.*?## "}{printf "  %-10s %s\n",$$1,$$2}'

install: ## Editable install with dev tools (pytest, build, twine)
	$(PIP) install -e '.[dev]'

test: ## Run the test suite
	$(PYTHON) -m pytest -q

clean: ## Remove build/ and dist/
	rm -rf build dist

build: clean test ## Build wheel + sdist into dist/ (runs tests first)
	$(PYTHON) -m build --outdir dist
	@echo "-- built artifacts --"
	@ls -1 dist

publish: build ## Upload dist/* to PyPI (~/.pypirc). Re-publishing needs a new version — see 'make release'
	@echo "Publishing $(NAME) $(VERSION) from dist/"
	$(PYTHON) -m twine upload dist/*

bump: ## Increment version in pyproject.toml (PART=patch|minor|major; default patch)
	@$(PYTHON) scripts/bump_version.py $(PART)

release: bump publish ## One-command patch release: bump -> build -> upload to PyPI
