PYTHON ?= python
DVC ?= dvc
DVC_SITE_CACHE_DIR ?= $(CURDIR)/.dvc-cache
DVC_CMD = DVC_SITE_CACHE_DIR=$(DVC_SITE_CACHE_DIR) $(DVC)

.PHONY: install mlflow-server init-dvc validate prepare train evaluate gate scenarios pipeline pipeline-offline pipeline-server pipeline-stages test check repro repro-offline graph clean inspect

install:
	$(PYTHON) -m pip install -r requirements.txt

mlflow-server:
	$(PYTHON) -m mlflow server --backend-store-uri sqlite:///mlflow.db --host 127.0.0.1 --port 5000

init-dvc:
	@test -d .dvc || $(DVC_CMD) init --no-scm

validate:
	$(PYTHON) src/validate_data.py

prepare:
	$(PYTHON) src/prepare.py

train:
	$(PYTHON) src/train.py

evaluate:
	$(PYTHON) src/evaluate.py

gate:
	$(PYTHON) src/quality_gate.py

scenarios:
	$(PYTHON) src/run_scenarios.py --kind all

pipeline-stages: validate prepare train evaluate gate

pipeline:
	MLFLOW_TRACKING_URI=sqlite:///mlflow-offline.db MLFLOW_EXPERIMENT_NAME=mlops-course-session-3-offline $(MAKE) pipeline-stages

pipeline-offline: pipeline

pipeline-server:
	$(MAKE) pipeline-stages

inspect:
	$(PYTHON) -m json.tool reports/quality_gate_decision.json

test:
	$(PYTHON) -m pytest

check: pipeline test

repro: init-dvc
	$(DVC_CMD) repro

repro-offline: init-dvc
	MLFLOW_TRACKING_URI=sqlite:///mlflow-offline.db MLFLOW_EXPERIMENT_NAME=mlops-course-session-3-offline $(DVC_CMD) repro

graph: init-dvc
	$(DVC_CMD) dag

clean:
	rm -rf data/processed artifacts reports/*.json .dvc
