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

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

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

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

test: env
		env/bin/python3.11 -m pytest tests \
				--cov product_configuration \
				--cov-report term-missing

test_unit: pip_dev
		env/bin/python3.11 -m pytest -v \
				product_configuration tests/ \
				--cov-report xml \
				--junitxml=pyunit.xml

lint: pip_dev
		env/bin/python3.11 -m flake8 product_configuration tests dev.py

docker_up:
		docker compose up --build -d

docker_down:
	docker compose down --remove-orphans

docker_unit_lint:
	docker compose run --name ows-product-configuration-unit-lint --build lint-and-test
	docker cp ows-product-configuration-unit-lint:/var/app/pyunit.xml ./pyunit.xml
	docker cp ows-product-configuration-unit-lint:/var/app/coverage.xml ./coverage.xml
	sed -i.bak "s?<source>/var/app/product_configuration</source>?<source>$$(pwd)/product_configuration</source>?g" ./coverage.xml
	docker rm -f ows-product-configuration-unit-lint

ci_unit_lint: ci_unit_lint_clean docker_unit_lint

ci_unit_lint_clean: docker_down

test_integration:
	echo 'I am a placeholder'
