.PHONY: install clean lint format precommit type test coverage run

SRC := src/srm
DEV ?= false

export PYTHONPYCACHEPREFIX := .cache/pycache

export UV_SYSTEM_CERTS := 1

## Dev tools Packages Handling
ifeq ($(DEV),true)
	EXTRAS := --extra dev
else
	EXTRAS :=
endif

## Uv sync command
# --locked fails fast if uv.lock is out of sync with pyproject.toml, instead of
# silently re-resolving, so local dev and CI always install the same versions.
UV_SYNC = uv sync --locked $(EXTRAS)

## Make Commands
install:
	$(UV_SYNC)

clean:
	rm -rf .venv
	rm -rf .cache
	rm -rf src/*.egg-info

lint:
	make install DEV=true
	.venv/bin/ruff check --fix

format:
	make install DEV=true
	.venv/bin/ruff format

precommit:
	make install DEV=true
	.venv/bin/pre-commit run --all-files

architecture:
	make install DEV=true
	.venv/bin/lint-imports --cache-dir .cache/import-linter

type:
	make install DEV=true
	.venv/bin/mypy src/ tests/

test:
	make install DEV=true
	.venv/bin/pytest

coverage:
	make install DEV=true
	.venv/bin/pytest --cov=$(SRC) --cov-branch --cov-report=term-missing

run:
	make install
	.venv/bin/uvicorn srm.main:create_app --reload
