This repository has been archived by the owner on May 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
218 lines (194 loc) · 6.16 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
# Copyright (C) 2021 Serghei Iakovlev <egrep@protonmail.ch>
#
# This file is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this file. If not, see <https://www.gnu.org/licenses/>.
include default.mk
define mk-venv-link
@if [ -n "$(WORKON_HOME)" ] ; then \
echo $(ROOT_DIR) > $(VENV_ROOT)/.project; \
if [ ! -d $(WORKON_HOME)/$(PKG_NAME) -a ! -L $(WORKON_HOME)/$(PKG_NAME) ]; \
then \
ln -s $(ROOT_DIR)/$(VENV_ROOT) $(WORKON_HOME)/$(PKG_NAME); \
echo ; \
echo Since you use virtualenvwrapper, we created a symlink; \
echo "so you can also use \"workon $(PKG_NAME)\" to activate the venv."; \
echo ; \
fi; \
fi
endef
define rm-venv-link
@if [ -n "$(WORKON_HOME)" ]; then \
if [ -L "$(WORKON_HOME)/$(PKG_NAME)" -a -f "$(WORKON_HOME)/$(PKG_NAME)" ]; \
then \
$(RM) $(WORKON_HOME)/$(PKG_NAME); \
fi; \
fi
endef
requirements/%.txt: requirements/%.in $(VENV_BIN)
$(VENV_BIN)/pip-compile --output-file=$@ $<
build.py: $(VENV_PYTHON)
@echo $(CS)Generate project-wide constants$(CE)
$(VENV_PYTHON) manage.py create_build_id
## Public targets
$(VENV_PYTHON): $(VENV_ROOT)
@echo
$(VENV_ROOT):
@echo $(CS)Creating a Python environment $(VENV_ROOT)$(CE)
$(PYTHON) -m venv --prompt $(PKG_NAME) $(VENV_ROOT)
@echo
@echo Done.
@echo
@echo To active it manually, run:
@echo
@echo " source $(VENV_BIN)/activate"
@echo
@echo See https://docs.python.org/3/library/venv.html for more.
@echo
$(call mk-venv-link)
.PHONY: init
init: $(VENV_PYTHON)
@echo $(CS)Set up virtualenv$(CE)
$(VENV_PIP) install --progress-bar=off --upgrade pip pip-tools setuptools wheel
@echo
.PHONY: install
install: $(REQUIREMENTS)
@echo $(CS)Installing $(PKG_NAME) and all its dependencies$(CE)
$(VENV_PIP) install -U -r requirements/requirements-dev.txt
$(VENV_PIP) install -U -r requirements/requirements.txt
$(VENV_PIP) install --progress-bar=off -e .
$(VENV_PIP) install --progress-bar=off --upgrade twine check-manifest check-wheel-contents
$(NPM) install
@echo
.PHONY: clean
clean:
@echo $(CS)Remove build and tests artefacts and directories$(CE)
$(call rm-venv-link)
find ./ -name '__pycache__' -delete -o -name '*.pyc' -delete
$(RM) -r ./build ./dist ./*.egg-info
$(RM) -r ./node_modules
$(RM) -r ./.cache ./.pytest_cache
$(RM) -r ./storage/coverage/htmlcov
$(RM) ./storage/coverage/coverage.*
$(RM) ./storage/logs/*.log
$(RM) ./storage/pids/*.pid
@echo
.PHONY: maintainer-clean
maintainer-clean: clean
@echo $(CS)Performing full clean$(CE)
-$(RM) -r $(VENV_ROOT)
$(call rm-venv-link)
$(RM) ./build.py
$(RM) requirements/*.txt
@echo
.PHONY: lint
lint: $(VENV_PYTHON)
@echo $(CS)Running linters$(CE)
-$(VENV_BIN)/flake8 $(FLAKE8_FLAGS) ./
$(VENV_BIN)/pylint $(PYLINT_FLAGS) ./$(PKG_NAME) ./apps
@echo
.PHONY: build
build: build.py
@echo $(CS)Compress static assets$(CE)
$(VENV_PYTHON) manage.py compress --force
.PHONY: messages
messages: $(VENV_PYTHON)
@echo $(CS)Pull out all strings marked for translation$(CE)
$(VENV_PYTHON) manage.py makemessages_plus --all
@echo
.PHONY: serve
serve: $(VENV_PYTHON)
@echo $(CS)Starting web server on $(LOCAL_PORT) port$(CE)
$(VENV_PYTHON) manage.py runserver $(LOCAL_PORT)
.PHONY: static
static: $(VENV_PYTHON)
@echo $(CS)Collect static files$(CE)
$(VENV_PYTHON) manage.py collectstatic --noinput --clear --ignore *.scss
# See: https://sass-lang.com/install
.PHONY: css
css:
sass -I $(include) --no-source-map $(infile) $(outfile)
.PHONY: migrations
migrations: $(VENV_PYTHON)
$(VENV_PYTHON) manage.py makemigrations
.PHONY: migrate
migrate: $(VENV_PYTHON)
$(VENV_PYTHON) manage.py migrate
.PHONY: ccov
ccov: $(VENV_PYTHON)
@echo $(CS)Combine coverage reports$(CE)
$(VENV_BIN)/coverage combine
$(VENV_BIN)/coverage report
$(VENV_BIN)/coverage html
$(VENV_BIN)/coverage xml
@echo
.PHONY: manifest
manifest:
@echo $(CS)Check MANIFEST.in for completeness$(CE)
$(VENV_BIN)/check-manifest -v
@echo
.PHONY: test
test: $(VENV_PYTHON)
@echo $(CS)Running tests$(CE)
$(VENV_BIN)/coverage erase
$(VENV_BIN)/coverage run -m pytest $(PYTEST_FLAGS)
@echo
.PHONY: help
help:
@echo $(PKG_NAME)
@echo
@echo 'Run "make init" first to install and update all dev dependencies.'
@echo 'See "default.mk" for variables you might want to set.'
@echo
@echo 'Available targets:'
@echo
@echo ' help: Show this help and exit'
@echo ' init: Set up virtualenv (has to be launched first)'
@echo ' install: Install project and all its dependencies'
@echo ' serve: Run development server'
@echo ' static: Collect static files'
@echo ' css: Build CSS files from SCSS source'
@echo ' migrations: Create database migrations'
@echo ' migrate: Run all database migrations'
@echo ' build: Prepare project to use'
@echo ' messages: Pull out all strings marked for translation'
@echo ' test: Run unit tests'
@echo ' ccov: Combine coverage reports'
@echo ' lint: Lint the code'
@echo ' clean: Remove build and tests artefacts and directories'
@echo ' maintainer-clean:'
@echo ' Delete almost everything that can be reconstructed'
@echo ' with this Makefile'
@echo
@echo 'Nodejs:'
@echo
@echo ' npm: $(HAVE_NPM)'
@echo
@echo 'Virtualenv:'
@echo
@echo ' Python: $(VENV_PYTHON)'
@echo ' pip: $(VENV_PIP)'
@echo
@echo 'Flags:'
@echo
@echo ' FLAKE8_FLAGS: $(FLAKE8_FLAGS)'
@echo ' PYTEST_FLAGS: $(PYTEST_FLAGS)'
@echo ' PYLINT_FLAGS: $(PYLINT_FLAGS)'
@echo
@echo 'Environment variables:'
@echo
@echo ' NPM: $(NPM)'
@echo ' PYTHON: $(PYTHON)'
@echo ' WORKON_HOME: ${WORKON_HOME}'
@echo ' SHELL: $(shell echo $$SHELL)'
@echo ' TERM: $(shell echo $$TERM)'
@echo