-
Notifications
You must be signed in to change notification settings - Fork 50
/
Makefile
107 lines (85 loc) · 2.81 KB
/
Makefile
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
SHELL=/bin/bash
# Prefer python 3.11 but take python3 if 3.11 is not installed
PYTHON := $(notdir $(shell for i in python3.11 python3; do command -v $$i; done|sed 1q))
CHECK_SYNTAX_FILES ?= .
RM ?= /bin/rm
UID := $(shell id -u)
TOX_ARGS ?= ""
COMPOSE_OPTS ?=
COMPOSE_UP_OPTS ?=
DOCKER_COMPOSE ?= docker compose
.PHONY: PYTHON_VERSION clean build\
check lint check_black check_flake8 check_isort git_hooks_config
PYTHON_VERSION:
@echo "$(subst python,,$(PYTHON))"
## Set the local git configuration(specific to this repo) to look for hooks in .githooks folder
git_hooks_config:
git config --local core.hooksPath .githooks
## Zero out all of the temp and build files
clean:
@-find . -type f -regex ".*\.py[co]$$" -print0 | xargs -0 $(RM) -f
@-find . -type d -name "__pycache__" -print0 \
-o -type d -name ".pytest_cache" -print0 | xargs -0 $(RM) -rf
# Test targets
# -------------------------------------
## Run test suite
check:
tox
## Run linters (and modify files if necessary)
lint:
tox -m lint
## Run black syntax check
check_black:
tox -e black -- --check $(CHECK_SYNTAX_FILES)
## Run flake8 syntax check
check_flake8:
tox -e flake8 -- $(CHECK_SYNTAX_FILES)
## Run isort syntax check
check_isort:
tox -e isort -- --check $(CHECK_SYNTAX_FILES)
## Starts a postgres container in the background if one is not running
# Options:
# -d, --detatch: run the container in background
# -q, --quiet: Surpress the pull output, mainly to condence output in CI
# --rm: automatically remove the container when it is stopped
postgres:
docker start dab_postgres || $(DOCKER_COMPOSE) up -d postgres --quiet-pull
## Stops the postgres container started with 'make postgres'
stop-postgres:
echo "Killing dab_postgres container"
$(DOCKER_COMPOSE) rm -fsv postgres
# Build targets
# --------------------------------------
# Build the library into /dist
build: git_hooks_config
python -m build .
# HELP related targets
# --------------------------------------
HELP_FILTER=.PHONY
## Display help targets
help:
@printf "Available targets:\n"
@$(MAKE) -s help/generate | grep -vE "\w($(HELP_FILTER))"
## Display help for all targets
help/all:
@printf "Available targets:\n"
@$(MAKE) -s help/generate
## Generate help output from MAKEFILE_LIST
help/generate:
@awk '/^[-a-zA-Z_0-9%:\\\.\/]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = $$1; \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
gsub("\\\\", "", helpCommand); \
gsub(":+$$", "", helpCommand); \
printf " \x1b[32;01m%-35s\x1b[0m %s\n", helpCommand, helpMessage; \
} else { \
helpCommand = $$1; \
gsub("\\\\", "", helpCommand); \
gsub(":+$$", "", helpCommand); \
printf " \x1b[32;01m%-35s\x1b[0m %s\n", helpCommand, "No help available"; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST) | sort -u
@printf "\n"