#!/bin/sh


echo -n $( dirname -- "$( readlink -f -- "$0" )" ) > pwd.txt
CWD=$(cat pwd.txt)
cd "${CWD}"

find . -name .venv -type d -exec rm -vrf {} \;
find . -name __pycache__ -type d -exec rm -vrf {} \;

python -m venv .venv
source "${CWD}/.venv/bin/activate"

pip install --upgrade pip
pip install poetry poetry-plugin-export
poetry lock
poetry self update
poetry export --without-hashes --format requirements.txt --output ./requirements.txt
pip install --no-cache-dir -r requirements.txt

pip show uvicorn | grep -E "Name:|Version:|Location:"
pip show gunicorn | grep -E "Name:|Version:|Location:"
pip show fastapi | grep -E "Name:|Version:|Location:"

pyenv local 3.13
poetry env activate
poetry lock
poetry install --no-root

#hypercorn main_package.app:app --reload -w $(nproc) --bind 0.0.0.0:8001
#poetry run hypercorn main_package/app:app --reload -w $(nproc) --bind 0.0.0.0:8001
#uvicorn main_package.app:app --reload --workers $(nproc) --host 0.0.0.0 --port 8001
#uvicorn main_package.app:app --reload --workers $(nproc) --host 127.0.0.1 --port 8001
#gunicorn -b 0.0.0.0:8001 -k uvicorn.workers.UvicornWorker main_package.app:app

cd "${CWD}"
source "${CWD}/.venv/bin/activate"
fastapi run main_package/app.py --reload --port 8001 --proxy-headers
