# `make demo` runs before setup because the simulator uses the standard library.
PYTHON ?= python3

# Package targets use the project virtual environment.
VENV_PYTHON ?= .venv/bin/python

# A VENV_PYTHON override disables automatic `.venv` creation.
BOOTSTRAP := $(filter .venv/bin/python,$(VENV_PYTHON))


.PHONY: setup test lint format links check demo stub-fleet wiki observe

.venv/bin/python:
	$(PYTHON) -m venv .venv
	.venv/bin/pip install -e '.[dev]'

setup: .venv/bin/python

test: $(BOOTSTRAP)
	$(VENV_PYTHON) -m pytest -q

SOURCES := src tests demo tools examples

lint: $(BOOTSTRAP)
	$(VENV_PYTHON) -m ruff check $(SOURCES)

format: $(BOOTSTRAP)
	$(VENV_PYTHON) -m ruff format --check $(SOURCES)

links: $(BOOTSTRAP)
	$(VENV_PYTHON) tools/check_links.py

# Keep this order aligned with `.github/workflows/ci.yml`.
check: lint format test links

demo:
	$(PYTHON) demo/run_demo.py

wiki:
	tools/publish_wiki.sh

# Start the provisioned Prometheus and Grafana services.
observe:
	cd tools/observability && docker compose up -d

# Run six engine-protocol stubs in the foreground on ports 8101 through 8106.
stub-fleet: $(BOOTSTRAP)
	$(VENV_PYTHON) tools/stub_fleet.py --base-port 8101 --instances 6 --model stub
