# MSMCP — developer ergonomics
# =============================================================================
# Python targets run through `uv`, so the only prerequisite for those is a
# working `uv` (https://docs.astral.sh/uv/).  Python itself is managed via
# .python-version.  The `repomix` target additionally requires the `repomix`
# CLI (https://repomix.com/, Node-based).

.PHONY: install format lint test eval run repomix all validate-similarity interop-check

install:            ## Create/update the virtualenv and sync all deps (incl. dev extras)
	uv sync --extra dev

format: install     ## Auto-format code and apply safe fixes (ruff)
	uv run ruff format .
	uv run ruff check --fix .

lint: install       ## Static checks: ruff format --check, ruff, mypy, basedpyright (mirrors CI)
	uv run ruff format --check .
	uv run ruff check .
	uv run mypy
	uv run basedpyright

test: install       ## Run the fast pytest suite (the eval notebook is deselected)
	uv run pytest

eval: install       ## Execute notebooks/eval_msmcp.ipynb end to end and report
	uv run pytest tests/test_eval_notebook.py -m eval -s -q

run:                ## Launch the MCP server on the stdio transport
	uv run msmcp

repomix:            ## Pack the repo into repomix-output.xml for AI analysis
	repomix --style xml --output repomix-output.xml

validate-similarity: ## Opt-in: independent similarity validation vs matchms (set MSMCP_VALIDATION_DATA; skips cleanly when unset)
	MSMCP_VALIDATION_DATA="$(MSMCP_VALIDATION_DATA)" uv run --with "matchms==0.33.1" python validation/similarity_validation.py

all: install format lint test eval repomix ## Full pipeline: sync, format, lint, test, evaluate, repomix-pack

# Each checkout uses its own already-synced environment; no dependency exchange.
INTEROP_OUTPUT ?= notebooks/.eval_artifacts/interop_report.json
interop-check: ## Opt-in: compare the two local reader contracts (set MASSFLOW_ROOT)
	@test -n "$(MASSFLOW_ROOT)" || (echo "Set MASSFLOW_ROOT to the analytical MassFlow checkout" >&2; exit 2)
	uv run --no-sync python validation/contract_probe.py --msmcp-root "$(CURDIR)" --massflow-root "$(MASSFLOW_ROOT)" --output "$(INTEROP_OUTPUT)"
