#!/usr/bin/env bash
export PYTHON_KEYRING_BACKEND="keyring.backends.null.Keyring"
PROJECT_NAME=$(basename "$(pwd)")
export PROJECT_NAME
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export PROJECT_ROOT
VIRTUAL_ENV="./.venv"
if [ -e "${VIRTUAL_ENV}/bin/activate" ]; then
    # shellcheck disable=SC1091
    source "${VIRTUAL_ENV}/bin/activate"
else
    make install
    # shellcheck disable=SC1091
    source "${VIRTUAL_ENV}/bin/activate"
    python3 -m ensurepip --upgrade
    python3 -m pip install --upgrade pip setuptools wheel
fi
# Load .env if it exists
if [ -f .env ]; then
    # Load each line in .env file
    while IFS= read -r line || [ -n "$line" ]; do
        # Skip comments and empty lines
        if [[ $line =~ ^[[:space:]]*# ]] || [[ -z $line ]]; then
            continue
        fi
        # Export the valid environment variables
        eval "export ${line}"
    done < .env
fi
