-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
214 lines (147 loc) · 5.7 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
SHELL=/bin/bash
.DEFAULT_GOAL := help
PROJECT_SLUG=commonslibrary
# ---------------------------------
# Project specific targets
# ---------------------------------
#
# Add any targets specific to the current project in here.
# -------------------------------
# Common targets for Dev projects
# -------------------------------
#
# Edit these targets so they work as expected on the current project.
#
# Remember there may be other tools which use these targets, so if a target is not suitable for
# the current project, then keep the target and simply make it do nothing.
help: ## This help dialog.
help: help-display
nuke: ## Full wipe of the local environment, uncommitted files, and database.
nuke: venv-check venv-wipe git-full-clean database-drop
reset: ## Reset your local environment. Useful after switching branches, etc.
reset: venv-check venv-wipe install-local fab-get-backup django-migrate django-user-passwords django-dev-createsuperuser
full-reset: ## Reset your local environment and download all media files.
full-reset: venv-check venv-wipe install-local fab-get-data django-migrate django-user-passwords django-dev-createsuperuser
clear: ## Like reset but without the wiping of the installs.
clear: fab-get-backup django-migrate django-user-passwords django-dev-createsuperuser
full-clear: ## Fresh download of remotely stored data including media files.
full-clear: fab-get-data django-migrate django-user-passwords django-dev-createsuperuser
check: ## Check for any obvious errors in the project's setup.
check: pipdeptree-check npm-check django-check
format: ## Run this project's code formatters.
format: yapf-format isort-format prettier-format
lint: ## Lint the project.
lint: npm-install yapf-lint isort-lint flake8-lint eslint-lint prettier-lint
test: ## Run unit and integration tests.
test: django-test
test-report: ## Run and report on unit and integration tests.
test-report: coverage-clean test coverage-report
deploy: ## Deploy this project to demo or live.
deploy: fab-deploy
# ---------------
# Utility targets
# ---------------
#
# Targets which are used by the common targets. You likely want to customise these per project,
# to ensure they're pointing at the correct directories, etc.
# Virtual Environments
venv-check:
ifndef VIRTUAL_ENV
$(error Must be in a virtualenv)
endif
venv-wipe: venv-check
if ! pip list --format=freeze | grep -v "^pip=\|^setuptools=\|^wheel=" | xargs pip uninstall -y; then \
echo "Nothing to remove"; \
fi
# Git
git-full-clean:
git clean -ffdx
# Database
database-drop:
dropdb --if-exists ${PROJECT_SLUG}_django
# Installs
install-local: npm-install pip-install-local
# Pip
pip-install-local: venv-check
pip install setuptools==59.8.0
pip install -r requirements/local.txt
# Fabfile
fab-get-data: fab-get-backup fab-get-media
fab-get-backup:
fab get_backup
fab-get-media:
fab get_media
fab-deploy:
fab deploy
# ISort
isort-lint:
isort --recursive --check-only --diff commonslibrary apps
isort-format:
isort --recursive commonslibrary apps
# Flake8
flake8-lint:
flake8 commonslibrary apps
# Coverage
coverage-report: coverage-html coverage-xml
coverage report --show-missing
coverage-html:
coverage html
coverage-xml:
coverage xml
coverage-clean:
rm -rf htmlcov
rm -rf reports
rm -f .coverage
# Django
django-check: django-check-missing-migrations django-check-validate-templates
django-test: django-collectstatic
coverage run --include="apps/*" ./manage.py test --noinput . apps
django-check-missing-migrations:
./manage.py makemigrations --settings=commonslibrary.settings.migrations --check --dry-run
django-collectstatic:
./manage.py collectstatic --verbosity 0 --noinput
django-check-validate-templates:
./manage.py validate_templates --verbosity 0
django-dev-createsuperuser: DJANGO_DEV_USERNAME ?= _dev@dev.ngo
django-dev-createsuperuser: DJANGO_DEV_PASSWORD ?= password
django-dev-createsuperuser: DJANGO_DEV_EMAIL ?= _dev@dev.ngo
django-dev-createsuperuser: DJANGO_DEV_FIRST_NAME ?= _dev
django-dev-createsuperuser: DJANGO_DEV_LAST_NAME ?= _dev
django-dev-createsuperuser:
@echo "import sys; from django.contrib.auth import get_user_model; obj = get_user_model().objects.create_superuser('$(DJANGO_DEV_EMAIL)', '$(DJANGO_DEV_FIRST_NAME)', '$(DJANGO_DEV_LAST_NAME)', '$(DJANGO_DEV_PASSWORD)');" | python manage.py shell >> /dev/null
@echo
@echo "Superuser details: "
@echo
@echo " $(DJANGO_DEV_USERNAME):$(DJANGO_DEV_PASSWORD)"
@echo
django-user-passwords: DJANGO_USER_PASSWORD ?= password
django-user-passwords:
@echo "from django.contrib.auth.hashers import make_password; from django.contrib.auth import get_user_model; get_user_model().objects.update(password=make_password('$(DJANGO_USER_PASSWORD)'));" | python manage.py shell >> /dev/null
django-migrate:
./manage.py migrate
# NPM
npm-check: npm-install npm-run-production
npm-install:
cmp --silent package-lock.json node_modules/.package-lock.json || npm ci && cp -a package-lock.json node_modules/.package-lock.json
npm-run-production:
npm run production
# ESLint
eslint-lint:
npm run eslint -- static/src/js
# Prettier
prettier-lint:
npm run prettier --silent -- --list-different "static/src/{js,scss}/**" "*.js"
prettier-format:
npm run prettier --silent -- --write "static/src/{js,scss}/**" "*.js"
# YAPF
yapf-lint:
yapf_lint_output="`yapf -r -p -d --exclude="*/migrations/*.py" --style .style.yapf commonslibrary apps`" && \
if [[ $$yapf_lint_output ]]; then echo -e "$$yapf_lint_output"; exit 1; fi
yapf-format:
yapf -r -i -p --exclude="*/migrations/*.py" --style .style.yapf commonslibrary apps
#pipdeptree
pipdeptree-check:
pipdeptree --warn fail > /dev/null
# Help
help-display:
@awk '/^[[:alnum:]-]*: ##/ { split($$0, x, "##"); printf "%20s%s\n", x[1], x[2]; }' $(MAKEFILE_LIST)