.PHONY: dev pip_dev lint test docker_unit_lint test_unit test_integration pip_test_integration clean clean_test_integration ci_unit_lint

dev: env
	env/bin/python3.13 dev.py

env pip_dev:
	python3.13 -m venv env
	env/bin/pip3.13 install --upgrade pip
	env/bin/pip3.13 install -r requirements.txt
	env/bin/pip3.13 install -r requirements-dev.txt
	env/bin/pip3.13 install setuptools

test_unit: env
	export Environment=test && env/bin/py.test \
		--cov participant tests/unit/ \
		--cov-report xml \
		--junitxml=pyunit.xml

test_integration: tests/integration/env
	py.test tests/integration/

tests/integration/env pip_test_integration:
	python3.13 -m venv tests/integration/env
	tests/integration/env/bin/pip3.13 install --upgrade pip
	tests/integration/env/bin/pip3.13 install -r requirements.txt
	tests/integration/env/bin/pip3.13 install -r tests/integration/requirements.txt

lint: env
	env/bin/autoflake --in-place --remove-all-unused-imports --remove-unused-variable --check .
	env/bin/black --skip-string-normalization --check .
	env/bin/flake8 participant/ tests/
	env/bin/docformatter --in-place --blank participant/**.py tests/**.py

fmt: env
	env/bin/autoflake --in-place --remove-all-unused-imports --remove-unused-variable .
	env/bin/black --skip-string-normalization .
	env/bin/flake8 participant/ tests/
	env/bin/docformatter --in-place --blank participant/**.py tests/**.py

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

docker_integration_test:  # Run integration tests in Docker
	docker compose up \
		--build \
		--exit-code-from integration-test \
		--abort-on-container-exit \
		--remove-orphans \
		integration-test

ci_unit_lint: # Run lint and unit tests in CI/CD
	mkdir -p build
	chmod a+w build
	make docker_unit_lint

down_unit_lint:
	docker compose down --remove-orphans

ci_unit_lint_clean: down_unit_lint  # Teardown lint and unit tests in CI/CD
	rm -rf build

clean:
	rm -rf env

clean_test_integration:
	rm -rf tests/integration/env
