-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
254 lines (219 loc) · 7.68 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
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
VENV_PATH=.venv
VENV_BIN=$(VENV_PATH)/bin
PYTHON_INTERPRETER=python3
PYTHON_BIN=$(VENV_BIN)/python
PIP=$(VENV_BIN)/pip
DJANGO_MANAGE=$(VENV_BIN)/python manage.py
FLAKE=$(VENV_BIN)/flake8
BLACK=$(VENV_BIN)/black
DJANGOPROJECT_DIR=main
DJANGO_SETTINGS=main.settings.local
STATICFILES_DIR=$(DJANGOPROJECT_DIR)/webapp_statics
FRONTEND_DIR=frontend
NPM=npm
# Formatting variables, FORMATRESET is always to be used last to close formatting
FORMATBLUE:=$(shell tput setab 4)
FORMATBOLD:=$(shell tput bold)
FORMATRESET:=$(shell tput sgr0)
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo
@echo " install-backend -- to install backend requirements with Virtualenv and Pip"
@echo " install-frontend -- to install frontend requirements with Npm"
@echo " install-pycheck -- to install globally Pycheck (WARNING: Have to install/clean manually)"
@echo " install -- to install backend and frontend"
@echo
@echo " clean -- to clean EVERYTHING (WARNING: you cannot recovery from this)"
@echo " clean-backend-install -- to clean backend installation"
@echo " clean-db -- to clean db files"
@echo " clean-frontend-install -- to clean frontend installation"
@echo " clean-frontend-build -- to clean frontend built files"
@echo " clean-pycache -- to remove all __pycache__, this is recursive from current directory"
@echo " clean-pycheck -- to remove Pycheck installation"
@echo
@echo " run -- to run Django development server"
@echo " check-migrations -- to check for pending application migrations (do not write anything)"
@echo " migrate -- to apply database migrations"
@echo " migrations -- to create database migrations"
@echo " superuser -- to create a superuser for Django admin"
@echo " shell -- to open a Django shell"
@echo
@echo " test -- run the unit tests"
@echo
@echo " build-front -- to build the frontend for production"
@echo " front -- to run the frontend in dev mode with watch autoreload"
@echo " netfront -- to run the frontend in dev network mode with watch autoreload"
@echo
@echo " check -- to run the check management command"
@echo " flake -- to launch Flake8 checking"
@echo " format -- to launch Black formating"
@echo " dryformat -- to launch Black formating in dry mode"
@echo " pycheck -- to launch Pycheck code checks"
@echo " quality -- to launch all quality checks"
@echo
@echo " doc -- to build the documentation from docstrings"
@echo
clean-pycache:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Clear Python cache <---$(FORMATRESET)\n"
@echo ""
rm -Rf .pytest_cache
find . -type d -name "__pycache__"|xargs rm -Rf
find . -name "*\.pyc"|xargs rm -f
.PHONY: clean-pycache
clean-backend-install:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Cleaning backend install <---$(FORMATRESET)\n"
@echo ""
rm -Rf $(VENV_PATH)
.PHONY: clean-backend-install
clean-db:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Cleaning db files <---$(FORMATRESET)\n"
@echo ""
rm -Rf db.sqlite3
.PHONY: clean-db
clean-frontend-build:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Cleaning frontend built files <---$(FORMATRESET)\n"
@echo ""
rm -Rf $(STATICFILES_DIR)/frontend/assets/*
.PHONY: clean-frontend-build
clean-frontend-install:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Cleaning frontend install <---$(FORMATRESET)\n"
@echo ""
rm -Rf $(FRONTEND_DIR)/node_modules
rm -Rf $(FRONTEND_DIR)/yarn.lock
.PHONY: clean-frontend-install
clean: clean-backend-install clean-db clean-frontend-install clean-frontend-build clean-pycache
.PHONY: clean
clean-pycheck:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Cleaning Pycheck installation <---$(FORMATRESET)\n"
@echo ""
$(NPM) uninstall -g @pycheck/cli
$(NPM) uninstall -g @pycheck/ui
rm -Rf yarn.lock
rm -Rf package.json
rm -Rf node_modules
install-pycheck:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Installing Pycheck <---$(FORMATRESET)\n"
@echo ""
$(NPM) i -g @pycheck/cli
$(NPM) i -g @pycheck/ui
venv:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Install virtual environment <---$(FORMATRESET)\n"
@echo ""
$(PYTHON_INTERPRETER) -m venv $(VENV_PATH)
# This is required for those ones using old distribution
$(PIP) install --upgrade pip
$(PIP) install --upgrade setuptools
.PHONY: venv
install-backend:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Installing backend requirements <---$(FORMATRESET)\n"
@echo ""
$(PIP) install -r requirements/dev.txt
.PHONY: install-backend
install-frontend:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Installing frontend requirements <---$(FORMATRESET)\n"
@echo ""
cd $(FRONTEND_DIR) && $(NPM) install
.PHONY: install-frontend
install: venv install-backend migrate install-frontend
.PHONY: install
shell:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Open a Django shell <---$(FORMATRESET)\n"
@echo ""
$(DJANGO_MANAGE) shell
.PHONY: shell
check-migrations:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Checking for pending project applications models migrations <---$(FORMATRESET)\n"
@echo ""
$(DJANGO_MANAGE) makemigrations --check --dry-run -v 3
.PHONY: check-migrations
migrations:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Apply pending migrations <---$(FORMATRESET)\n"
@echo ""
$(DJANGO_MANAGE) makemigrations
.PHONY: migrations
migrate:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Apply pending migrations <---$(FORMATRESET)\n"
@echo ""
$(DJANGO_MANAGE) migrate
.PHONY: migrate
superuser:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Create a new superuser <---$(FORMATRESET)\n"
@echo ""
$(DJANGO_MANAGE) createsuperuser
.PHONY: superuser
run:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Running the backend development server <---$(FORMATRESET)\n"
@echo ""
$(DJANGO_MANAGE) runserver 8000 --settings=${DJANGO_SETTINGS}
.PHONY: run
build-front:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Building the frontend <---$(FORMATRESET)\n"
@echo ""
cd $(FRONTEND_DIR) && $(NPM) run build
.PHONY: build-front
front:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Running the frontend in dev mode <---$(FORMATRESET)\n"
@echo ""
cd $(FRONTEND_DIR) && $(NPM) run dev
.PHONY: front
netfront:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Running the frontend in dev network mode <---$(FORMATRESET)\n"
@echo ""
cd $(FRONTEND_DIR) && $(NPM) run net
.PHONY: front
test:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Run the tests <---$(FORMATRESET)\n"
@echo ""
$(PYTHON_BIN) -m pytest --capture=no
.PHONY: test
check:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Run the manage check command <---$(FORMATRESET)\n"
@echo ""
$(DJANGO_MANAGE) check
.PHONY: check
format:
$(BLACK) --extend-exclude='/*/migrations/*|setup.py' .
.PHONY: format
dryformat:
$(BLACK) --extend-exclude='/*/migrations/*|setup.py' --check .
.PHONY: dryformat
pycheck:
pycheck --django
.PHONY: pycheck
flake:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Flake <---$(FORMATRESET)\n"
@echo ""
$(FLAKE) --statistics --show-source $(DJANGOPROJECT_DIR) apps/
.PHONY: flake
quality: check-migrations pycheck
@echo ""
@echo "Running quality checks"
@echo ""
.PHONY: quality
doc:
@echo ""
@echo "Building the doc from docstrings"
$(DJANGO_MANAGE) build_doc
.PHONY: doc