File size: 2,544 Bytes
32519eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import sys
import subprocess
import logging
from pathlib import Path

# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

def check_python_version():
    """Check if Python version is compatible"""
    if sys.version_info < (3, 11):
        logger.error("Python 3.11 or higher is required")
        sys.exit(1)
    logger.info(f"Python version {sys.version_info.major}.{sys.version_info.minor} detected")

def create_virtual_environment():
    """Create and activate virtual environment"""
    venv_name = "synthex_env"
    if not os.path.exists(venv_name):
        logger.info(f"Creating virtual environment: {venv_name}")
        subprocess.run([sys.executable, "-m", "venv", venv_name], check=True)
    else:
        logger.info(f"Virtual environment {venv_name} already exists")

def install_requirements():
    """Install required packages"""
    logger.info("Installing requirements...")
    subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"], check=True)

def create_directories():
    """Create necessary directories"""
    directories = [
        "data/raw",
        "data/processed",
        "data/reports",
        "data/reports/plots"
    ]
    for directory in directories:
        Path(directory).mkdir(parents=True, exist_ok=True)
        logger.info(f"Created directory: {directory}")

def setup_environment():
    """Setup the complete environment"""
    try:
        logger.info("Starting environment setup...")
        
        # Check Python version
        check_python_version()
        
        # Create virtual environment
        create_virtual_environment()
        
        # Install requirements
        install_requirements()
        
        # Create directories
        create_directories()
        
        logger.info("Environment setup completed successfully!")
        logger.info("\nNext steps:")
        logger.info("1. Activate the virtual environment:")
        logger.info("   - Windows: synthex_env\\Scripts\\activate")
        logger.info("   - Unix/MacOS: source synthex_env/bin/activate")
        logger.info("2. Run data collection: python setup_data.py")
        logger.info("3. Analyze data quality: python analyze_data_quality.py")
        
    except subprocess.CalledProcessError as e:
        logger.error(f"Error during setup: {str(e)}")
        sys.exit(1)
    except Exception as e:
        logger.error(f"Unexpected error: {str(e)}")
        sys.exit(1)

if __name__ == "__main__":
    setup_environment()