|
| 1 | +################################################## |
| 2 | +# Constants |
| 3 | +################################################## |
| 4 | + |
| 5 | +APP_NAME := app-catala |
| 6 | + |
| 7 | +SHELL = /bin/bash -o pipefail |
| 8 | + |
| 9 | +APP_DIR := app |
| 10 | +ifdef CI |
| 11 | + DOCKER_EXEC_ARGS := -T -e CI -e PYTEST_ADDOPTS="--color=yes" |
| 12 | + MYPY_FLAGS := --no-pretty |
| 13 | + MYPY_POSTPROC := | perl -pe "s/^(.+):(\d+):(\d+): error: (.*)/::warning file=$(APP_DIR)\/\1,line=\2,col=\3::\4/" |
| 14 | +endif |
| 15 | + |
| 16 | +ifeq "$(PY_RUN_APPROACH)" "local" |
| 17 | +PY_RUN_CMD := poetry run |
| 18 | +else |
| 19 | +PY_RUN_CMD := docker compose run $(DOCKER_EXEC_ARGS) --rm $(APP_NAME) poetry run |
| 20 | +endif |
| 21 | + |
| 22 | +# Docker user configuration |
| 23 | +ifeq ($(user),) |
| 24 | +RUN_USER ?= $(or $(strip $(USER)),nodummy) |
| 25 | +RUN_UID ?= $(or $(strip $(shell id -u)),4000) |
| 26 | +else |
| 27 | +RUN_USER = $(user) |
| 28 | +RUN_UID = $(or $(strip $(uid)),0) |
| 29 | +endif |
| 30 | + |
| 31 | +export RUN_USER |
| 32 | +export RUN_UID |
| 33 | + |
| 34 | +release-build: |
| 35 | + docker buildx build \ |
| 36 | + --target release \ |
| 37 | + --platform=linux/amd64 \ |
| 38 | + --build-arg RUN_USER=$(RUN_USER) \ |
| 39 | + --build-arg RUN_UID=$(RUN_UID) \ |
| 40 | + $(OPTS) \ |
| 41 | + . |
| 42 | + |
| 43 | +################################################## |
| 44 | +# Local Development Environment Setup |
| 45 | +################################################## |
| 46 | + |
| 47 | +setup-local: |
| 48 | + poetry config virtualenvs.in-project true |
| 49 | + poetry install --no-root |
| 50 | + |
| 51 | +################################################## |
| 52 | +# Build & Run |
| 53 | +################################################## |
| 54 | + |
| 55 | +build: |
| 56 | + docker compose build |
| 57 | + |
| 58 | +start: |
| 59 | + docker compose up --detach |
| 60 | + |
| 61 | +run-logs: start |
| 62 | + docker compose logs --follow --no-color $(APP_NAME) |
| 63 | + |
| 64 | +init: build |
| 65 | + |
| 66 | +stop: |
| 67 | + docker compose down |
| 68 | + |
| 69 | +check: format-check lint test |
| 70 | + |
| 71 | +################################################## |
| 72 | +# Catala Compilation |
| 73 | +################################################## |
| 74 | + |
| 75 | +CATALA_DIR := catala |
| 76 | +CATALA_GEN_DIR := src/generated |
| 77 | + |
| 78 | +catala-build: ## Compile Catala sources to Python via clerk |
| 79 | + cd $(CATALA_DIR) && clerk build |
| 80 | + # There's a bug where dates.py is missing from the target code |
| 81 | + # https://github.com/CatalaLang/catala/issues/981 |
| 82 | + cp $(CATALA_DIR)/_build/libcatala/python/dates.py $(CATALA_GEN_DIR)/ |
| 83 | + cp $(CATALA_DIR)/_target/paidleave/python/* $(CATALA_GEN_DIR)/ |
| 84 | + |
| 85 | +catala-test: ## Run Catala test assertions via clerk |
| 86 | + cd $(CATALA_DIR) && clerk test |
| 87 | + |
| 88 | +catala-ci: ## Run Catala CI build and tests |
| 89 | + cd $(CATALA_DIR) && clerk ci |
| 90 | + |
| 91 | +################################################## |
| 92 | +# Testing |
| 93 | +################################################## |
| 94 | + |
| 95 | +test: ## Run Python tests |
| 96 | + $(PY_RUN_CMD) pytest $(args) |
| 97 | + |
| 98 | +test-watch: ## Run tests continually and watch for changes |
| 99 | + $(PY_RUN_CMD) pytest-watch --clear $(args) |
| 100 | + |
| 101 | +test-coverage: ## Run tests and generate coverage report |
| 102 | + $(PY_RUN_CMD) coverage run --branch --source=src -m pytest $(args) |
| 103 | + $(PY_RUN_CMD) coverage report |
| 104 | + |
| 105 | +test-coverage-report: ## Open HTML test coverage report |
| 106 | + $(PY_RUN_CMD) coverage html --directory .coverage_report |
| 107 | + open .coverage_report/index.html |
| 108 | + |
| 109 | +test-all: catala-test test ## Run all Catala and Python tests |
| 110 | + |
| 111 | +################################################## |
| 112 | +# Formatting and linting |
| 113 | +################################################## |
| 114 | + |
| 115 | +format: ## Format Python files |
| 116 | + $(PY_RUN_CMD) ruff format src tests |
| 117 | + |
| 118 | +format-check: ## Check Python file formatting |
| 119 | + $(PY_RUN_CMD) ruff format --check src tests |
| 120 | + |
| 121 | +lint: lint-ruff lint-mypy ## Lint all files |
| 122 | + |
| 123 | +lint-ruff: |
| 124 | + $(PY_RUN_CMD) ruff check src tests |
| 125 | + |
| 126 | +lint-mypy: |
| 127 | + $(PY_RUN_CMD) mypy --show-error-codes $(MYPY_FLAGS) src $(MYPY_POSTPROC) |
| 128 | + |
| 129 | +################################################## |
| 130 | +# Miscellaneous Utilities |
| 131 | +################################################## |
| 132 | + |
| 133 | +login: start ## Start shell in running container |
| 134 | + docker exec -it $(APP_NAME) bash |
| 135 | + |
| 136 | +help: ## Prints the help documentation and info about each command |
| 137 | + @grep -E '^[/a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
0 commit comments