-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·176 lines (148 loc) · 5.13 KB
/
setup.py
File metadata and controls
executable file
·176 lines (148 loc) · 5.13 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env python3
"""
CrisisCast Setup Script
"""
import os
import sys
import subprocess
import asyncio
from pathlib import Path
def run_command(command, description):
"""Run a command and handle errors"""
print(f"🔄 {description}...")
try:
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
print(f"✅ {description} completed")
return True
except subprocess.CalledProcessError as e:
print(f"❌ {description} failed: {e}")
print(f"Error output: {e.stderr}")
return False
def check_python_version():
"""Check if Python version is compatible"""
if sys.version_info < (3, 8):
print("❌ Python 3.8 or higher is required")
sys.exit(1)
print(f"✅ Python {sys.version.split()[0]} detected")
def check_redis():
"""Check if Redis is available"""
try:
import redis
r = redis.Redis(host='localhost', port=6379, db=0)
r.ping()
print("✅ Redis is running")
return True
except Exception as e:
print(f"❌ Redis is not available: {e}")
print("Please install and start Redis:")
print(" macOS: brew install redis && brew services start redis")
print(" Ubuntu: sudo apt install redis-server && sudo systemctl start redis")
return False
def install_dependencies():
"""Install Python dependencies"""
return run_command("pip install -r requirements.txt", "Installing Python dependencies")
def create_directories():
"""Create necessary directories"""
directories = [
"data/raw",
"data/processed",
"data/models",
"logs"
]
for directory in directories:
os.makedirs(directory, exist_ok=True)
print(f"✅ Created directory: {directory}")
def setup_environment():
"""Set up environment file"""
env_file = Path(".env")
env_example = Path("config.env.example")
if not env_file.exists() and env_example.exists():
import shutil
shutil.copy(env_example, env_file)
print("✅ Created .env file from template")
print("⚠️ Please edit .env file with your API keys and configuration")
elif env_file.exists():
print("✅ .env file already exists")
else:
print("⚠️ No .env file found, please create one manually")
async def initialize_database():
"""Initialize the database"""
try:
sys.path.append(str(Path(__file__).parent))
from app.core.database import init_db
print("🔄 Initializing database...")
await init_db()
print("✅ Database initialized")
return True
except Exception as e:
print(f"❌ Database initialization failed: {e}")
return False
def make_executable():
"""Make scripts executable"""
scripts = [
"run.py",
"scripts/crisiscast_cli.py"
]
for script in scripts:
if os.path.exists(script):
os.chmod(script, 0o755)
print(f"✅ Made {script} executable")
def run_tests():
"""Run basic tests"""
print("🔄 Running basic tests...")
# Test imports
try:
sys.path.append(str(Path(__file__).parent))
from app.main import app
from app.core.config import settings
from app.services.ml_service import MLService
from app.services.data_ingestion import DataIngestionService
from app.services.alert_service import AlertService
print("✅ All imports successful")
except Exception as e:
print(f"❌ Import test failed: {e}")
return False
# Test configuration
try:
print(f"✅ Configuration loaded: {len(settings.supported_markets)} markets supported")
except Exception as e:
print(f"❌ Configuration test failed: {e}")
return False
return True
def main():
"""Main setup function"""
print("🚀 CrisisCast Setup")
print("=" * 50)
# Check Python version
check_python_version()
# Check Redis
if not check_redis():
print("\n⚠️ Redis is required for CrisisCast to function properly")
print("Please install and start Redis, then run this setup again")
return
# Install dependencies
if not install_dependencies():
print("❌ Setup failed during dependency installation")
return
# Create directories
create_directories()
# Setup environment
setup_environment()
# Make scripts executable
make_executable()
# Initialize database
if not asyncio.run(initialize_database()):
print("❌ Setup failed during database initialization")
return
# Run tests
if not run_tests():
print("❌ Setup failed during testing")
return
print("\n🎉 CrisisCast setup completed successfully!")
print("\nNext steps:")
print("1. Edit .env file with your API keys")
print("2. Start the API server: python run.py")
print("3. Use the CLI: python scripts/crisiscast_cli.py --help")
print("4. Visit http://localhost:8000/docs for API documentation")
if __name__ == "__main__":
main()