# Add any tasks that are not dependent on files to the .PHONY list.
.PHONY: pip_dev dev lint test test_unit test_integration clean docker_dev docker_down docker_unit_lint ci_test_integration ci_test_integration_clean down_unit_lint ci_unit_lint ci_unit_lint_clean


pip_dev:
	pip install --upgrade pip
	pip install -r requirements.txt
	pip install -r requirements-dev.txt

dev: pip_dev
	python3.13 dev.py

lint: pip_dev
	python3.13 -m flake8 sound_recordings/ tests/ dev.py

test: pip_dev
	pytest tests/ \
		--cov sound_recordings \
		--cov-report term-missing

test_unit: pip_dev
	pytest -v \
		--cov sound_recordings tests/unit \
		--cov-report xml \
		--junitxml=pyunit.xml

test_integration: pip_dev
	pytest -v \
		--cov sound_recordings tests/integration \
		--cov-report xml \
		--junitxml=pyunit.xml

clean:
	rm -rf \
		env \
		.coverage \
		.pytest_cache \
		.cache \
		coverage.xml \
		pyunit.xml
	find . | grep -E '__pycache__|\.pyc|\.pyo$\' | xargs rm -rf

docker_dev:
	docker compose up --build dev

docker_down:
	docker compose down --remove-orphans

docker_unit_lint:
	docker compose up \
    	--exit-code-from unit-lint \
    	--abort-on-container-exit \
    	--build unit-lint \
		--remove-orphans \

ci_test_integration:
	docker compose up \
		--exit-code-from test-integration \
		--abort-on-container-exit \
		--remove-orphans \
		--build test-integration

ci_test_integration_clean:
	docker compose down test-integration --remove-orphans

down_unit_lint:
	docker compose down unit-lint --remove-orphans

ci_unit_lint: ci_unit_lint_clean
	mkdir -p build
	chmod a+w build
	make docker_unit_lint

ci_unit_lint_clean: down_unit_lint
