-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
Β·147 lines (124 loc) Β· 4.88 KB
/
setup.py
File metadata and controls
executable file
Β·147 lines (124 loc) Β· 4.88 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
#!/usr/bin/env python3
"""
Expense Tracker Setup Script
This script helps set up the backend environment and validates the installation.
"""
import os
import subprocess
import sys
from pathlib import Path
def run_command(command, description):
"""Run a command and return success status"""
print(f"π {description}...")
try:
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
print(f"β
{description} - Success")
return True
except subprocess.CalledProcessError as e:
print(f"β {description} - Failed")
print(f"Error: {e.stderr}")
return False
def check_python_version():
"""Check if Python version is compatible"""
print("π Checking Python version...")
if sys.version_info < (3, 8):
print("β Python 3.8 or higher is required")
return False
print(f"β
Python {sys.version_info.major}.{sys.version_info.minor} detected")
return True
def setup_virtual_environment():
"""Set up virtual environment"""
backend_dir = Path("backend")
venv_dir = backend_dir / "venv"
if not venv_dir.exists():
print("π§ Creating virtual environment...")
if not run_command(f"python3 -m venv {venv_dir}", "Creating venv"):
return False
else:
print("β
Virtual environment already exists")
return True
def install_dependencies():
"""Install Python dependencies"""
backend_dir = Path("backend")
os.chdir(backend_dir)
# Check if we're in a virtual environment
if 'VIRTUAL_ENV' not in os.environ:
print("β οΈ Virtual environment not activated")
print("Please run: source backend/venv/bin/activate (or backend\\venv\\Scripts\\activate on Windows)")
return False
return run_command("pip install -r requirements.txt", "Installing dependencies")
def setup_environment_file():
"""Set up environment file"""
backend_dir = Path("backend")
env_file = backend_dir / ".env"
env_example = backend_dir / ".env.example"
if not env_file.exists():
if env_example.exists():
print("π Creating .env file from template...")
with open(env_example, 'r') as f:
content = f.read()
with open(env_file, 'w') as f:
f.write(content)
print("β
.env file created")
print("β οΈ Please edit .env file with your actual credentials:")
print(" - SUPABASE_URL")
print(" - SUPABASE_KEY")
print(" - SUPABASE_SERVICE_KEY")
print(" - JWT_SECRET")
print(" - ANTHROPIC_API_KEY")
else:
print("β .env.example not found")
return False
else:
print("β
.env file already exists")
return True
def run_tests():
"""Run basic tests"""
print("π§ͺ Running core functionality tests...")
# Test core functionality without dependencies
if run_command("python3 test_core_functionality.py", "Core functionality tests"):
print("β
Core tests passed")
else:
print("β Core tests failed")
return False
# Test Claude integration structure
if run_command("python3 test_claude_categorization.py", "Claude integration tests"):
print("β
Claude integration tests passed")
else:
print("β Claude integration tests failed")
return False
return True
def main():
"""Main setup function"""
print("π Expense Tracker Backend Setup")
print("=" * 50)
# Check if we're in the right directory
if not Path("backend").exists():
print("β Please run this script from the ExpenseTracker root directory")
return False
steps = [
("Check Python Version", check_python_version),
("Setup Virtual Environment", setup_virtual_environment),
("Setup Environment File", setup_environment_file),
("Run Basic Tests", run_tests)
]
for step_name, step_func in steps:
print(f"\nπ Step: {step_name}")
if not step_func():
print(f"\nβ Setup failed at: {step_name}")
return False
print("\n" + "=" * 50)
print("π Setup completed successfully!")
print("\nπ Next Steps:")
print("1. Activate virtual environment: source backend/venv/bin/activate")
print("2. Install dependencies: cd backend && pip install -r requirements.txt")
print("3. Edit backend/.env with your API credentials")
print("4. Set up Supabase database with the provided schema")
print("5. Run the backend: cd backend && python main.py")
print("6. Test API at: http://localhost:8000")
print("\nπ Get Claude API key: https://console.anthropic.com")
print("π Set up Supabase: https://supabase.com")
return True
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)