SHELL := /bin/bash

PYTHON_SRC := das_setup_helper tests tools

.DEFAULT: help

all: info

info:  ## Show this information
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'


# ------------------------------------------------------------------ #
# Environment                                                        #
# ------------------------------------------------------------------ #

sync:  ## Install / update all dependencies (dev included)
	uv sync --extra dev --no-install-project

clean:  ## Remove the virtual environment
	rm -rf .venv

# ------------------------------------------------------------------ #
# Development                                                        #
# ------------------------------------------------------------------ #

lint:  ## Run black and isort formatters
	uv run --no-project black $(PYTHON_SRC)
	uv run --no-project isort $(PYTHON_SRC)

pre-commit-install:  ## Install git pre-commit, commit-msg and pre-push hooks
	uv run --no-project pre-commit install
	uv run --no-project pre-commit install --hook-type commit-msg
	uv run --no-project pre-commit install --hook-type pre-push

pre-commit-run:  ## Run pre-commit on all files
	uv run --no-project pre-commit run --all-files

test:  ## Run tests
	uv run --no-project pytest $(PYTEST_OPTIONS)

# ------------------------------------------------------------------ #
# Pipelines                                                          #
# ------------------------------------------------------------------ #

run-crawler:  ## Run setup_crawler pipeline
	uv run --no-project python -m das_setup_helper.pipelines.setup_crawler

run-acq:  ## Run create_acquisitions pipeline
	uv run --no-project python -m das_setup_helper.pipelines.create_acquisitions

extract-data:  ## Run extract_data_from_acquisitions pipeline
	uv run das-extract-data

fetch-rates:  ## Download Eurostat exchange rates and generate lookup file
	uv run python tools/generate_exchange_rates_lookup.py

run-stop:  ## Run stop_acquisitions pipeline
	uv run --no-project python -m das_setup_helper.pipelines.stop_acquisitions

run-extract:  ## Run extract_data_from_acquisitions pipeline
	uv run --no-project python -m das_setup_helper.pipelines.extract_data_from_acquisitions

# ------------------------------------------------------------------ #
# Release                                                            #
# ------------------------------------------------------------------ #

build:  ## Build the package
	uv build

publish-test:  ## Publish to TestPyPI
	uv publish --index testpypi

publish:  ## Publish to PyPI
	uv publish

lock:  ## Refresh uv.lock without upgrading
	uv lock

lock-upgrade:  ## Upgrade all dependencies and refresh uv.lock
	uv lock --upgrade
