generated from timoguin/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
135 lines (114 loc) · 4.94 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
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
DEPS ?=awk docker grep poetry realpath sed
AWS_OKTA_PROFILE ?=
PY_INSTALL_ARGS ?=--extras="all" --with="docs"
VENV_DIR ?=.venv
CMD ?=/bin/bash
DEBUG ?=false
PYTHONBREAKPOINT ?=ipdb.set_trace
ifeq (${DEBUG},true)
export PYTHONBREAKPOINT
else
export PYTHONBREAKPOINT=0
endif
ifneq (${AWS_OKTA_PROFILE},)
SHELL_CMD_PREFIX =aws-okta exec ${AWS_OKTA_PROFILE} --
endif
.PHONY: default
default: help
.PHONY: shell ## Activate the Python virtual environment in a subshell
shell: ${VENV_DIR}
@${SHELL_CMD_PREFIX} poetry shell --quiet --no-interaction
.PHONY: shellcmd ## Run a command (CMD arg)in the activated Python venv
shellcmd: ${VENV_DIR}
@${SHELL_CMD_PREFIX} /bin/bash -c "poetry run ${CMD}"
.PHONY: lint ## Run code linting
lint: ${VENV_DIR}
@echo "Running the black code formatter"
@poetry run black ${ARGS} .
# flakehell currently disabled, see .pre-commit-config.yaml notesk
# @echo "Running flakehell plugins"
# @poetry run flakehell lint aws_data_tools
.PHONY: lint-docs ## Run docs linting
lint-docs: ${VENV_DIR}
@echo "Running blacken code formatter for Markdown code blocks"
@poetry run blacken-docs *.md
.PHONY: test-integration ## Run the integration test suite
test-integration: run-test-server
@printf "${OK}%s...\n${CCEND}" "Starting motoserver"
@docker --log-level ERROR compose up --detach >/dev/null
@pushd tests >/dev/null && ./test.sh && popd >/dev/null || popd >/dev/null
.PHONY: run-test-server ## Start motoserver with docker compose if it's not running
run-test-server:
@CONTAINER_ID=$$(docker compose ps --quiet motoserver 2>/dev/null); \
CONTAINER_START=0; \
if [ "$$CONTAINER_ID" != "" ]; then \
if ! $$(docker ps --quiet --no-trunc | grep --quiet "$$CONTAINER_ID"); then \
CONTAINER_START=1; \
fi; \
else \
CONTAINER_START=1; \
fi; \
if [ $$CONTAINER_START -eq 1 ]; then \
docker compose up --detach --no-recreate --remove-orphans; \
fi
.PHONY: stop-test-server ## Stop motoserver container(s)
stop-test-server:
@docker compose down --remove-orphans --volumes
.PHONY: build ## Build the Python package for distribution
build: ${VENV_DIR}
@echo "Building the Python package"
@poetry build --quiet --no-interaction
.PHONY: test ## Run the test suite
test: ${VENV_DIR}
@echo "Running test suite"
@poetry run pytest --cov ${OPTS} ${ARGS}
# Ensures the Python venv exists and has dependencies installed
${VENV_DIR}:
@python -m venv ${VENV_DIR} >/dev/null
@${VENV_DIR}/bin/pip install --quiet --upgrade pip
@make python-install-deps
.PHONY: python-install-deps ## Install Python dependencies in the venv
python-install-deps: ${VENV_DIR}
@poetry install --quiet --no-interaction ${PY_INSTALL_ARGS}
.PHONY: python-update-deps ## Update Python dependencies in the venv
python-update-deps: ${VENV_DIR}
@poetry update --quiet --no-interaction
.PHONY: python-update-lock ## Update Python dependency lock file
python-update-lock:
@poetry update --quiet --no-interaction --lock
.PHONY: clean ## Remove temp files and build artifacts
clean:
@find . -path ./${VENV_DIR} -prune -false -o -type f -iname '*.pyc' -delete
@find . -path ./${VENV_DIR} -prune -false -o \
-type d \( -name 'dist' -o -name '__pycache__' \) \
-exec rm -rf "{}" +
@poetry install --remove-untracked --quiet
.PHONY: clean-all ## Run clean, remove the Python venv and untracked / ignored Git files
clean-all: clean
@git clean --quiet --force -d -f -x
@docker compose down --rmi 'all' --volumes --remove-orphans
.PHONY: help
help:
@echo "Available commands:"
@echo
@cat Makefile \
| grep -E '^\.PHONY: [a-zA-Z_-]+ ## .*$$' \
| sed 's/^\.PHONY: //' \
| awk 'BEGIN {FS = " ## "}; {printf "\033[36mmake %-30s\033[0m %s\n", $$1, $$2}'
@echo
.PHONY: deps ## Check that dependencies are installed
deps:
@deps_not_found=; \
for dep in ${DEPS}; do \
if ! command -v $$dep &> /dev/null; then deps_not_found+="$$dep "; fi; \
done; \
if [ "$$deps_not_found" != "" ]; then \
printf "${ERROR}%s${CCEND}\n" \
"This script has unmet dependencies: $$deps_not_found"; \
exit 1; \
fi
# Colors
OK ="\\033[32m"
WARN ="\\033[33m"
ERROR ="\\033[31m"
CCEND ="\\033[0m"