Spaces:
Build error
Build error
| #!/usr/bin/env python3 | |
| """Quick setup script for AudioForge backend.""" | |
| import sys | |
| import subprocess | |
| 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 run_command(cmd: list[str], description: str) -> bool: | |
| """Run a command and return success status.""" | |
| print(f"\n{description}...") | |
| try: | |
| result = subprocess.run(cmd, check=True, capture_output=True, text=True) | |
| print(f"[OK] {description} completed") | |
| return True | |
| except subprocess.CalledProcessError as e: | |
| print(f"[ERROR] {description} failed: {e.stderr}") | |
| return False | |
| except FileNotFoundError: | |
| print(f"[ERROR] Command not found. Please install required tools.") | |
| return False | |
| def main(): | |
| """Run quick setup.""" | |
| print("AudioForge Quick Setup") | |
| print("=" * 50) | |
| # Check Python version | |
| if sys.version_info < (3, 11): | |
| print(f"[ERROR] Python 3.11+ required. Current: {sys.version}") | |
| return 1 | |
| # Change to backend directory | |
| backend_dir = Path(__file__).parent.parent | |
| import os | |
| os.chdir(backend_dir) | |
| # Create virtual environment if needed | |
| venv_path = Path(".venv") | |
| if not venv_path.exists(): | |
| print("\nCreating virtual environment...") | |
| if not run_command([sys.executable, "-m", "venv", ".venv"], "Create venv"): | |
| return 1 | |
| # Determine activation script | |
| if sys.platform == "win32": | |
| python_exe = venv_path / "Scripts" / "python.exe" | |
| pip_exe = venv_path / "Scripts" / "pip.exe" | |
| else: | |
| python_exe = venv_path / "bin" / "python" | |
| pip_exe = venv_path / "bin" / "pip" | |
| # Install uv | |
| print("\nInstalling uv...") | |
| if not run_command([str(pip_exe), "install", "uv"], "Install uv"): | |
| return 1 | |
| # Install dependencies | |
| print("\nInstalling dependencies (this may take a few minutes)...") | |
| uv_cmd = str(venv_path / "Scripts" / "uv.exe") if sys.platform == "win32" else str(venv_path / "bin" / "uv") | |
| if not Path(uv_cmd).exists(): | |
| uv_cmd = "uv" # Fallback to system uv | |
| if not run_command([uv_cmd, "pip", "install", "-e", ".[dev]"], "Install dependencies"): | |
| return 1 | |
| # Create .env file | |
| env_path = Path(".env") | |
| env_example = Path(".env.example") | |
| if not env_path.exists() and env_example.exists(): | |
| print("\nCreating .env file...") | |
| import shutil | |
| shutil.copy(env_example, env_path) | |
| print("[OK] .env file created") | |
| # Create storage directories | |
| print("\nCreating storage directories...") | |
| storage_path = Path("storage/audio") | |
| for subdir in ["music", "vocals", "mixed", "mastered"]: | |
| (storage_path / subdir).mkdir(parents=True, exist_ok=True) | |
| print("[OK] Storage directories created") | |
| print("\n" + "=" * 50) | |
| print("[OK] Setup complete!") | |
| print("\nNext steps:") | |
| print("1. Edit .env with your database and Redis URLs") | |
| print("2. Start PostgreSQL and Redis (or use docker-compose)") | |
| print("3. Run: python scripts/init_db.py") | |
| print("4. Run: uvicorn app.main:app --reload") | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |