.DEFAULT_GOAL := help

help: ## display this help message
	@echo "Please use \`make <target>' where <target> is one of"
	@perl -nle'print $& if m{^[\.a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m  %-25s\033[0m %s\n", $$1, $$2}'

clean: ## remove generated byte code, coverage reports, and build artifacts
	find . -name '*.pyc' -exec rm -f {} +
	find . -name '*.pyo' -exec rm -f {} +
	find . -name '__pycache__' -exec rm -rf {} +
	find . -name '*~' -exec rm -f {} +
	coverage erase
	rm -fr build/
	rm -fr dist/
	rm -fr *.egg-info

coverage: clean ## generate and view HTML coverage report
	pytest --cov-report html
	$(BROWSER) htmlcov/index.html

compile-requirements: ## generate the uv.lock file without upgrading packages
	uv lock

upgrade: ## upgrade all packages in uv.lock and sync constraints from edx-lint
	uv run --with edx-lint edx_lint write_uv_constraints pyproject.toml
	uv lock --upgrade

requirements: ## install development environment requirements
	uv sync --group dev

test: clean ## run tests in the current virtualenv
	pytest

quality: ## check coding style with isort, pylint, pycodestyle, and pydocstyle
	tox -e quality

test-all: clean ## run tests on every supported Python/Django combination
	tox
	$(MAKE) quality

validate: test ## run tests and quality checks
	$(MAKE) quality

isort: ## call isort on packages/files that are checked in quality tests
	isort --recursive tests src/enterprise_reporting src/enterprise_data src/enterprise_data_roles manage.py

.PHONY: requirements upgrade help compile-requirements quality test-all validate
