-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
198 lines (139 loc) · 6.76 KB
/
Makefile
File metadata and controls
198 lines (139 loc) · 6.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
PROJECT_DIR := $(patsubst %/,%,$(dir $(MAKEFILE_PATH)))
.DEFAULT_GOAL = help
# ---- Docker delegation -----------------------------------------------------
# Hors devcontainer (DEVCONTAINER != true), on réexécute la cible demandée
# dans la stack docker Python 3.11 définie dans .docker/. À l'intérieur du
# conteneur, DEVCONTAINER vaut "true" (cf. .docker/Dockerfile) donc cette
# branche est ignorée et le Makefile s'exécute normalement.
ifneq ($(DEVCONTAINER),true)
DOCKER_COMPOSE ?= docker compose -f .docker/docker-compose.yml
DOCKER_SERVICE ?= dev
DOCKER_ENV := UID=$$(id -u) GID=$$(id -g)
DOCKER_RUN := $(DOCKER_ENV) $(DOCKER_COMPOSE) run --rm $(DOCKER_SERVICE)
# Cibles déléguées à la stack docker (exécution dans le conteneur dev)
DELEGATED_TARGETS := all setup pkgs tox syntax black isort mypy flake8 pylint \
cover doc test test-unit test-cli
.PHONY: $(DELEGATED_TARGETS) test-functional \
docker-build docker-shell docker-clean \
stack-up stack-down stack-reset stack-logs stack-ps
## -- Docker (host) -----------------------------------------------------------
$(DELEGATED_TARGETS):
@$(DOCKER_RUN) make $@ $(MAKEOVERRIDES)
docker-build: ## Build the Python 3.11 docker dev image
$(DOCKER_ENV) $(DOCKER_COMPOSE) build
docker-shell: ## Open an interactive shell in the docker dev container
$(DOCKER_ENV) $(DOCKER_COMPOSE) run --rm $(DOCKER_SERVICE) bash
docker-clean: ## Remove the docker dev image and associated resources
-$(DOCKER_COMPOSE) down --rmi local --volumes --remove-orphans
## -- Functional stack (mssql/oracle/postgres) --------------------------------
# `functional` profile = mssql + postgres (fast). Oracle lives in its own
# `oracle` profile because the image is ~10 GB and takes 3-5 min to boot.
# `stack-up` keeps the historical "everything" behaviour for local dev.
stack-up: ## Start the full functional DB stack (mssql, mysql, postgres, oracle) and wait until healthy
$(DOCKER_ENV) $(DOCKER_COMPOSE) --profile functional --profile oracle up -d --wait mssql mysql postgres oracle
$(DOCKER_ENV) $(DOCKER_COMPOSE) --profile functional run --rm mssql-init
stack-up-light: ## Start only the lightweight functional DB stack (mssql, mysql, postgres) — no Oracle
$(DOCKER_ENV) $(DOCKER_COMPOSE) --profile functional up -d --wait mssql mysql postgres
$(DOCKER_ENV) $(DOCKER_COMPOSE) --profile functional run --rm mssql-init
stack-up-oracle: ## Start only the Oracle container (heavy, ~3-5 min boot) — no mssql/postgres
$(DOCKER_ENV) $(DOCKER_COMPOSE) --profile oracle up -d --wait oracle
stack-down: ## Stop the functional DB stack (keep volumes)
$(DOCKER_COMPOSE) --profile functional --profile oracle down
stack-reset: ## Stop the functional DB stack and wipe its volumes (re-runs init scripts)
$(DOCKER_COMPOSE) --profile functional --profile oracle down -v
stack-logs: ## Follow logs of the functional DB stack
$(DOCKER_COMPOSE) --profile functional --profile oracle logs -f
stack-ps: ## Show status of the functional DB stack
$(DOCKER_COMPOSE) --profile functional --profile oracle ps
test-functional: stack-up ## Run functional tests against the running docker stack
@$(DOCKER_RUN) make test-functional $(MAKEOVERRIDES)
test-functional-light: stack-up-light ## Run functional tests excluding Oracle (mssql + postgres only)
@$(DOCKER_RUN) make test-functional-light $(MAKEOVERRIDES)
test-oracle: stack-up-oracle ## Run Oracle functional tests only (on-demand, heavy)
@$(DOCKER_RUN) make test-oracle $(MAKEOVERRIDES)
include .make/help.mk
else
# ---- Devcontainer / in-docker path : exécution locale -----------------------
PIPUSER ?= 1
ifeq ($(OS),Windows_NT)
PYTHON ?= python.exe
VENV_BIN_DIR = Scripts
EXE_EXT = .exe
VENV_INIT = activate.bat
VENV_CMD = call
PATH_SEP = /
else
PYTHON ?= python3
VENV_BIN_DIR = bin
EXE_EXT =
VENV_INIT = activate
VENV_CMD = .
PATH_SEP = /
endif
VENV_BIN_DIR := .venv$(PATH_SEP)$(VENV_BIN_DIR)
VENV_ACTIVATE = $(VENV_CMD) $(VENV_BIN_DIR)$(PATH_SEP)$(VENV_INIT)
VENV_ACTIVATE_CMD := $(VENV_ACTIVATE) &&
TOX_EXE = $(VENV_BIN_DIR)$(PATH_SEP)tox$(EXE_EXT)
PRECOMMIT_EXE = $(VENV_BIN_DIR)$(PATH_SEP)pre-commit$(EXE_EXT)
ifeq ($(PIPUSER),1)
TOX_CMD = $(VENV_ACTIVATE_CMD) $(PYTHON) -m tox
else
TOX_CMD = tox
endif
ifeq ($(VERBOSE),1)
TOX_ARG := $(TOX_ARG) -v
endif
MNOPD = --no-print-directory
## -- Global makefile rules ---------------------------------------------------
all: | $(VENV_BIN_DIR) ## Setup local environment with pre-commit and tox
$(NOISE)env PATH="$(PROJECT_DIR)/.venv/$(VENV_BIN_DIR):$(PATH)" hash tox$(EXE_EXT) pre-commit$(EXE_EXT) > /dev/null 2>&1 || $(MAKE) $(MFLAGS) $(MNOPD) setup
pkgs: ## Generate pythong packages
$(NOISE)$(PYTHON) setup.py sdist
$(NOISE)$(PYTHON) setup.py bdist_wheel --universal
include .make/help.mk
## -- Setup -------------------------------------------------------------------
setup: $(TOX_EXE) $(PRECOMMIT_EXE) ## Setup local environment with pre-commit and tox
@$(call infomsg,"venv can be activate using $(VENV_ACTIVATE)")
$(TOX_EXE): | $(VENV_BIN_DIR)
$(call actionmsg, installing $@ ...)
$(NOISE)$(VENV_ACTIVATE_CMD) $(PYTHON) -m pip install $(basename $(@F))
$(PRECOMMIT_EXE): | $(VENV_BIN_DIR)
$(call actionmsg, installing $@ ...)
$(NOISE)$(VENV_ACTIVATE_CMD) $(PYTHON) -m pip install pre-commit
$(VENV_BIN_DIR):
$(NOISE)$(PYTHON) -m venv .venv
## -- Tox ---------------------------------------------------------------------
tox: | $(TOX_EXE) ## Execute specific tox environment using e parameter (ex. make tox e=py311)
$(NOISE)$(if $(e),,$(error e is required, e.g. 'make tox e=py311' — see tox.ini for env names))
$(NOISE)$(ECHO_CMD)$(TOX_CMD) -e $(e) $(TOX_ARG)
syntax: e=syntax ## Perform all formatting, styling and coding checks
syntax: tox
black: e=black ## Run black as code formatter
black: tox
isort: e=isort ## Run isort to review import order
isort: tox
mypy: e=mypy ## Run mypy as static typing checker
mypy: tox
flake8: e=flake8 ## Run flake8 as style guide checker
flake8: tox
pylint: e=pylint ## Run pylint as static code analyser
pylint: tox
cover: e=cover ## Run tests with coverage report (term + html)
cover: tox
doc: e=docs ## Generate documentation
doc: tox
## -- Testing -----------------------------------------------------------------
test: e=unit,cli ## Run all tests
test: tox
test-unit: e=unit ## Run unit tests
test-unit: tox
test-cli: e=cli ## Run cli tests
test-cli: tox
test-functional: e=functional ## Run functional tests (requires running mssql/oracle/postgres stack)
test-functional: tox
test-functional-light: e=functional-light ## Run functional tests excluding Oracle (requires mssql + postgres stack)
test-functional-light: tox
test-oracle: e=functional-oracle ## Run Oracle-only functional tests (requires Oracle container)
test-oracle: tox
endif