Spaces:
Build error
Build error
| #!/usr/bin/env python3 | |
| """Verify AudioForge backend setup.""" | |
| import sys | |
| from pathlib import Path | |
| # Fix Windows console encoding | |
| if sys.platform == "win32": | |
| import io | |
| sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace') | |
| sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='replace') | |
| def check_python_version(): | |
| """Check Python version.""" | |
| if sys.version_info < (3, 11): | |
| print("[ERROR] Python 3.11+ required") | |
| print(f" Current version: {sys.version}") | |
| return False | |
| print(f"[OK] Python version: {sys.version.split()[0]}") | |
| return True | |
| def check_dependencies(): | |
| """Check if dependencies are installed.""" | |
| required_packages = [ | |
| "fastapi", | |
| "uvicorn", | |
| "pydantic", | |
| "sqlalchemy", | |
| "structlog", | |
| "torch", | |
| "librosa", | |
| ] | |
| missing = [] | |
| for package in required_packages: | |
| try: | |
| __import__(package) | |
| except ImportError: | |
| missing.append(package) | |
| if missing: | |
| print(f"[ERROR] Missing packages: {', '.join(missing)}") | |
| print(" Run: uv pip install -e '.[dev]'") | |
| return False | |
| print("[OK] All required packages installed") | |
| return True | |
| def check_env_file(): | |
| """Check if .env file exists.""" | |
| env_path = Path(".env") | |
| env_example = Path(".env.example") | |
| if not env_path.exists(): | |
| if env_example.exists(): | |
| print("[WARN] .env file not found") | |
| print(" Creating .env from .env.example...") | |
| import shutil | |
| shutil.copy(env_example, env_path) | |
| print("[OK] .env file created (please review and configure)") | |
| return True | |
| else: | |
| print("[ERROR] .env.example not found") | |
| return False | |
| print("[OK] .env file exists") | |
| return True | |
| def check_storage_dirs(): | |
| """Check if storage directories exist.""" | |
| storage_path = Path("storage/audio") | |
| required_dirs = ["music", "vocals", "mixed", "mastered"] | |
| missing = [] | |
| for subdir in required_dirs: | |
| dir_path = storage_path / subdir | |
| if not dir_path.exists(): | |
| missing.append(str(dir_path)) | |
| if missing: | |
| print(f"[WARN] Missing storage directories:") | |
| for d in missing: | |
| print(f" {d}") | |
| print(" Creating directories...") | |
| for d in missing: | |
| Path(d).mkdir(parents=True, exist_ok=True) | |
| print("[OK] Storage directories created") | |
| else: | |
| print("[OK] Storage directories exist") | |
| return True | |
| def check_database_config(): | |
| """Check database configuration.""" | |
| try: | |
| from app.core.config import settings | |
| db_url = settings.DATABASE_URL | |
| if "postgresql" in db_url: | |
| print("[OK] Database URL configured") | |
| return True | |
| else: | |
| print("[WARN] Database URL may be incorrect") | |
| return False | |
| except ImportError as e: | |
| print(f"[WARN] Cannot check config (dependencies not installed): {e}") | |
| print(" Install dependencies first: uv pip install -e '.[dev]'") | |
| return False | |
| except Exception as e: | |
| print(f"[ERROR] Error loading config: {e}") | |
| return False | |
| def main(): | |
| """Run all checks.""" | |
| print("AudioForge Backend Setup Verification") | |
| print("=" * 50) | |
| print() | |
| checks = [ | |
| ("Python Version", check_python_version), | |
| ("Dependencies", check_dependencies), | |
| ("Environment File", check_env_file), | |
| ("Storage Directories", check_storage_dirs), | |
| ("Database Config", check_database_config), | |
| ] | |
| results = [] | |
| for name, check_func in checks: | |
| print(f"\n{name}:") | |
| result = check_func() | |
| results.append(result) | |
| print("\n" + "=" * 50) | |
| if all(results): | |
| print("[OK] All checks passed! Ready to run.") | |
| return 0 | |
| else: | |
| print("[ERROR] Some checks failed. Please fix issues above.") | |
| return 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |