Merge branch 'refactor-image-validation'

This commit is contained in:
Fahad
2025-08-08 12:01:28 +05:00
2 changed files with 69 additions and 31 deletions

View File

@@ -14,7 +14,7 @@ import os
# These values are used in server responses and for tracking releases # These values are used in server responses and for tracking releases
# IMPORTANT: This is the single source of truth for version and author info # IMPORTANT: This is the single source of truth for version and author info
# Semantic versioning: MAJOR.MINOR.PATCH # Semantic versioning: MAJOR.MINOR.PATCH
__version__ = "5.8.3" __version__ = "5.8.4"
# Last update date in ISO format # Last update date in ISO format
__updated__ = "2025-08-08" __updated__ = "2025-08-08"
# Primary maintainer # Primary maintainer

View File

@@ -853,8 +853,8 @@ setup_venv() {
# Check if package is installed # Check if package is installed
check_package() { check_package() {
local python_cmd="$1" local python_cmd="$1"
local package="$2" local module_name="$2"
$python_cmd -c "import $package" 2>/dev/null "$python_cmd" -c "import importlib, sys; importlib.import_module(sys.argv[1])" "$module_name" &>/dev/null
} }
# Install dependencies # Install dependencies
@@ -862,20 +862,67 @@ install_dependencies() {
local python_cmd="$1" local python_cmd="$1"
local deps_needed=false local deps_needed=false
# First verify pip is available (always check, even for uv environments) # First verify pip is available with retry logic and bootstrap fallback
if ! $python_cmd -m pip --version &>/dev/null 2>&1; then local pip_available=false
local max_attempts=3
for ((attempt=1; attempt<=max_attempts; attempt++)); do
if "$python_cmd" -m pip --version &>/dev/null; then
pip_available=true
break
else
if (( attempt < max_attempts )); then
print_warning "Attempt $attempt/$max_attempts: pip not available, retrying in 1 second..."
sleep 1
fi
fi
done
# If pip is still not available after retries, try to bootstrap it
if [[ "$pip_available" == false ]]; then
print_warning "pip is not available in the Python environment after $max_attempts attempts"
print_info "Python command: $python_cmd"
print_info "Attempting to bootstrap pip..."
# Extract the base python command for bootstrap (fallback to python3)
local base_python_cmd="python3"
if command -v python &> /dev/null; then
base_python_cmd="python"
fi
# Try to bootstrap pip
if bootstrap_pip "$python_cmd" "$base_python_cmd"; then
print_success "Successfully bootstrapped pip"
# Verify pip is now available
if $python_cmd -m pip --version &>/dev/null 2>&1; then
pip_available=true
else
print_error "pip still not available after bootstrap attempt"
fi
else
print_error "Failed to bootstrap pip"
fi
fi
# Final check - if pip is still not available, exit with error
if [[ "$pip_available" == false ]]; then
print_error "pip is not available in the Python environment" print_error "pip is not available in the Python environment"
echo "" echo ""
echo "This indicates an incomplete Python installation." echo "This indicates an incomplete Python installation or a problem with the virtual environment."
echo "Please see the instructions above for installing the required packages." echo ""
echo "Troubleshooting steps:"
echo "1. Delete the virtual environment: rm -rf $VENV_PATH"
echo "2. Run this script again: ./run-server.sh"
echo "3. If the problem persists, check your Python installation"
echo ""
return 1 return 1
fi fi
# Check required packages # Check required packages
local packages=("mcp" "google.generativeai" "openai" "pydantic" "dotenv") local packages=("mcp" "google.genai" "openai" "pydantic" "dotenv")
for package in "${packages[@]}"; do for package in "${packages[@]}"; do
local import_name=${package%%.*} # Get first part before dot if ! check_package "$python_cmd" "$package"; then
if ! check_package "$python_cmd" "$import_name"; then
deps_needed=true deps_needed=true
break break
fi fi
@@ -895,30 +942,21 @@ install_dependencies() {
echo " • Environment configuration" echo " • Environment configuration"
echo "" echo ""
# Determine installation method - prefer uv if available and we're in a uv-created environment # Determine installation method and execute directly to handle paths with spaces
local install_cmd local install_output
local use_uv=false local exit_code=0
echo -n "Downloading packages..."
if command -v uv &> /dev/null && [[ -f "$VENV_PATH/uv_created" ]]; then if command -v uv &> /dev/null && [[ -f "$VENV_PATH/uv_created" ]]; then
# Use uv for faster installation if environment was created by uv
install_cmd="uv pip install -q -r requirements.txt --python $python_cmd"
use_uv=true
print_info "Using uv for faster package installation..." print_info "Using uv for faster package installation..."
install_output=$(uv pip install -q -r requirements.txt --python "$python_cmd" 2>&1) || exit_code=$?
elif [[ -n "${VIRTUAL_ENV:-}" ]] || [[ "$python_cmd" == *"$VENV_PATH"* ]]; then elif [[ -n "${VIRTUAL_ENV:-}" ]] || [[ "$python_cmd" == *"$VENV_PATH"* ]]; then
install_cmd="$python_cmd -m pip install -q -r requirements.txt" install_output=$("$python_cmd" -m pip install -q -r requirements.txt 2>&1) || exit_code=$?
else else
install_cmd="$python_cmd -m pip install -q --user -r requirements.txt" install_output=$("$python_cmd" -m pip install -q --user -r requirements.txt 2>&1) || exit_code=$?
fi fi
# Install packages with better error handling
echo -n "Downloading packages..."
local install_output
local install_error
# Capture both stdout and stderr
install_output=$($install_cmd 2>&1)
local exit_code=$?
if [[ $exit_code -ne 0 ]]; then if [[ $exit_code -ne 0 ]]; then
echo -e "\r${RED}✗ Setup failed${NC} " echo -e "\r${RED}✗ Setup failed${NC} "
echo "" echo ""