-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
135 lines (109 loc) Β· 4.23 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
PY=python3
VENV=venv
BIN=$(VENV)/bin
PYTHON=$(BIN)/python
# -------------------------------------------------------------------
# Development-related commands
# Run commands inside virtualenv - https://earthly.dev/blog/python-makefile/
# -------------------------------------------------------------------
$(VENV)/bin/activate: requirements.txt
$(PY) -m venv $(VENV)
@echo "\n\033[1;36m[2/3] Upgrading pip and installing requirements π§ π¦ π§ \033[0m\n"
$(PYTHON) -m pip install --upgrade pip
$(BIN)/pip install -r requirements.txt
install-django: $(VENV)/bin/activate
@echo "\033[1;37m---- Installing Django π ---- \033[0m\n"
$(PYTHON) -m pip install Django~=3.2.7
# -------------------------------------------------------------------
# Local development-related commands
# -------------------------------------------------------------------
## @(development) - Run the example app
run-example: install-django
@echo "\033[1;37m---- Running migrations π ---- \033[0m\n"
$(PYTHON) example/manage.py migrate --noinput --settings=example.project.settings
@echo "\n\033[1;37m---- Loading fixtures π½ ---- \033[0m\n"
$(PYTHON) example/manage.py loaddata fake_data.json --settings=example.project.settings
@echo "\n\033[1;37m---- Running server πββοΈ ---- \033[0m\n"
$(PYTHON) example/manage.py runserver --settings=example.project.settings
## @(development) - Run tests with coverage and make reports
coverage: install-django
@echo "\033[1;37m---- Running unittests π§ͺβ¨ ---- \033[0m\n"
DJANGO_SETTINGS_MODULE=tests.settings \
$(BIN)/coverage run -m django test && $(BIN)/coverage report
$(BIN)/coverage html
$(BIN)/coverage xml
## @(development) - Run linting and formatting checks
lint: $(VENV)/bin/activate
@echo "\n\033[1;36m[1/4] Running pycln check π» π§Ή π»\033[0m\n"
$(BIN)/pycln . --config pyproject.toml -vc
@echo "\n\033[1;36m[2/4] Running isort check π π π\033[0m\n"
$(BIN)/isort . -vc
@echo "\n\033[1;36m[3/4] Running black check π€ π₯ π€\033[0m\n"
$(BIN)/black . -v --check
@echo "\n\033[1;36m[4/4] Running flake8 π₯Ά π¦ π₯Ά\033[0m\n"
$(BIN)/flake8 .
## @(development) - Run linting and formatting
format: $(VENV)/bin/activate
@echo "\n\033[1;36m[1/4] Running pycln π» π§Ή π»\033[0m\n"
$(BIN)/pycln . --config pyproject.toml -v
@echo "\n\033[1;36m[2/4] Running isort π π π\033[0m\n"
$(BIN)/isort . -v
@echo "\n\033[1;36m[3/4] Running black π€ π₯ π€\033[0m\n"
$(BIN)/black . -v
@echo "\n\033[1;36m[4/4] Running flake8 π₯Ά π¦ π₯Ά\033[0m\n"
$(BIN)/flake8 .
# -------------------------------------------------------------------
# Misc. commands
# -------------------------------------------------------------------
## @(misc) - Remove cached files and dirs from workspace
clean:
@echo "\033[1;37m---- Cleaning workspace π§Ήπ¨ ----\033[0m\n"
find . -type f -name "*.pyc" -delete
find . -type d -name "__pycache__" -delete
find . -type f -name "*.DS_Store" -delete
## @(misc) - Remove virtualenv directory
rm-venv:
@echo "\033[1;37m---- Removing virtualenv π π§Ήπ¨ ----\033[0m\n"
rm -rf $(VENV)
# -------------------------------------------------------------------
# Self-documenting Makefile targets - https://git.io/Jg3bU
# -------------------------------------------------------------------
.DEFAULT_GOAL := help
help:
@echo "Usage:"
@echo " make <target>"
@echo ""
@echo "Targets:"
@awk '/^[a-zA-Z\-\_0-9]+:/ \
{ \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
helpGroup = match(helpMessage, /^@([^ ]*)/); \
if (helpGroup) { \
helpGroup = substr(helpMessage, RSTART + 1, index(helpMessage, " ")-2); \
helpMessage = substr(helpMessage, index(helpMessage, " ")+1); \
} \
printf "%s| %-18s %s\n", \
helpGroup, helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' \
$(MAKEFILE_LIST) \
| sort -t'|' -sk1,1 \
| awk -F '|' ' \
{ \
cat = $$1; \
if (cat != lastCat || lastCat == "") { \
if ( cat == "0" ) { \
print "\nTargets:" \
} else { \
gsub("_", " ", cat); \
printf "\n%s\n", cat; \
} \
} \
print $$2 \
} \
{ lastCat = $$1 }'
@echo ""