-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
284 lines (228 loc) · 8.02 KB
/
Makefile
File metadata and controls
284 lines (228 loc) · 8.02 KB
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
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 "Formatting and static analysis:"
@echo "mypy -- let mypy run over our codebase"
@echo "lint -- run linters (ruff)"
@echo "format -- automatically sort imports and reformat code"
@echo "autoformat -- automatically sort imports, reformat code and lint"
@echo "format-diff -- show the changes 'format' would make but do not apply them"
@echo "shellcheck -- run shellcheck over all shell scripts"
@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 #
###############
UV ?= uv
PYTHONBIN ?= $(UV) run --all-groups python3
RUFF ?= $(UV) run ruff
ISORT ?= $(RUFF) check --select I
COVERAGE ?= $(PYTHONBIN) -m coverage
MYPY ?= $(UV) run --all-groups mypy
DMYPY ?= $(UV) run --all-groups dmypy
#####################
# 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))
UV_PROJECT_ENVIRONMENT ?= .venv
###########
# General #
###########
.PHONY: cron
cron: www-cde-venv
sudo -u www-cde -g www-data UV_PROJECT_ENVIRONMENT=/home/www-cde/.venv $(UV) run --no-sync /cdedb2/bin/cron_execute.py
.PHONY: doc
doc:
bin/create_email_template_list.sh .
$(MAKE) -C doc html
.PHONY: reload
reload: i18n-compile venv
$(PYTHONBIN) -m cdedb db remove-transactions
ifeq ($(wildcard /CONTAINER),/CONTAINER)
sudo apachectl restart
kill $$(pidof -x gunicorn) || true
sudo /run-gunicorn.sh
else
sudo systemctl restart apache2.service cdedb-app.service
endif
################
# Translations #
################
.PHONY: i18n-output-dirs
i18n-output-dirs:
ifeq ($(wildcard /CONTAINER),/CONTAINER)
sudo chown -R cdedb:cdedb $(I18NOUTDIR)
endif
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 venv
$(PYTHONBIN) cdedb/i18n_additional.py > cdedb/.i18n_additional.py
$(UV) run pybabel extract --msgid-bugs-address="cdedb@lists.cde-ev.de" \
--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 #
###################
$(UV_PROJECT_ENVIRONMENT)/bin/python:
$(UV) venv
.PHONY: venv
venv: $(UV_PROJECT_ENVIRONMENT)/bin/python
.PHONY: www-cde-venv
www-cde-venv:
sudo UV_PYTHON_INSTALL_DIR=/home/www-cde/.local/share/uv/python \
UV_CACHE_DIR=/home/www-cde/.cache/uv \
UV_PROJECT_ENVIRONMENT=/home/www-cde/.venv/ \
$(UV) sync --no-dev --group ldap
.PHONY: format
format: venv
$(ISORT) --fix
$(RUFF) format
.PHONY: autoformat
autoformat: format
$(RUFF) check
.PHONY: format-diff
format-diff: venv
$(ISORT) --diff
$(RUFF) format --diff
.PHONY: mypy
mypy: venv
$(MYPY)
.PHONY: dmypy
dmypy: venv
$(DMYPY) run
BANNERLINE := "================================================================================"
.PHONY: isort
isort: venv
@echo $(BANNERLINE)
@echo "All of isort"
@echo $(BANNERLINE)
$(ISORT)
@echo ""
.PHONY: ruff
ruff: venv
@echo $(BANNERLINE)
@echo "All of ruff"
@echo $(BANNERLINE)
ifeq ($(CI),true)
# Use the grouped output format to make it easier to read in CI
$(RUFF) check --output-format=grouped
$(RUFF) format --check
else
$(RUFF) check
$(RUFF) format --check
endif
@echo ""
.PHONY: ruff-fix
ruff-fix: venv
$(RUFF) check --fix
.PHONY: shellcheck
shellcheck:
@echo $(BANNERLINE)
@echo "All of shellcheck"
@echo $(BANNERLINE)
shellcheck $$( \
find bin/ i18n/ related/ \
-type f \
\( -name '*.sh' -or \( -executable -not -name '*.py' \) \) \
-not \( -path bin/archive/'*' -or -path related/deploy/archive/'*' -or -path related/auto-build/bin/'*' \) \
)
.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
################
# Code testing #
################
.PHONY: check
check: venv
$(PYTHONBIN) bin/check.py --verbose
.PHONY: xss-check
xss-check: venv
$(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/: venv
$(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) venv
$(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: venv
$(PYTHONBIN) -m cdedb dev compile-sample-data-json \
--outfile /cdedb2/tests/ancillary_files/sample_data.json
.PHONY: sample-data
sample-data: venv
$(UV) sync --all-groups
sudo $(PYTHONBIN) -m cdedb dev apply-sample-data --owner www-cde --group www-data