.PHONY: test checkstyle coverage run-benchmarks all

all: checkstyle test

# Command to run pytest for correctness tests
test:
	python -m pytest --disable-warnings \
		--cov=src/chalk \
		--cov-report=term-missing \
		test/

# Command to run coverage report
coverage:
	coverage report -m

# Command to run ruff for linting and formatting code
checkstyle:
	ruff check --output-format=concise .; ruff_check_status=$$?; \
	ruff format --check --diff .; ruff_format_status=$$?; \
	ruff check . --fix; \
	ruff format .; \
	if [ $$ruff_check_status -ne 0 ] || [ $$ruff_format_status -ne 0 ]; then \
		exit 1; \
	fi

# Command to run all benchmark scripts and update benchmarking data file
# By default this doesn't overwrite existing data for the same benchmark experiment
# run with `make run-benchmarks OVERWRITE=1` to overwrite existing benchmark data
BENCHMARK_DIR = benchmark/scripts
BENCHMARK_SCRIPTS = $(wildcard $(BENCHMARK_DIR)/benchmark_*.py)
OVERWRITE ?= 0

run-benchmarks:
	@for script in $(BENCHMARK_SCRIPTS); do \
		echo "Running benchmark: $$script"; \
		if [ $(OVERWRITE) -eq 1 ]; then \
			python $$script --overwrite; \
		else \
			python $$script; \
		fi; \
	done
