This repository has been archived by the owner on Mar 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
238 lines (208 loc) · 7.08 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
PYTHON_INTERPRETER=python3
VENV_PATH=.venv
SANDBOX_DIR=contact_form
STATICFILES_DIR=$(SANDBOX_DIR)/static
PYTHON_BIN=$(VENV_PATH)/bin/python
PIP_BIN=$(VENV_PATH)/bin/pip
FLAKE_BIN=$(VENV_PATH)/bin/flake8
PYTEST_BIN=$(VENV_PATH)/bin/pytest
TOX_BIN=$(VENV_PATH)/bin/tox
TWINE_BIN=$(VENV_PATH)/bin/twine
DJANGO_MANAGE=manage.py
PACKAGE_NAME=emencia-contact-form-maintenance
PACKAGE_SLUG=emencia_contact_form_maintenance
APPLICATION_NAME=emencia_contact_form
# 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> [<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-backend-install -- to clean Python side installation"
@echo " clean-pycache -- to recursively remove all Python cache files"
@echo
@echo " Installation"
@echo " ============"
@echo
@echo " install -- to install this project with virtualenv and Pip"
@echo
@echo " Django commands"
@echo " ==============="
@echo
@echo " run -- to run Django development server"
@echo " check-migrations -- to check for pending application migrations (do not write anything)"
@echo " migrations -- to create new migrations for application after changes"
@echo " migrate -- to apply demo database migrations"
@echo " superuser -- to create a superuser for Django admin"
@echo " po -- to update every PO files from application for enabled languages"
@echo " mo -- to build MO files from application PO files"
@echo
@echo " Quality"
@echo " ======="
@echo
@echo " check-release -- to check package release before uploading it to PyPi"
@echo " flake -- to launch Flake8 checking"
@echo " quality -- to launch run quality tasks and checks"
@echo " test -- to launch base test suite using Pytest"
@echo " test-initial -- to launch base test suite using Pytest and re-initialized database"
@echo " tox -- to launch tests for every Tox environments"
@echo
@echo " Release"
@echo " ======="
@echo
@echo " release -- to release latest package version on PyPi"
@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)---> Clear installation <---$(FORMATRESET)\n"
@echo ""
rm -Rf $(VENV_PATH)
rm -Rf $(PACKAGE_SLUG).egg-info
.PHONY: clean-install
clean-var:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Clear 'var/' directory <---$(FORMATRESET)\n"
@echo ""
rm -Rf var
.PHONY: clean-var
clean: clean-var clean-backend-install clean-pycache
.PHONY: clean
create-var-dirs:
@mkdir -p var/db
@mkdir -p var/static/css
@mkdir -p var/media
@mkdir -p $(SANDBOX_DIR)/media
@mkdir -p $(STATICFILES_DIR)/css
.PHONY: create-var-dirs
venv:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Install virtual environment <---$(FORMATRESET)\n"
@echo ""
virtualenv -p $(PYTHON_INTERPRETER) $(VENV_PATH)
.PHONY: venv
install-backend:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Install everything for development <---$(FORMATRESET)\n"
@echo ""
$(PIP_BIN) install -r requirements.txt
$(PIP_BIN) install twine
$(PIP_BIN) install -e .
.PHONY: install-backend
install: venv create-var-dirs install-backend migrate
.PHONY: install
check-django:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Running Django System check <---$(FORMATRESET)\n"
@echo ""
$(PYTHON_BIN) $(DJANGO_MANAGE) check
.PHONY: check-django
migrations:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Making application migrations <---$(FORMATRESET)\n"
@echo ""
$(PYTHON_BIN) $(DJANGO_MANAGE) makemigrations $(APPLICATION_NAME)
.PHONY: migrations
check-migrations:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Checking for pending backend model migrations <---$(FORMATRESET)\n"
@echo ""
$(PYTHON_BIN) $(DJANGO_MANAGE) makemigrations --dry-run -v 3 $(APPLICATION_NAME)
$(PYTHON_BIN) $(DJANGO_MANAGE) makemigrations --check -v 3 $(APPLICATION_NAME)
.PHONY: check-migrations
migrate:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Apply pending migrations <---$(FORMATRESET)\n"
@echo ""
$(PYTHON_BIN) $(DJANGO_MANAGE) migrate
.PHONY: migrate
superuser:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Create new superuser <---$(FORMATRESET)\n"
@echo ""
$(PYTHON_BIN) $(DJANGO_MANAGE) createsuperuser
.PHONY: superuser
run:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Running development server <---$(FORMATRESET)\n"
@echo ""
$(PYTHON_BIN) $(DJANGO_MANAGE) runserver 0.0.0.0:8001
.PHONY: run
po:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Updating PO from application <---$(FORMATRESET)\n"
@echo ""
@cd $(APPLICATION_NAME); ../$(PYTHON_BIN) ../$(DJANGO_MANAGE) 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) compilemessages --verbosity 3
.PHONY: mo
flake:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Flake <---$(FORMATRESET)\n"
@echo ""
$(FLAKE_BIN) --statistics --show-source $(APPLICATION_NAME)
.PHONY: flake
test:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Tests <---$(FORMATRESET)\n"
@echo ""
$(PYTEST_BIN) -vv $(APPLICATION_NAME)/tests/
rm -Rf var/media-tests/
.PHONY: test
test-initial:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Tests from zero <---$(FORMATRESET)\n"
@echo ""
$(PYTEST_BIN) -vv --reuse-db --create-db $(APPLICATION_NAME)/tests/
rm -Rf var/media-tests/
.PHONY: test-initial
build-package:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Build package <---$(FORMATRESET)\n"
@echo ""
rm -Rf dist
$(VENV_PATH)/bin/python setup.py sdist
.PHONY: build-package
release: build-package
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Release package <---$(FORMATRESET)\n"
@echo ""
$(TWINE_BIN) upload dist/*
.PHONY: release
check-release: build-package
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Check package <---$(FORMATRESET)\n"
@echo ""
$(TWINE_BIN) check dist/*
.PHONY: check-release
tox:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Launch all Tox environments <---$(FORMATRESET)\n"
@echo ""
$(TOX_BIN)
.PHONY: tox
quality: check-django check-migrations test-initial flake docs check-release
@echo ""
@printf "$(FORMATGREEN)$(FORMATBOLD) ♥ ♥ Everything should be fine ♥ ♥ $(FORMATRESET)\n"
@echo ""
@echo ""
.PHONY: quality