# SPDX-FileCopyrightText: UL Research Institutes
# SPDX-License-Identifier: Apache-2.0

VENV ?= venv
PYTHON ?= $(VENV)/bin/python3
PYTHON_VERSION ?= 3.11
MANAGE ?= $(PYTHON) ./manage.py

.PHONY: all
all: setup

.PHONY: setup
setup: $(VENV)/requirements.txt editable

requirements.txt: pyproject.toml | $(VENV)
	uv pip compile --python-version $(PYTHON_VERSION) --extra test --upgrade -o requirements.txt pyproject.toml

$(VENV)/requirements.txt: requirements.txt | $(VENV)
	uv pip install --python $(PYTHON) -r requirements.txt
	cp -f requirements.txt $(VENV)/requirements.txt

$(VENV):
	uv venv $(VENV)

.PHONY: clean
clean:
	find -name __pycache__ -type d -exec rm -rf '{}' \;
	find -name \*.pyc -type f -exec rm -f '{}' \;

.PHONY: distclean
distclean:
	rm -rf $(VENV)

.PHONY: editable
editable:
	uv pip install --python $(PYTHON) -e .

.PHONY: test
test:
	$(PYTHON) -m pytest tests/ --cov=cici --cov-report=term-missing

.PHONY: serve
serve:
	$(PYTHON) ./scripts/serve.py

.PHONY: schema
schema:
	$(VENV)/bin/cici schema | $(PYTHON) ./scripts/gen-api-doc.py --template scripts/config-file.md.j2 - > docs/config-file.md
