File size: 3,495 Bytes
09fa60b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/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())