-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
298 lines (228 loc) · 8.83 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
#!/usr/bin/env make
# Makefile: because we need more elaborate commands than manage.py
# The target names are not a file produced by the commands of that target. Always out of date.
.PHONY: clean unit test data cov odsimport doc install_script npm gulp tox migrations shell
all: qa unit
clone:
git clone --recursive https://gitlab.com/vindarel/abelujo.git
# System dependencies to install as root on Debian (Ubuntu/LinuxMint):
debian-nosudo:
@grep -v "^#" abelujo/apt-requirements.txt | xargs apt-get install -y
pip install virtualenvwrapper
debian:
@grep -v "^#" abelujo/apt-requirements.txt | xargs sudo apt-get install -y
@sudo pip install virtualenvwrapper
pull:
git stash save "autostash from make publl"
git pull --rebase
git submodule update --remote
# Install in current directory
pip: pip-submodule
@pip install -r abelujo/requirements.txt # install python libraries locally
pip-nosudo: pip-submodule
@pip install -r abelujo/requirements.txt
pip-dev:
@pip install -r abelujo/requirements-dev.txt # other python libs, for development
pip-submodule:
cd search/datasources && python setup.py install
pip-submodule-dev:
cd search/datasources && pip install -r requirements-dev.txt
# deprecated when all clients are above bookshops v0.9. Should be in late 2020.
pip-uninstall-previous-libs:
@pip uninstall -y bookshops # around v0.9, an installed "bookshops" lib will hide newer code.
db:
@python manage.py syncdb --noinput # populate the db for django
@python manage.py loaddata dbfixture.json # set required card types and default place.
dbback:
# back up the db, append a timestamp
bash -c "cp db.db{,.`date +%Y%m%d-%H%M%S`}"
# Install everything: Django requirements, the DB, node packages, and
# build the app.
install: debian pip pip-submodule db npm-system npm gulp translation-compile collectstatic
# xxx: there must be a better way (to do the same task with and without sudo)
install-nosudo: debian-nosudo pip-nosudo db npm-system-nosudo npm gulp collectstatic translation-compile
install-dev: debian pip pip-dev pip-submodule pip-submodule-dev db npm npm-dev gulp translation-compile
# Install npm packages
npm-system:
@echo "Installing gulp globally... (needs root)"
@sudo npm install -g gulp@3
npm-system-nosudo:
@echo "Installing gulp globally... (needs root)"
npm global install gulp
npm:
@echo "Installing Node packages..."
mkdir -p public
npm install --production # don't install devDependencies
./node_modules/bower/bin/bower install --allow-root
# Saving dev ip for gunicorn
echo "localhost" > IP.txt
npm-dev:
npm install # not in production, install also devDependencies
set-prod:
touch PROD.txt
stash:
git stash save "update (probably stashing npm lock)"
update: stash
make pull
make set-prod
make pip
make pip-submodule
make migrate
# Get code, install new packages, run DB migrations, compile JS and translation files.
make npm
gulp
make collectstatic
make translation-compile # gunicorn needs a restart
# echo "it's good to do an apt-get update once in a while" # prevents unreachable sources, sometimes.
@echo "For development, don't forget make pip-dev. To update Debian dependencies, use make update-apt."
update-code: stash
make set-prod
make pull
make migrate
gulp
make collectstatic
make translation-compile
make gunicorn-restart
update-dev: update pip-dev pip-submodule-dev
# Create migrations and commit them.
migrations:
python manage.py makemigrations
git add search/migrations/*.py
migrate:
python manage.py migrate --noinput
collectstatic:
python manage.py collectstatic --noinput
# Run the tests of the UI in a browser.
livescript: search/tests/integration-tests/*.ls
# compile livescript files
cd search/tests/integration-tests/ && lsc -c *.ls
end2end:
# it was buggy on Firefox (waiting for async/await ?).
testcafe chromium search/tests/integration-tests/testcafetest.js
# Build static files
gulp:
gulp
# Run the dev server
run:
python manage.py runserver 8000
run_plus:
python manage.py runserver_plus 8000
run-wsgi:
# Run a development server using Apache and mod_wsgi, like in production.
# required: run collectstatic.
# see also --log-to-terminal, --enable-coverage, --profiler-
python manage.py runmodwsgi --reload-on-changes
run-wsgi-prod:
# TODO: run as daemon.
# https://pypi.python.org/pypi/mod_wsgi#running-mod-wsgi-express-as-root
python manage.py runmodwsgi
run-wsgi-debug:
# Allows: single thread, pdb, debug on exception
# Disables: auto code reloading, multithreading.
python manage.py runmodwsgi --debug-mode --enable-debugger
# Get our IP adress, only ipv4 form, trim whitespaces. Works for localhost.
# MAINIP := $(shell hostname --ip-address | cut -d " " -f 2 | tr -d '[[:space:]]')
# put the IP in IP.txt: ok for dev and prod
run-gunicorn:
# and static files are served by whitenoise.
# option --reload to reload on code changes. use --daemon or C-z and bg
gunicorn --env DJANGO_SETTINGS_MODULE=abelujo.settings abelujo.wsgi --bind=$(shell cat IP.txt):$(shell cat PORT.txt) --reload --pid=PID.txt
@echo "server running on $(shell cat IP.txt):$(shell cat PORT.txt)"
gunicorn-daemon:
gunicorn --env DJANGO_SETTINGS_MODULE=abelujo.settings abelujo.wsgi --bind=$(shell cat IP.txt):$(shell cat PORT.txt) --reload --pid=PID.txt --daemon
@echo "server running on $(shell cat IP.txt):$(shell cat PORT.txt)"
gunicorn-restart:
kill -HUP $(shell cat PID.txt)
gunicorn: run-gunicorn
shell:
python manage.py shell_plus
# Define processes in the Procfile.
taskqueue:
honcho start &
# run only unit tests.
unit:
# With this pattern we don't run the tests from "datasources".
./manage.py test search.tests --pattern="tests_*.py"
# Run test of an independent module.
ods:
cd search/datasources/bookshops/odslookup/tests/ && nosetests --nologcapture
# Test the scrapers but not the ods module.
testscrapers:
@cd search/datasources/frFR/ && nosetests
@cd search/datasources/deDE/buchwagner/ && nosetests
# Run all tests possible.
test: unit ods testscrapers
testcafe:
# Firefox has pbs with the new syntax (async/await).
cd search/tests/integration-tests/ && testcafe chromium test*.js
# Build test virtual environments, test against multiple python versions.
# see tox.ini
tox:
@tox
# Install the app in a fresh environment
ci:
source ci-testing.sh
# Code coverage analysis:
cov:
coverage run --source='search/' \
manage.py test search.tests --pattern="tests_*.py"
# XXX: discogs unit tests are missing.
coverage html
@echo -n "Current status:"
@coverage report | tail -n 1 | grep -o "..%"
@echo "You can now open the page htmlcov/index.html"
# Import from an ods file (LibreOffice Calc)
# usage: make odsimport srcfile=myfile.ods
srcfile = ""
odsimport:
python manage.py runscript -v2 odsimport --script-args=$(srcfile)
doc:
# the chmod is for the host server to serve the files.
@cd doc/dev/ && make html && cp *png _build/html/ && chmod 777 -R _build/html/
publish: doc
# publish on dev.abelujo.cc
@rsync -avzr doc/dev/_build/html/ $(ABELUJO_USER)@$(ABELUJO_SERVER):$(ABELUJO_HTDOCS)
html: doc
# I18n, translation.
# doc: https://docs.djangoproject.com/en/1.7/topics/i18n/translation/#localization-how-to-create-language-files
translation-files:
# py, html, jade files and all locales:
python manage.py makemessages --ignore="collectedstatic/*" --ignore="node_modules/*" -a -e py,html,jade
# Same for js files (djangojs flag) (compile .ls files before):
# (we may want to translate js in admin/)
# check the --ignore flags...
django-admin.py makemessages -d djangojs --ignore="doc/dev/_build/*" --ignore="static/js/build/vendor.js" --ignore="static/lib/*" --ignore="./static/bower_components/" --ignore="node_modules/*" --ignore="bootstrap/*" --ignore="admin/js/*" --ignore="collectedstatic/*" -a
translation-compile:
django-admin.py compilemessages # gunicorn needs a restart
flake8:
flake8 --config=setup.cfg abelujo search *.py
mccabe:
python -m mccabe --min 10 search/models/models.py
python -m mccabe --min 10 search/models/api.py
qa: flake8
pylint:
pylint abelujo search
uninstall-js:
@echo "##### Removing local JS libraries..."
rm -rf node_modules/
@echo " done."
@echo "##### Uninstalling nodejs..."
sudo apt-get remove nodejs npm
uninstall-pip:
@echo "This depends on how you created the python virtual env."
@echo "If you used mkvirtualenv, do"
@echo "\t rmvirtualenv abelujo"
@echo "Otherwise, delete abelujo/bin/ or ~/.venvs/abelujo or ~/.virtualenvs/abelujo."
uninstall-python:
@echo "We don't see why you would need this :]"
@echo "You shouldn't remove python from your system, it is used by many other applications."
uninstall:
@echo "See these subcommands: uninstall-js, uninstall-pip (and uninstall-python)."
@echo "You can remove the abelujo directory afterwards."
clean:
find . -name "*.pyc" -exec rm {} +
rm -rf htmlcov
rm -rf .coverage
clean-caches:
# that can be needed when moving scraper code.
find . -name "cache.sqlite" -exec rm {} +