context_generator/run.sh

81 lines
2.1 KiB
Bash
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Cross-platform helper to set up .venv, install dependencies, and run alpha.py
set -e
# Get the directory of the script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
VENV_DIR=".venv"
# List of essential Python packages
REQUIRED_PACKAGES=("pywebview")
# Function to check Linux GTK dependencies
check_gtk_linux() {
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Try importing gi in python
python3 - <<EOF 2>/dev/null
try:
import gi
except ImportError:
import sys
sys.exit(1)
EOF
if [[ $? -ne 0 ]]; then
echo -e "\e[31mError: GTK dependencies missing on Linux.\e[0m"
echo "Install them with:"
echo " sudo apt install python3-gi python3-gi-cairo gir1.2-webkit2-4.0"
exit 1
fi
fi
}
# Function to create virtual environment and install dependencies
setup_venv() {
echo -e "\e[32mCreating virtual environment...\e[0m"
python3 -m venv "$VENV_DIR"
if [ ! -f "$VENV_DIR/bin/activate" ]; then
echo -e "\e[31mError: Failed to create virtual environment.\e[0m"
exit 1
fi
echo -e "\e[32mActivating virtual environment...\e[0m"
source "$VENV_DIR/bin/activate"
# Upgrade pip first
pip install --upgrade pip
# Install pywebview and other dependencies
for pkg in "${REQUIRED_PACKAGES[@]}"; do
pip install "$pkg"
done
# Install packages from requirements.txt if it exists
if [ -f "requirements.txt" ]; then
echo -e "\e[32mInstalling dependencies from requirements.txt...\e[0m"
pip install -r requirements.txt
else
echo -e "\e[33mNo requirements.txt found, skipping additional dependencies.\e[0m"
fi
echo -e "\e[32mVirtual environment ready.\e[0m"
}
# 1⃣ Check GTK dependencies on Linux
check_gtk_linux
# 2⃣ Activate existing venv or create one
if [ -f "$VENV_DIR/bin/activate" ]; then
echo -e "\e[32mActivating existing virtual environment...\e[0m"
source "$VENV_DIR/bin/activate"
else
setup_venv
fi
# 3⃣ Run the application
echo -e "\e[32mRunning alpha.py...\e[0m"
python alpha.py