VENV_PIP := .venv/bin/pip
VENV_PY := .venv/bin/python

APP_LOC := comfy_server/server.py::Comfy
APP_NAME := comfy
APP_AUTH := private

PYTHON_BIN_PATH := $(shell which python3.11)

-include .env
export

check-python-3.11:
	@if [ -z "$(PYTHON_BIN_PATH)" ]; then \
		echo "Error: Python 3.11 is not installed or not in PATH."; \
		echo "Please install Python 3.11 and make sure it's available in your PATH."; \
		exit 1; \
	elif ! $(PYTHON_BIN_PATH) -c "import sys; sys.exit(0)"; then \
		echo "Error: Python 3.11 is not functioning correctly."; \
		echo "Please ensure Python 3.11 is properly installed and configured."; \
		exit 1; \
	fi

init: check-python-3.11
	${PYTHON_BIN_PATH} -m venv .venv
	${VENV_PIP} install --upgrade pip
	${VENV_PIP} install --upgrade setuptools
	${VENV_PIP} install -e '.[dev]'
	${VENV_PY} -m pre_commit install

run: check-python-3.11
	${VENV_PY} -m fal run ${APP_LOC}

deploy: check-python-3.11
	${VENV_PY} -m fal deploy ${APP_LOC} --app-name ${APP_NAME} --auth ${APP_AUTH}


.PHONY: init run deploy
