#!/usr/bin/env python3 """ Dependency Update and Compatibility Verification Script Updates all Python dependencies to latest 2025 versions with compatibility checks """ import subprocess import sys import pkg_resources import json from pathlib import Path def run_command(cmd, check=True): """Run a shell command and return the result""" try: result = subprocess.run(cmd, shell=True, capture_output=True, text=True, check=check) return result.stdout.strip(), result.stderr.strip(), result.returncode except subprocess.CalledProcessError as e: return e.stdout, e.stderr, e.returncode def check_python_version(): """Check if Python version is compatible""" version = sys.version_info print(f"๐Ÿ Python version: {version.major}.{version.minor}.{version.micro}") if version.major < 3 or (version.major == 3 and version.minor < 8): print("โŒ Python 3.8+ is required for this project") return False elif version.minor >= 11: print("โœ… Python version is optimal for 2025 dependencies") else: print("โš ๏ธ Consider upgrading to Python 3.11+ for best compatibility") return True def backup_requirements(): """Create a backup of current requirements""" backup_file = "requirements_backup.txt" try: subprocess.run(["pip", "freeze"], stdout=open(backup_file, 'w'), check=True) print(f"โœ… Created backup: {backup_file}") return True except Exception as e: print(f"โŒ Failed to create backup: {e}") return False def update_pip_tools(): """Update pip and essential tools""" print("\n๐Ÿ”ง Updating pip and essential tools...") commands = [ "python -m pip install --upgrade pip", "pip install --upgrade setuptools wheel", "pip install --upgrade pip-tools pip-check" ] for cmd in commands: print(f"Running: {cmd}") stdout, stderr, code = run_command(cmd, check=False) if code == 0: print(f"โœ… Success") else: print(f"โš ๏ธ Warning: {stderr}") def install_dependencies(): """Install updated dependencies""" print("\n๐Ÿ“ฆ Installing updated dependencies...") cmd = "pip install -r requirements.txt" print(f"Running: {cmd}") stdout, stderr, code = run_command(cmd, check=False) if code == 0: print("โœ… Dependencies installed successfully") return True else: print(f"โŒ Installation failed: {stderr}") return False def check_compatibility(): """Check for dependency conflicts""" print("\n๐Ÿ” Checking for dependency conflicts...") stdout, stderr, code = run_command("pip check", check=False) if code == 0: print("โœ… No dependency conflicts found") return True else: print(f"โš ๏ธ Dependency conflicts detected:") print(stderr) return False def verify_key_imports(): """Verify that key packages can be imported""" print("\n๐Ÿงช Testing key package imports...") key_packages = [ ("torch", "PyTorch"), ("numpy", "NumPy"), ("aiohttp", "aiohttp"), ("websockets", "websockets"), ("openai", "OpenAI"), ("elevenlabs", "ElevenLabs"), ("kokoro_tts", "Kokoro TTS"), ("edge_tts", "Edge TTS"), ("loguru", "Loguru"), ("requests", "Requests") ] results = [] for package, name in key_packages: try: __import__(package) print(f"โœ… {name}: OK") results.append((name, True, None)) except ImportError as e: print(f"โŒ {name}: FAILED - {e}") results.append((name, False, str(e))) except Exception as e: print(f"โš ๏ธ {name}: WARNING - {e}") results.append((name, False, str(e))) return results def generate_report(import_results): """Generate a compatibility report""" print("\n๐Ÿ“Š COMPATIBILITY REPORT") print("=" * 50) total = len(import_results) passed = sum(1 for _, success, _ in import_results if success) print(f"Total packages tested: {total}") print(f"Successfully imported: {passed}") print(f"Failed imports: {total - passed}") print(f"Success rate: {(passed/total)*100:.1f}%") if passed == total: print("\n๐ŸŽ‰ ALL DEPENDENCIES ARE COMPATIBLE!") print("โœ… Ready for production use") else: print("\nโš ๏ธ SOME DEPENDENCIES NEED ATTENTION:") for name, success, error in import_results: if not success: print(f"โŒ {name}: {error}") return passed == total def main(): """Main update and verification process""" print("๐Ÿš€ Python Dependencies Update & Compatibility Check") print("=" * 60) # Step 1: Check Python version if not check_python_version(): return False # Step 2: Create backup if not backup_requirements(): return False # Step 3: Update pip and tools update_pip_tools() # Step 4: Install dependencies if not install_dependencies(): print("\nโŒ Dependency installation failed!") print("๐Ÿ’ก Try restoring from backup: pip install -r requirements_backup.txt") return False # Step 5: Check compatibility compatible = check_compatibility() # Step 6: Test imports import_results = verify_key_imports() # Step 7: Generate report all_good = generate_report(import_results) if all_good and compatible: print("\n๐ŸŽ‰ UPDATE SUCCESSFUL!") print("โœ… All dependencies updated to latest 2025 versions") print("โœ… No compatibility issues detected") print("โœ… All key packages import successfully") else: print("\nโš ๏ธ UPDATE COMPLETED WITH WARNINGS") print("๐Ÿ’ก Review the issues above and consider:") print(" - Checking package documentation for breaking changes") print(" - Running your application tests") print(" - Restoring from backup if needed") return all_good and compatible if __name__ == "__main__": success = main() sys.exit(0 if success else 1)