APP = python-getstream-connector

TEST_IMAGE_NAME = python:3.11

VENV := ./venv

PYTHON     = $(VENV)/bin/python
PIP        = $(VENV)/bin/pip
PYTEST     = $(VENV)/bin/pytest
RUFF       = $(VENV)/bin/ruff
MYPY       = $(VENV)/bin/mypy
PRE_COMMIT = $(VENV)/bin/pre-commit

.DEFAULT_GOAL := help


## help - this message
.PHONY: help
help: Makefile
	@echo "Application: $(APP)\n"
	@echo "Run command:\n  make <target>\n"
	@echo $(MAKEFILE_LIST)
	@grep -E -h '^## .*' $(MAKEFILE_LIST) | sed -n 's/^## //p'

$(VENV)/bin/activate:
	@echo "Creating virtual environment"
	python -m venv $(VENV)/

venv: $(VENV)/bin/activate
	@echo "Ensure pip installed"
	$(PYTHON) -m ensurepip --upgrade
	@echo "Installing requirements"
	$(PIP) install --no-cache-dir -U .

testenv: venv
	@echo "Installing dev requirements"
	$(PIP) install --no-cache-dir -r requirements-dev.txt

## test - run unit tests and create report
.PHONY: test
test: testenv
	@echo "Running unit tests"
	$(PYTEST) tests \
		--cov getstream_connector/ \
		--cov-report xml:coverage.xml \
		--junitxml=pyunit.xml

## fix_style - fix codestyle
.PHONY: fix_style
fix_style: testenv
	@echo "Fixing codestyle"
	$(RUFF) check --fix
	$(RUFF) format

## check_style - check codestyle
.PHONY: check_style
check_style: testenv
	@echo "Checking codestyle"
	$(RUFF) check
	$(RUFF) format --check

## check_types - check static typing
.PHONY: check_types
check_types: testenv
	@echo "Checking static typing"
	$(MYPY)

## run_check_suite - run full check suite with style check and tests
.PHONY: run_check_suite
run_check_suite: testenv check_style check_types test


## docker/<local target> - universal docker wrapper for local targets
docker/%:
	docker run --rm \
		-v $(PWD):/var/app \
		-w /var/app \
		$(TEST_IMAGE_NAME) make VENV=/var/venv $*
