# PYTHONDEVMODE to enable PYTHONASYNCIODEBUG=1 and other flags.
# PYTHONTRACEMALLOC=1 is helpful when debugging ResourceWarnings, but is too
# slow to leave enabled all the time.
PYTHON_ENVIRONMENT := PYTHONASYNCIODEBUG=1 PYTHONDEBUG=1 PYTHONWARNINGS=always::ResourceWarning

ifeq ($(VERBOSE),1)
    VERBOSE_OPTION_TESTS := -v
else
    VERBOSE_OPTION_TESTS :=
endif

# Quick sanity check to run before each commit
check:
	pre-commit run -a

# Reformat the code and show changes made by black
format black:
	tox -e format

djlint:
	tox -e djlint

coverage:
	python3 -m coverage erase
	$(PYTHON_ENVIRONMENT) pytest --ignore=debusine/signing --cov=debusine --cov-append --cov-report= $(VERBOSE_OPTION_TESTS)
	$(PYTHON_ENVIRONMENT) pytest --ds=debusine.signing.settings --cov=debusine --cov-append --cov-report= debusine/signing $(VERBOSE_OPTION_TESTS)
ifeq ($(HTML_COVERAGE),1)
	python3 -m coverage html
endif
	python3 -m coverage report --precision=2 --show-missing --skip-covered $(if $(TOTAL_COVERAGE),| perl -pe '$$total = $$1 if /^TOTAL .* (\d+(?:\.\d+)?%)/; END { print "TOTAL COVERAGE $$total\n" }')

css:
	( \
		echo "/* This file is generated by pygments by running make css. License is BSD-2-clause (same as pygments) */" ; \
		python3 -m pygments -S github-dark -f html \
	) > debusine/web/static/web/css/debusine-code-highlight.css

.PHONY: check format black djlint coverage css
