<commit_before>LINT_PKG_IGNORE_GLOBAL = -path "./debian/*" -o -path "./build/*" -o -path "./.pybuild/*" -o -path "./scripts/*" \
	-o -path "./.venv/*" -o -path "./gitlab-ci-build-venv/*"
LINT_PKG_PEP420 = $(shell find . -mindepth 2 -type f -name "*.py" -not \( $(LINT_PKG_IGNORE_GLOBAL) \) -print0 | \
	xargs -0 -n1 dirname | sort | uniq)

.PHONY: lint
lint: lint_js lint-python lint_packages

.PHONY: lint_js
lint_js: $(DIR_NODE)
	$(RUN_NODE) "$(BIN_NODE_PKG)" run lint

.PHONY: lint_packages
lint_packages:
	# setuptools’ find_packages() does not find PEP420 packages
	# we therefor forbid the use of PEP420 to ease automation
	# see: https://github.com/pypa/setuptools/issues/97
	@EXIT=0; for package in $(LINT_PKG_PEP420); do \
		if [ ! -f "$$package/__init__.py" ]; then \
			EXIT=1; \
			echo "missing __init__.py in $$package" >&2; \
		fi; \
	done && test "$$EXIT" = "0"
	@echo "OK"

.PHONY: test
test: lint test_js test_py

.PHONY: test_py
test_py: virtualenv_check
	@# check for duplicate test method names that may overwrite each other
	@duplicate_function_names=$$(find . -mindepth 2 -type f -name tests.py -not \( $(LINT_PKG_IGNORE_GLOBAL) \) \
			| xargs grep -h "def test_" \
			| sed 's/^ \+def //g' | cut -f 1 -d "(" \
			| sort | uniq -d); \
		if [ -n "$$duplicate_function_names" ]; then \
			echo "[ERROR] non-unique test method names found:"; \
			echo "$$duplicate_function_names" | sed 's/^/    /g'; \
			exit 1; \
		fi >&2
	STADTGESTALTEN_PRESET=test python manage.py test

.PHONY: test_js
test_js: $(DIR_NODE) lint_js
	$(RUN_NODE) "$(BIN_NODE_PKG)" run test

.PHONY: report-python-coverage
coverage_py: virtualenv_check
	STADTGESTALTEN_PRESET=test python -m coverage run -m manage test
	python -m coverage report
	python -m coverage html --directory="$(DIR_BUILD)/coverage-report"
	@echo "Coverage Report Location: file://$(realpath $(DIR_BUILD))/coverage-report/index.html"<commit_msg>make sure core/_assets.html template exists during python test runs<commit_after>LINT_PKG_IGNORE_GLOBAL = -path "./debian/*" -o -path "./build/*" -o -path "./.pybuild/*" -o -path "./scripts/*" \
	-o -path "./.venv/*" -o -path "./gitlab-ci-build-venv/*"
LINT_PKG_PEP420 = $(shell find . -mindepth 2 -type f -name "*.py" -not \( $(LINT_PKG_IGNORE_GLOBAL) \) -print0 | \
	xargs -0 -n1 dirname | sort | uniq)

.PHONY: lint
lint: lint_js lint-python lint_packages

.PHONY: lint_js
lint_js: $(DIR_NODE)
	$(RUN_NODE) "$(BIN_NODE_PKG)" run lint

.PHONY: lint_packages
lint_packages:
	# setuptools’ find_packages() does not find PEP420 packages
	# we therefor forbid the use of PEP420 to ease automation
	# see: https://github.com/pypa/setuptools/issues/97
	@EXIT=0; for package in $(LINT_PKG_PEP420); do \
		if [ ! -f "$$package/__init__.py" ]; then \
			EXIT=1; \
			echo "missing __init__.py in $$package" >&2; \
		fi; \
	done && test "$$EXIT" = "0"
	@echo "OK"

.PHONY: test
test: lint test_js test_py

.PHONY: test_py
test_py: virtualenv_check
	@# check for duplicate test method names that may overwrite each other
	@duplicate_function_names=$$(find . -mindepth 2 -type f -name tests.py -not \( $(LINT_PKG_IGNORE_GLOBAL) \) \
			| xargs grep -h "def test_" \
			| sed 's/^ \+def //g' | cut -f 1 -d "(" \
			| sort | uniq -d); \
		if [ -n "$$duplicate_function_names" ]; then \
			echo "[ERROR] non-unique test method names found:"; \
			echo "$$duplicate_function_names" | sed 's/^/    /g'; \
			exit 1; \
		fi >&2
	# Our base template includes 'core/_assets.html' which is generated by 'make assets'.
	# Without it any view that renders from the base template will fail when the include
	# is resolved, which breaks a lot of our python-tests. As this template only includes
	# asset metadata and JavaScript & CSS file references, we simply make sure that the file
	# exists during the test run. The content itself is of no relevance to the python-tests.
	touch core/templates/core/_assets.html
	STADTGESTALTEN_PRESET=test python manage.py test

.PHONY: test_js
test_js: $(DIR_NODE) lint_js
	$(RUN_NODE) "$(BIN_NODE_PKG)" run test

.PHONY: report-python-coverage
coverage_py: virtualenv_check
	STADTGESTALTEN_PRESET=test python -m coverage run -m manage test
	python -m coverage report
	python -m coverage html --directory="$(DIR_BUILD)/coverage-report"
	@echo "Coverage Report Location: file://$(realpath $(DIR_BUILD))/coverage-report/index.html"
{'fraction_non_alphanumeric': 0.14699127239320164, 'fraction_numerical': 0.011943040881947635, 'mean_word_length': 3.5938818565400843, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3547194', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1638, 'n_words': 482}