-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
232 lines (184 loc) · 6.55 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
SHELL := /bin/bash
.PHONY: help
help:
@echo "Default Variables:"
@echo "I18NDIR -- directory of the translation files. Default: ./i18n"
@echo ""
@echo "General:"
@echo "cron -- trigger cronjob execution (as user www-cde)"
@echo "doc -- build documentation"
@echo "reload -- re-compile GNU gettext data and trigger WSGI worker reload"
@echo ""
@echo "Translations"
@echo "i18n-refresh -- extract translatable strings from code and update translation catalogs in I18NDIR"
@echo ""
@echo "Code formatting:"
@echo "mypy -- let mypy run over our codebase (bin, cdedb, tests)"
@echo "lint -- run linters (ruff, isort and pylint)"
@echo ""
@echo "Code testing:"
@echo "check -- run (parts of the) test suite"
@echo "xss-check -- check for xss vulnerabilities"
@echo "dump-html -- run frontend tests and store all encountered pages inside /tmp/cdedb-dump/"
@echo "validate-html -- run html validator over the dumped frontend pages "
@echo " (dump-html is executed before if they do not exist yet)"
@echo "coverage -- run coverage to determine test suite coverage"
@echo ""
@echo "Sample Data:"
@echo "sample-data-dump -- shortcut to dump current database state into json file in tests directory"
@echo "sample-data -- shortcut to reset the whole application via the python cli"
###############
# Executables #
###############
PYTHONBIN ?= python3
PYLINT ?= $(PYTHONBIN) -m pylint
RUFF ?= sudo -u cdedb $(PYTHONBIN) -m ruff check --config /cdedb2/pyproject.toml
ISORT ?= $(RUFF) --select I
COVERAGE ?= $(PYTHONBIN) -m coverage
MYPY ?= $(PYTHONBIN) -m mypy
#####################
# Default Variables #
#####################
# Use makes command-line arguments to override the following default variables
# Directory where the translation input files are stored.
# Especially used by the i18n-targets.
I18NDIR = ./i18n
# Directory where the translation output files are stored.
# Especially used by the i18n-targets.
I18NOUTDIR = ./i18n-output
# Available languages, by default detected as subdirectories of the translation targets.
I18N_LANGUAGES = $(patsubst $(I18NDIR)/%/LC_MESSAGES, %, $(wildcard $(I18NDIR)/*/LC_MESSAGES))
###########
# General #
###########
.PHONY: cron
cron:
sudo -u www-cde -g www-data /cdedb2/bin/cron_execute.py
.PHONY: doc
doc:
bin/create_email_template_list.sh .
$(MAKE) -C doc html
.PHONY: reload
reload: i18n-compile
python3 -m cdedb db remove-transactions
ifeq ($(wildcard /CONTAINER),/CONTAINER)
sudo apachectl restart
kill $$(pidof -x gunicorn) || true
/run-gunicorn.sh
else
sudo systemctl restart apache2.service cdedb-app.service
endif
################
# Translations #
################
.PHONY: i18n-output-dirs
i18n-output-dirs:
for lang in $(I18N_LANGUAGES) ; do \
mkdir -p $(I18NOUTDIR)/$$lang/LC_MESSAGES ; \
done
.PHONY: i18n-refresh
i18n-refresh: i18n-extract i18n-update
.PHONY: i18n-extract
i18n-extract: i18n-output-dirs
pybabel extract --msgid-bugs-address="[email protected]" \
--mapping=./babel.cfg --keywords="rs.gettext rs.ngettext n_" \
--output=$(I18NOUTDIR)/cdedb.pot --input-dirs="bin,cdedb"
i18n-update: $(foreach lang, $(I18N_LANGUAGES), $(I18NDIR)/$(lang)/LC_MESSAGES/cdedb.po)
$(I18NDIR)/%/LC_MESSAGES/cdedb.po: $(I18NOUTDIR)/cdedb.pot
msgmerge --lang=$* --update $@ $<
msgattrib --no-obsolete --sort-by-file -o $@ $@
i18n-compile: i18n-output-dirs
i18n-compile: $(foreach lang, $(I18N_LANGUAGES), $(I18NOUTDIR)/$(lang)/LC_MESSAGES/cdedb.mo)
$(I18NOUTDIR)/%/LC_MESSAGES/cdedb.mo: $(I18NDIR)/%/LC_MESSAGES/cdedb.po
msgfmt --verbose --check --statistics -o $@ $<
###################
# Code formatting #
###################
.PHONY: format
format:
$(ISORT) --fix bin/*.py cdedb tests
.PHONY: mypy
mypy:
$(MYPY) bin/*.py cdedb tests
BANNERLINE := "================================================================================"
.PHONY: isort
isort:
@echo $(BANNERLINE)
@echo "All of isort"
@echo $(BANNERLINE)
$(ISORT) bin/*.py cdedb tests
@echo ""
.PHONY: pylint
pylint:
@echo $(BANNERLINE)
@echo "All of pylint"
@echo $(BANNERLINE)
$(PYLINT) cdedb tests
@echo ""
.PHONY: ruff
ruff:
@echo $(BANNERLINE)
@echo "All of ruff"
@echo $(BANNERLINE)
sudo mkdir .ruff_cache -p
sudo chown cdedb -R .ruff_cache
$(RUFF) cdedb tests
@echo ""
.PHONY: template-line-length
template-line-length:
@echo $(BANNERLINE)
@echo "Lines too long in templates"
@echo $(BANNERLINE)
grep -E -R '^.{121,}' cdedb/frontend/templates/ | grep 'tmpl:'
@echo ""
.PHONY: lint
lint: ruff isort pylint
################
# Code testing #
################
.PHONY: check
check:
$(PYTHONBIN) bin/check.py --verbose
.PHONY: xss-check
xss-check:
$(PYTHONBIN) bin/check.py --verbose --parts xss
.PHONY: dump-html
dump-html:
$(MAKE) -B /tmp/cdedb-dump/
/tmp/cdedb-dump/: export CDEDB_TEST_DUMP_DIR=/tmp/cdedb-dump/
/tmp/cdedb-dump/:
$(PYTHONBIN) -m bin.check --verbose tests.frontend_tests.*
.PHONY: validate-html
validate-html: /tmp/cdedb-dump/ /opt/validator/vnu-runtime-image/bin/vnu
/opt/validator/vnu-runtime-image/bin/vnu --no-langdetect --stdout \
--filterpattern '(.*)input type is not supported in all browsers(.*)' /tmp/cdedb-dump/* \
> /cdedb2/validate-html.txt
/opt/validator/vnu-runtime-image/bin/vnu: /opt/validator/vnu.linux.zip
unzip -DD /opt/validator/vnu.linux.zip -d /opt/validator
VALIDATORURL := "https://github.com/validator/validator/releases/download/20.6.30/vnu.linux.zip"
VALIDATORCHECKSUM := "f56d95448fba4015ec75cfc9546e3063e8d66390 /opt/validator/vnu.linux.zip"
/opt/validator/vnu.linux.zip: /opt/validator
wget $(VALIDATORURL) -O /opt/validator/vnu.linux.zip
echo $(VALIDATORCHECKSUM) | sha1sum -c -
touch /opt/validator/vnu.linux.zip # refresh downloaded timestamp
/opt/validator:
sudo mkdir /opt/validator
sudo chown cdedb:cdedb /opt/validator
.coverage: $(wildcard cdedb/*.py) $(wildcard cdedb/database/*.py) $(wildcard cdedb/frontend/*.py) \
$(wildcard cdedb/backend/*.py) $(wildcard tests/*.py)
$(COVERAGE) run -m bin.check
.PHONY: coverage
coverage: .coverage
$(COVERAGE) report --include 'cdedb/*' --show-missing
$(COVERAGE) html --include 'cdedb/*'
@echo "HTML reports for easier inspection are in ./htmlcov"
##########################
# Sample Data Generation #
##########################
.PHONY: sample-data-dump
sample-data-dump:
python3 -m cdedb dev compile-sample-data-json \
--outfile /cdedb2/tests/ancillary_files/sample_data.json
.PHONY: sample-data
sample-data:
sudo python3 -m cdedb dev apply-sample-data --owner www-cde --group www-data