- Fixed Bootstrap bg-dark class to use better contrasting color - Added comprehensive text-muted contrast fixes for various contexts - Improved dark theme colors for better accessibility - Fixed CSS inheritance issues for code elements in dark contexts - All color choices meet WCAG AA contrast requirements
321 lines
9.4 KiB
Bash
Executable File
321 lines
9.4 KiB
Bash
Executable File
#!/bin/bash
|
||
set -e
|
||
|
||
# UnitForge Development Setup Script with uv
|
||
# This script sets up the development environment using uv for fast package management
|
||
|
||
# Load centralized color utility
|
||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
source "${SCRIPT_DIR}/scripts/colors.sh"
|
||
|
||
# Configuration
|
||
PROJECT_NAME="UnitForge"
|
||
PYTHON_VERSION="3.8"
|
||
UV_MIN_VERSION="0.1.0"
|
||
|
||
box_header "UnitForge Development Setup"
|
||
echo -e "${BLUE}║ ${PROJECT_NAME} Development Setup ║${NC}"
|
||
echo -e "${BLUE}║ Using uv Package Manager ║${NC}"
|
||
echo -e "${BLUE}╚══════════════════════════════════════════════╝${NC}"
|
||
echo ""
|
||
|
||
# Function to check if command exists
|
||
command_exists() {
|
||
command -v "$1" >/dev/null 2>&1
|
||
}
|
||
|
||
# Function to check version
|
||
version_ge() {
|
||
printf '%s\n%s\n' "$2" "$1" | sort -V -C
|
||
}
|
||
|
||
# Check if we're in the right directory
|
||
if [[ ! -f "pyproject.toml" ]]; then
|
||
echo -e "${RED}Error: pyproject.toml not found${NC}"
|
||
echo "Please run this script from the unitforge project root directory."
|
||
exit 1
|
||
fi
|
||
|
||
echo -e "${CYAN}🔍 Checking prerequisites...${NC}"
|
||
|
||
# Check Python version
|
||
if ! command_exists python3; then
|
||
echo -e "${RED}Error: Python 3 is not installed or not in PATH${NC}"
|
||
echo "Please install Python 3.8 or higher"
|
||
exit 1
|
||
fi
|
||
|
||
PYTHON_VERSION_ACTUAL=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
|
||
if ! python3 -c "import sys; exit(0 if sys.version_info >= (3, 8) else 1)"; then
|
||
echo -e "${RED}Error: Python ${PYTHON_VERSION}+ is required, but ${PYTHON_VERSION_ACTUAL} is installed${NC}"
|
||
exit 1
|
||
fi
|
||
|
||
echo -e "${GREEN}✓ Python ${PYTHON_VERSION_ACTUAL} found${NC}"
|
||
|
||
# Check for uv installation
|
||
if ! command_exists uv; then
|
||
echo -e "${YELLOW}⚠ uv not found. Installing uv...${NC}"
|
||
|
||
# Install uv using the official installer
|
||
if command_exists curl; then
|
||
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||
|
||
# Add uv to PATH for current session
|
||
export PATH="$HOME/.cargo/bin:$PATH"
|
||
|
||
# Source shell configuration to get uv in PATH
|
||
if [[ -f "$HOME/.bashrc" ]]; then
|
||
source "$HOME/.bashrc" 2>/dev/null || true
|
||
fi
|
||
if [[ -f "$HOME/.zshrc" ]]; then
|
||
source "$HOME/.zshrc" 2>/dev/null || true
|
||
fi
|
||
|
||
elif command_exists wget; then
|
||
wget -qO- https://astral.sh/uv/install.sh | sh
|
||
export PATH="$HOME/.cargo/bin:$PATH"
|
||
else
|
||
echo -e "${RED}Error: Neither curl nor wget found${NC}"
|
||
echo "Please install uv manually: https://github.com/astral-sh/uv"
|
||
echo "Visit: https://github.com/astral-sh/uv#installation"
|
||
exit 1
|
||
fi
|
||
|
||
# Check if uv is now available
|
||
if ! command_exists uv; then
|
||
echo -e "${RED}Error: Failed to install uv${NC}"
|
||
echo "Please install uv manually and restart this script"
|
||
echo "Installation guide: https://github.com/astral-sh/uv#installation"
|
||
exit 1
|
||
fi
|
||
|
||
success "Dependencies installed successfully"
|
||
else
|
||
success "uv found and ready"
|
||
fi
|
||
|
||
# Display uv version
|
||
UV_VERSION=$(uv --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "unknown")
|
||
echo -e "${BLUE} Version: ${UV_VERSION}${NC}"
|
||
|
||
echo ""
|
||
echo -e "${CYAN}🏗️ Setting up virtual environment...${NC}"
|
||
|
||
# Remove existing virtual environment if it exists
|
||
if [[ -d ".venv" ]]; then
|
||
info "Removing existing virtual environment..."
|
||
rm -rf .venv
|
||
fi
|
||
|
||
# Create virtual environment with uv
|
||
info "Creating virtual environment with Python ${PYTHON_VERSION}+..."
|
||
uv venv --python python3
|
||
|
||
# Activate virtual environment
|
||
source .venv/bin/activate
|
||
success "Virtual environment created successfully"
|
||
|
||
echo ""
|
||
echo -e "${CYAN}📦 Installing dependencies...${NC}"
|
||
|
||
# Install core dependencies
|
||
info "Installing project dependencies..."
|
||
uv pip install -e .
|
||
|
||
# Install development dependencies
|
||
info "Installing development dependencies..."
|
||
uv pip install -e ".[dev]"
|
||
|
||
# Install web dependencies
|
||
info "Installing web dependencies..."
|
||
uv pip install -e ".[web]"
|
||
|
||
success "Development dependencies installed"
|
||
|
||
echo ""
|
||
header "Setting up development tools"
|
||
|
||
# Install pre-commit hooks if available
|
||
if [[ -f ".pre-commit-config.yaml" ]]; then
|
||
info "Setting up pre-commit hooks..."
|
||
pre-commit install
|
||
success "Pre-commit hooks installed"
|
||
else
|
||
warning "No pre-commit configuration found, skipping..."
|
||
fi
|
||
|
||
# Create development configuration files
|
||
echo -e "${BLUE}Creating development configuration...${NC}"
|
||
|
||
# Create .env file for development
|
||
if [[ ! -f ".env" ]]; then
|
||
cat > .env << 'EOF'
|
||
# UnitForge Development Environment
|
||
DEBUG=true
|
||
LOG_LEVEL=debug
|
||
HOST=127.0.0.1
|
||
PORT=8000
|
||
RELOAD=true
|
||
|
||
# API Configuration
|
||
API_TITLE="UnitForge Development"
|
||
API_VERSION="1.0.0-dev"
|
||
|
||
# Security (for development only)
|
||
SECRET_KEY="dev-secret-key-change-in-production"
|
||
ALLOWED_HOSTS=["localhost", "127.0.0.1", "0.0.0.0"]
|
||
EOF
|
||
echo -e "${GREEN}✓ Created .env file for development${NC}"
|
||
else
|
||
echo -e "${YELLOW}ℹ .env file already exists, skipping...${NC}"
|
||
fi
|
||
|
||
# Create development script shortcuts
|
||
cat > dev.sh << 'EOF'
|
||
#!/bin/bash
|
||
# Development helper script
|
||
|
||
set -e
|
||
|
||
# Ensure virtual environment is activated
|
||
if [[ -z "${VIRTUAL_ENV}" ]]; then
|
||
source .venv/bin/activate
|
||
fi
|
||
|
||
case "$1" in
|
||
"server"|"serve")
|
||
echo "🚀 Starting development server..."
|
||
./start-server.sh --log-level debug
|
||
;;
|
||
"test")
|
||
echo "🧪 Running tests..."
|
||
uv run pytest tests/ -v "${@:2}"
|
||
;;
|
||
"test-watch")
|
||
echo "👀 Running tests in watch mode..."
|
||
uv run pytest tests/ -v --watch "${@:2}"
|
||
;;
|
||
"test-cov")
|
||
echo "📊 Running tests with coverage..."
|
||
uv run pytest tests/ --cov=backend --cov-report=html --cov-report=term "${@:2}"
|
||
;;
|
||
"lint")
|
||
echo "🔍 Running linters..."
|
||
uv run black --check backend/ tests/
|
||
uv run isort --check-only backend/ tests/
|
||
uv run flake8 backend/ tests/
|
||
;;
|
||
"format")
|
||
echo "✨ Formatting code..."
|
||
uv run black backend/ tests/
|
||
uv run isort backend/ tests/
|
||
;;
|
||
"type-check")
|
||
echo "🔎 Running type checks..."
|
||
uv run mypy backend/
|
||
;;
|
||
"cli")
|
||
echo "🖥️ Running CLI..."
|
||
./unitforge-cli "${@:2}"
|
||
;;
|
||
"install")
|
||
echo "📦 Installing/updating dependencies..."
|
||
uv pip install -e ".[dev,web]"
|
||
;;
|
||
"clean")
|
||
echo "🧹 Cleaning up..."
|
||
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
|
||
find . -type f -name "*.pyc" -delete 2>/dev/null || true
|
||
rm -rf .pytest_cache/ htmlcov/ .coverage
|
||
;;
|
||
"demo")
|
||
echo "🎮 Running demo..."
|
||
./demo.sh
|
||
;;
|
||
*)
|
||
echo "UnitForge Development Helper"
|
||
echo ""
|
||
echo "Usage: ./dev.sh <command>"
|
||
echo ""
|
||
echo "Commands:"
|
||
echo " server Start development server"
|
||
echo " test Run tests"
|
||
echo " test-watch Run tests in watch mode"
|
||
echo " test-cov Run tests with coverage"
|
||
echo " lint Run linters"
|
||
echo " format Format code"
|
||
echo " type-check Run type checks"
|
||
echo " cli Run CLI tool"
|
||
echo " install Install/update dependencies"
|
||
echo " clean Clean up cache files"
|
||
echo " demo Run interactive demo"
|
||
;;
|
||
esac
|
||
EOF
|
||
|
||
chmod +x dev.sh
|
||
echo -e "${GREEN}✓ Created development helper script (dev.sh)${NC}"
|
||
|
||
echo ""
|
||
echo -e "${CYAN}🧪 Running initial tests...${NC}"
|
||
|
||
# Run tests to verify everything is working
|
||
if python -m pytest tests/ -v --tb=short; then
|
||
success "All tests passed"
|
||
else
|
||
warning "Some tests failed, but setup is complete"
|
||
fi
|
||
|
||
echo ""
|
||
echo -e "${CYAN}📋 Verifying installation...${NC}"
|
||
|
||
# Verify CLI works
|
||
if ./unitforge-cli --help >/dev/null 2>&1; then
|
||
echo -e "${GREEN}✓ CLI tool working${NC}"
|
||
else
|
||
echo -e "${RED}✗ CLI tool not working${NC}"
|
||
fi
|
||
|
||
# Check if server can start (quick test)
|
||
echo -e "${BLUE}Testing server startup...${NC}"
|
||
timeout 5s python -c "
|
||
import sys
|
||
sys.path.insert(0, 'backend')
|
||
from app.main import app
|
||
print('✓ Server imports successfully')
|
||
" && echo -e "${GREEN}✓ Server configuration valid${NC}" || echo -e "${YELLOW}⚠ Server test incomplete${NC}"
|
||
|
||
echo ""
|
||
echo -e "${GREEN}🎉 Development environment setup complete!${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}Next steps:${NC}"
|
||
echo ""
|
||
echo -e "${CYAN} 1. Start the development server:${NC}"
|
||
echo -e " ${YELLOW}./dev.sh server${NC}"
|
||
echo ""
|
||
echo -e "${CYAN} 2. Run tests:${NC}"
|
||
echo -e " ${YELLOW}./dev.sh test${NC}"
|
||
echo ""
|
||
echo -e "${CYAN} 3. Try the CLI:${NC}"
|
||
echo -e " ${YELLOW}./dev.sh cli --help${NC}"
|
||
echo ""
|
||
echo -e "${CYAN} 4. Run the demo:${NC}"
|
||
echo -e " ${YELLOW}./dev.sh demo${NC}"
|
||
echo ""
|
||
echo -e "${CYAN} 5. Development workflow:${NC}"
|
||
echo -e " ${YELLOW}./dev.sh format ${NC}# Format code"
|
||
echo -e " ${YELLOW}./dev.sh lint ${NC}# Check code style"
|
||
echo -e " ${YELLOW}./dev.sh test-cov ${NC}# Test with coverage"
|
||
echo ""
|
||
echo -e "${BLUE}Virtual environment activated at: ${VIRTUAL_ENV}${NC}"
|
||
echo -e "${BLUE}Web interface will be available at: http://localhost:8000${NC}"
|
||
echo ""
|
||
echo -e "${GREEN}Happy coding! 🚀${NC}"
|
||
|
||
# Create activation reminder
|
||
echo ""
|
||
echo -e "${YELLOW}💡 To activate the virtual environment in future sessions:${NC}"
|
||
echo -e " ${CYAN}source .venv/bin/activate${NC}"
|
||
echo ""
|