-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
399 lines (350 loc) · 12.9 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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
PYTHON_INTERPRETER=python3
VENV_PATH=.venv
FRONTEND_DIR=frontend
SANDBOX_DIR=sandbox
STATICFILES_DIR=$(SANDBOX_DIR)/static-sources
DJANGO_MANAGE_PATH=$(SANDBOX_DIR)/manage.py
PYTHON_BIN=$(VENV_PATH)/bin/python
PIP_BIN=$(VENV_PATH)/bin/pip
TOX_BIN=$(VENV_PATH)/bin/tox
TWINE_BIN=$(VENV_PATH)/bin/twine
DJANGO_MANAGE_BIN=$(PYTHON_BIN) $(DJANGO_MANAGE_PATH)
FLAKE_BIN=$(VENV_PATH)/bin/flake8
PYTEST_BIN=$(VENV_PATH)/bin/pytest
SPHINX_RELOAD_BIN=$(PYTHON_BIN) docs/sphinx_reload.py
DEMO_DJANGO_SECRET_KEY=samplesecretfordev
PACKAGE_NAME=cmsplugin-blocks
PACKAGE_SLUG=`echo $(PACKAGE_NAME) | tr '-' '_'`
APPLICATION_NAME=cmsplugin_blocks
# Formatting variables, FORMATRESET is always to be used last to close formatting
FORMATBLUE:=$(shell tput setab 4)
FORMATGREEN:=$(shell tput setab 2)
FORMATRED:=$(shell tput setab 1)
FORMATBOLD:=$(shell tput bold)
FORMATRESET:=$(shell tput sgr0)
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo
@echo " Cleaning"
@echo " ========"
@echo
@echo " clean -- to clean EVERYTHING (Warning)"
@echo " clean-var -- to clean data (uploaded medias, database, etc..)"
@echo " clean-doc -- to remove documentation builds"
@echo " clean-backend-install -- to clean backend installation"
@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
@echo " Installation"
@echo " ============"
@echo
@echo " install-backend -- to install backend requirements with Virtualenv and Pip"
@echo " install-frontend -- to install frontend requirements with Npm"
@echo " install -- to install backend and frontend"
@echo
@echo " Django commands"
@echo " ==============="
@echo
@echo " run -- to run Django development server"
@echo " migrate -- to apply demo database migrations"
@echo " migrations -- to create new migrations for application after changes"
@echo " superuser -- to create a superuser for Django admin"
@echo " po -- to update every PO files from app and sandbox sources for enabled languages"
@echo " mo -- to build MO files from app and sandbox PO files"
@echo
@echo " Frontend commands"
@echo " ================="
@echo
@echo " css -- to build uncompressed CSS from Sass sources"
@echo " icon-font -- to copy bootstrap-icons font to static"
@echo " watch-css -- to watch for Sass changes to rebuild CSS"
@echo " css-prod -- to build compressed and minified CSS from Sass sources"
@echo " js -- to build uncompressed Javascript from sources"
@echo " watch-js -- to watch for Javascript sources changes to rebuild assets"
@echo " js-prod -- to build minified JS assets"
@echo " frontend -- to build uncompressed frontend assets (CSS, JS, etc..)"
@echo " frontend-prod -- to build minified frontend assets (CSS, JS, etc..)"
@echo
@echo " Documentation"
@echo " ============="
@echo
@echo " docs -- to build documentation"
@echo " livedocs -- to run livereload server to rebuild documentation on source changes"
@echo
@echo " Quality"
@echo " ======="
@echo
@echo " flake -- to launch Flake8 checking"
@echo " test -- to launch base test suite using Pytest"
@echo " test-initial -- to launch tests with pytest and re-initialized database (for after new application or model changes)"
@echo " tox -- to launch tests for every Tox environments"
@echo " freeze-dependencies -- to write a frozen.txt file with installed dependencies versions"
@echo " quality -- to launch Flake8 checking and every tests suites"
@echo " check-migrations -- to check for pending migrations (do not write anything)"
@echo " check-django -- to run Django System check framework"
@echo " check-release -- to check package release before uploading it to PyPi"
@echo
@echo " Release"
@echo " ======="
@echo
@echo " release -- to release package for latest version on PyPi (once release has been pushed to repository)"
@echo
clean-pycache:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Clear Python cache <---$(FORMATRESET)\n"
@echo ""
rm -Rf .tox
rm -Rf .pytest_cache
find . -type d -name "__pycache__"|xargs rm -Rf
find . -name "*\.pyc"|xargs rm -f
.PHONY: clean-pycache
clean-var:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Cleaning var/ directory <---$(FORMATRESET)\n"
@echo ""
rm -Rf var
.PHONY: clean-var
clean-doc:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Clear documentation <---$(FORMATRESET)\n"
@echo ""
rm -Rf docs/_build
.PHONY: clean-doc
clean-backend-install:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Cleaning backend install <---$(FORMATRESET)\n"
@echo ""
rm -Rf $(PACKAGE_SLUG).egg-info
rm -Rf $(VENV_PATH)
.PHONY: clean-backend-install
clean-backend-build:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Cleaning backend built files <---$(FORMATRESET)\n"
@echo ""
rm -Rf dist
.PHONY: clean-backend-build
clean-frontend-install:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Cleaning frontend install <---$(FORMATRESET)\n"
@echo ""
rm -Rf $(FRONTEND_DIR)/node_modules
.PHONY: clean-frontend-install
clean-frontend-build:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Cleaning frontend built files <---$(FORMATRESET)\n"
@echo ""
rm -Rf $(STATICFILES_DIR)/webpack-stats.json
rm -Rf $(STATICFILES_DIR)/css
rm -Rf $(STATICFILES_DIR)/js
rm -Rf $(STATICFILES_DIR)/fonts
rm -Rf $(STATICFILES_DIR)/media
.PHONY: clean-frontend-build
clean: clean-var clean-doc clean-backend-install clean-backend-build clean-frontend-install clean-frontend-build clean-pycache
.PHONY: clean
venv:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Install virtual environment <---$(FORMATRESET)\n"
@echo ""
virtualenv -p $(PYTHON_INTERPRETER) $(VENV_PATH)
.PHONY: venv
create-var-dirs:
@mkdir -p var/db
@mkdir -p var/media
@mkdir -p var/static
@mkdir -p $(SANDBOX_DIR)/media
@mkdir -p $(STATICFILES_DIR)/fonts
.PHONY: create-var-dirs
icon-font:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Copying bootstrap-icons to staticfiles directory <---$(FORMATRESET)\n"
@echo ""
rm -Rf $(STATICFILES_DIR)/fonts/icons
cp -r $(FRONTEND_DIR)/node_modules/bootstrap-icons/font/fonts $(STATICFILES_DIR)/fonts/icons
.PHONY: icon-font
install-backend:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Installing backend requirements <---$(FORMATRESET)\n"
@echo ""
# Temporary: My SQLite verson is incompatible with DjangoCMS>=4 for now
#$(PIP_BIN) install psycopg2
# Temporary: My PostgreSQL is incompatible with Django>=5.1 for now
#$(PIP_BIN) install 'django>=5.0,<5.1'
$(PIP_BIN) install -e .[dev,quality,doc,doc-live,release]
.PHONY: install
install-frontend:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Installing frontend requirements <---$(FORMATRESET)\n"
@echo ""
cd $(FRONTEND_DIR) && npm install
${MAKE} icon-font
.PHONY: install-frontend
install: venv create-var-dirs install-backend migrate install-frontend frontend
.PHONY: install
migrations:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Making application migrations for application <---$(FORMATRESET)\n"
@echo ""
$(DJANGO_MANAGE_BIN) makemigrations $(APPLICATION_NAME)
.PHONY: migrations
migrate:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Apply pending migrations <---$(FORMATRESET)\n"
@echo ""
@DJANGO_SECRET_KEY=$(DEMO_DJANGO_SECRET_KEY) \
$(DJANGO_MANAGE_BIN) migrate
.PHONY: migrate
superuser:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Create new superuser <---$(FORMATRESET)\n"
@echo ""
@DJANGO_SECRET_KEY=$(DEMO_DJANGO_SECRET_KEY) \
$(DJANGO_MANAGE_BIN) createsuperuser
.PHONY: superuser
po:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Updating PO from application <---$(FORMATRESET)\n"
@echo ""
@cd $(APPLICATION_NAME); ../$(PYTHON_BIN) ../$(DJANGO_MANAGE_PATH) makemessages -a --keep-pot --no-obsolete
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Updating PO from sandbox <---$(FORMATRESET)\n"
@echo ""
@cd $(SANDBOX_DIR); ../$(PYTHON_BIN) ../$(DJANGO_MANAGE_PATH) makemessages -a --keep-pot --no-obsolete
.PHONY: po
mo:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Building MO from application <---$(FORMATRESET)\n"
@echo ""
@cd $(APPLICATION_NAME); ../$(PYTHON_BIN) ../$(DJANGO_MANAGE_PATH) compilemessages --verbosity 3
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Building MO from sandbox <---$(FORMATRESET)\n"
@echo ""
@cd $(SANDBOX_DIR); ../$(PYTHON_BIN) ../$(DJANGO_MANAGE_PATH) compilemessages --verbosity 3
.PHONY: mo
run:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Running development server <---$(FORMATRESET)\n"
@echo ""
@DJANGO_SECRET_KEY=$(DEMO_DJANGO_SECRET_KEY) \
$(DJANGO_MANAGE_BIN) runserver 0.0.0.0:8001
.PHONY: run
css:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Building CSS for development environment <---$(FORMATRESET)\n"
@echo ""
cd $(FRONTEND_DIR) && npm run-script css
.PHONY: css
watch-sass:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Watching Sass sources for development environment <---$(FORMATRESET)\n"
@echo ""
cd $(FRONTEND_DIR) && npm run-script watch-css
.PHONY: watch-sass
css-prod:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Building CSS for production environment <---$(FORMATRESET)\n"
@echo ""
cd $(FRONTEND_DIR) && npm run-script css-prod
.PHONY: css-prod
js:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Building distributed Javascript for development environment <---$(FORMATRESET)\n"
@echo ""
cd $(FRONTEND_DIR) && npm run js
.PHONY: js
watch-js:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Watching Javascript sources for development environment <---$(FORMATRESET)\n"
@echo ""
cd $(FRONTEND_DIR) && npm run watch-js
.PHONY: watch-js
js-prod:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Building distributed Javascript for production environment <---$(FORMATRESET)\n"
@echo ""
cd $(FRONTEND_DIR) && npm run js-prod
.PHONY: js-prod
frontend: css js
.PHONY: frontend
frontend-prod: css-prod js-prod
.PHONY: frontend-prod
docs:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Build documentation <---$(FORMATRESET)\n"
@echo ""
cd docs && make html
.PHONY: docs
livedocs:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Watching documentation sources <---$(FORMATRESET)\n"
@echo ""
$(SPHINX_RELOAD_BIN)
.PHONY: livedocs
check-django:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Running Django System check framework <---$(FORMATRESET)\n"
@echo ""
$(DJANGO_MANAGE_BIN) check
.PHONY: check-django
check-migrations:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Checking for pending project applications models migrations <---$(FORMATRESET)\n"
@echo ""
$(DJANGO_MANAGE_BIN) makemigrations --check --dry-run -v 3
.PHONY: check-migrations
flake:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Running Flake check <---$(FORMATRESET)\n"
@echo ""
$(FLAKE_BIN) --statistics --show-source $(APPLICATION_NAME) sandbox tests
.PHONY: flake
test:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Running Tests <---$(FORMATRESET)\n"
@echo ""
$(PYTEST_BIN) --reuse-db tests/
rm -Rf var/media-tests/
.PHONY: test
test-initial:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Running Tests from zero <---$(FORMATRESET)\n"
@echo ""
$(PYTEST_BIN) --reuse-db --create-db tests/
rm -Rf var/media-tests/
.PHONY: test-initial
freeze-dependencies:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Freezing backend dependencies versions <---$(FORMATRESET)\n"
@echo ""
$(PYTHON_BIN) freezer.py ${PACKAGE_NAME} --destination=frozen.txt
.PHONY: freeze-dependencies
tox:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Launching tests with Tox environments <---$(FORMATRESET)\n"
@echo ""
$(TOX_BIN)
.PHONY: tox
build-package:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Building package <---$(FORMATRESET)\n"
@echo ""
rm -Rf dist
$(PYTHON_BIN) setup.py sdist
.PHONY: build-package
release: build-package
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Releasing <---$(FORMATRESET)\n"
@echo ""
$(TWINE_BIN) upload dist/*
.PHONY: release
check-release: build-package
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Checking package <---$(FORMATRESET)\n"
@echo ""
$(TWINE_BIN) check dist/*
.PHONY: check-release
quality: flake check-migrations test-initial docs check-release freeze-dependencies
@echo ""
@echo "♥ ♥ Everything should be fine ♥ ♥"
@echo ""
.PHONY: quality