#!/bin/bash # UnitForge uv System Check # Validates that uv is properly installed and working set -e # Load centralized color utility SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${SCRIPT_DIR}/scripts/colors.sh" echo -e "${BLUE}╔══════════════════════════════════════════════╗${NC}" echo -e "${BLUE}║ UnitForge uv System Check ║${NC}" echo -e "${BLUE}║ Validating uv Installation ║${NC}" echo -e "${BLUE}╚══════════════════════════════════════════════╝${NC}" echo "" # Function to check if command exists command_exists() { command -v "$1" >/dev/null 2>&1 } # Function to compare versions version_ge() { printf '%s\n%s\n' "$2" "$1" | sort -V -C } ERRORS=0 WARNINGS=0 echo -e "${CYAN}🔍 Checking system requirements...${NC}" echo "" # Check Python if command_exists python3; then PYTHON_VERSION=$(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 "${GREEN}✓ Python ${PYTHON_VERSION} found (>= 3.8 required)${NC}" else echo -e "${RED}✗ Python ${PYTHON_VERSION} found but 3.8+ required${NC}" ERRORS=$((ERRORS + 1)) fi else echo -e "${RED}✗ Python 3 not found${NC}" ERRORS=$((ERRORS + 1)) fi # Check uv if command_exists uv; then UV_VERSION=$(uv --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "unknown") echo -e "${GREEN}✓ uv ${UV_VERSION} found${NC}" # Test uv functionality echo -e "${CYAN} Testing uv functionality...${NC}" # Create temporary directory for testing TEMP_DIR=$(mktemp -d) cd "$TEMP_DIR" # Test uv venv creation if uv venv test-env >/dev/null 2>&1; then echo -e "${GREEN} ✓ uv venv creation works${NC}" # Test package installation if uv pip install --target ./test-env/lib/python*/site-packages click >/dev/null 2>&1; then echo -e "${GREEN} ✓ uv pip installation works${NC}" else echo -e "${YELLOW} ⚠ uv pip installation test failed${NC}" WARNINGS=$((WARNINGS + 1)) fi else echo -e "${YELLOW} ⚠ uv venv creation test failed${NC}" WARNINGS=$((WARNINGS + 1)) fi # Cleanup cd - >/dev/null rm -rf "$TEMP_DIR" else echo -e "${RED}✗ uv not found${NC}" echo -e "${YELLOW} Install with: curl -LsSf https://astral.sh/uv/install.sh | sh${NC}" ERRORS=$((ERRORS + 1)) fi echo "" # Check git (for pre-commit hooks) if command_exists git; then echo -e "${GREEN}✓ Git found${NC}" else echo -e "${YELLOW}⚠ Git not found (needed for pre-commit hooks)${NC}" WARNINGS=$((WARNINGS + 1)) fi # Check curl/wget (for installations) if command_exists curl; then echo -e "${GREEN}✓ curl found${NC}" elif command_exists wget; then echo -e "${GREEN}✓ wget found${NC}" else echo -e "${YELLOW}⚠ Neither curl nor wget found (may affect installations)${NC}" WARNINGS=$((WARNINGS + 1)) fi # Check Docker (optional) if command_exists docker; then DOCKER_VERSION=$(docker --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+' || echo "unknown") echo -e "${GREEN}✓ Docker ${DOCKER_VERSION} found (optional)${NC}" else echo -e "${YELLOW}ℹ Docker not found (optional for containerized development)${NC}" fi # Check make if command_exists make; then echo -e "${GREEN}✓ make found${NC}" else echo -e "${YELLOW}⚠ make not found (development commands will not work)${NC}" WARNINGS=$((WARNINGS + 1)) fi echo "" echo -e "${CYAN}📋 UnitForge project checks...${NC}" echo "" # Check if we're in UnitForge directory if [[ -f "pyproject.toml" && -f "unitforge-cli" ]]; then echo -e "${GREEN}✓ UnitForge project directory detected${NC}" # Check project structure if [[ -d "backend" && -d "frontend" && -d "tests" ]]; then echo -e "${GREEN}✓ Project structure is valid${NC}" else echo -e "${YELLOW}⚠ Some project directories missing${NC}" WARNINGS=$((WARNINGS + 1)) fi # Check if virtual environment exists if [[ -d ".venv" ]]; then success "Virtual environment is active" # Check if it's activated if [[ -n "${VIRTUAL_ENV}" ]]; then success "Virtual environment activated" else echo -e "${YELLOW}⚠ Virtual environment not activated${NC}" echo -e "${CYAN} Run: source .venv/bin/activate${NC}" WARNINGS=$((WARNINGS + 1)) fi else echo -e "${YELLOW}⚠ Virtual environment not found${NC}" echo -e "${CYAN} Run: make setup-dev${NC}" WARNINGS=$((WARNINGS + 1)) fi # Check CLI tool if [[ -x "unitforge-cli" ]]; then echo -e "${GREEN}✓ CLI tool is executable${NC}" else echo -e "${YELLOW}⚠ CLI tool not executable${NC}" echo -e "${CYAN} Run: chmod +x unitforge-cli${NC}" WARNINGS=$((WARNINGS + 1)) fi else echo -e "${YELLOW}⚠ Not in UnitForge project directory${NC}" echo -e "${CYAN} Navigate to UnitForge project root${NC}" WARNINGS=$((WARNINGS + 1)) fi echo "" echo -e "${CYAN}📊 Performance test...${NC}" echo "" # Quick performance test if command_exists uv; then echo -e "${BLUE}Testing uv performance (package list)...${NC}" START_TIME=$(date +%s.%N) uv pip list >/dev/null 2>&1 || true END_TIME=$(date +%s.%N) DURATION=$(echo "$END_TIME - $START_TIME" | bc -l 2>/dev/null || echo "N/A") if [[ "$DURATION" != "N/A" ]]; then echo -e "${GREEN}✓ uv pip list completed in ${DURATION}s${NC}" else success "Performance test completed" fi fi echo "" echo -e "${CYAN}📋 Summary${NC}" echo "" if [[ $ERRORS -eq 0 && $WARNINGS -eq 0 ]]; then echo -e "${GREEN}🎉 Perfect! Your system is fully ready for UnitForge development.${NC}" echo "" echo -e "${BLUE}Next steps:${NC}" echo -e " ${CYAN}make setup-dev # Setup development environment${NC}" echo -e " ${CYAN}make server # Start development server${NC}" echo -e " ${CYAN}make test # Run tests${NC}" elif [[ $ERRORS -eq 0 ]]; then echo -e "${YELLOW}⚠ Your system is mostly ready with ${WARNINGS} warning(s).${NC}" echo -e "${GREEN}You can proceed with development, but consider addressing the warnings.${NC}" echo "" echo -e "${BLUE}Recommended:${NC}" echo -e " ${CYAN}make setup-dev # This may resolve some warnings${NC}" else echo -e "${RED}❌ Your system has ${ERRORS} error(s) and ${WARNINGS} warning(s).${NC}" echo -e "${RED}Please resolve the errors before proceeding.${NC}" echo "" echo -e "${BLUE}Required actions:${NC}" if ! command_exists uv; then echo -e " ${CYAN}curl -LsSf https://astral.sh/uv/install.sh | sh${NC}" echo -e " ${CYAN}source ~/.bashrc # Or restart terminal${NC}" fi if ! command_exists python3; then echo -e " ${CYAN}Install Python 3.8+ from https://python.org${NC}" fi fi echo "" echo -e "${BLUE}Environment Information:${NC}" echo -e " ${CYAN}OS: $(uname -s) $(uname -r)${NC}" echo -e " ${CYAN}Architecture: $(uname -m)${NC}" echo -e " ${CYAN}Shell: ${SHELL}${NC}" if command_exists uv; then echo -e " ${CYAN}uv version: ${UV_VERSION}${NC}" fi if command_exists python3; then success "Python version: $PYTHON_VERSION" fi echo "" echo -e "${CYAN}For more information:${NC}" echo -e " ${BLUE}UnitForge: ${GITHUB_URL:-https://github.com/will666/unitforge}${NC}" echo -e " ${BLUE}uv docs: https://github.com/astral-sh/uv${NC}" # Exit with appropriate code if [[ $ERRORS -eq 0 ]]; then exit 0 else exit 1 fi