-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
137 lines (114 loc) · 4.02 KB
/
setup.py
File metadata and controls
137 lines (114 loc) · 4.02 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
#!/usr/bin/env python3
"""
Setup script for the Voting System
This script helps you set up the development environment quickly.
"""
import os
import sys
import subprocess
import shutil
from pathlib import Path
def run_command(command, cwd=None):
"""Run a command and return the result"""
try:
result = subprocess.run(command, shell=True, check=True, cwd=cwd, capture_output=True, text=True)
return True, result.stdout
except subprocess.CalledProcessError as e:
return False, e.stderr
def check_python_version():
"""Check if Python version is compatible"""
if sys.version_info < (3, 8):
print("❌ Python 3.8+ is required")
return False
print(f"✅ Python {sys.version_info.major}.{sys.version_info.minor} detected")
return True
def check_node_version():
"""Check if Node.js is installed"""
success, output = run_command("node --version")
if success:
print(f"✅ Node.js {output.strip()} detected")
return True
else:
print("❌ Node.js is not installed. Please install Node.js 16+")
return False
def setup_backend():
"""Set up the backend"""
print("\n🔧 Setting up backend...")
backend_dir = Path("backend")
if not backend_dir.exists():
print("❌ Backend directory not found")
return False
# Create virtual environment
print("Creating virtual environment...")
success, output = run_command("python -m venv venv", cwd=backend_dir)
if not success:
print(f"❌ Failed to create virtual environment: {output}")
return False
# Determine activation command based on OS
if os.name == 'nt': # Windows
activate_cmd = "venv\\Scripts\\activate"
pip_cmd = "venv\\Scripts\\pip"
else: # Unix/Linux/Mac
activate_cmd = "source venv/bin/activate"
pip_cmd = "venv/bin/pip"
# Install dependencies
print("Installing Python dependencies...")
success, output = run_command(f"{pip_cmd} install -r requirements.txt", cwd=backend_dir)
if not success:
print(f"❌ Failed to install dependencies: {output}")
return False
# Create .env file if it doesn't exist
env_file = backend_dir / ".env"
env_example = backend_dir / "env.example"
if not env_file.exists() and env_example.exists():
print("Creating .env file...")
shutil.copy(env_example, env_file)
print("✅ Backend setup complete!")
else:
print("✅ Backend setup complete!")
return True
def setup_frontend():
"""Set up the frontend"""
print("\n🔧 Setting up frontend...")
frontend_dir = Path("frontend")
if not frontend_dir.exists():
print("❌ Frontend directory not found")
return False
# Install dependencies
print("Installing Node.js dependencies...")
success, output = run_command("npm install", cwd=frontend_dir)
if not success:
print(f"❌ Failed to install dependencies: {output}")
return False
print("✅ Frontend setup complete!")
return True
def main():
"""Main setup function"""
print("🚀 Setting up Voting System...")
# Check prerequisites
if not check_python_version():
return
if not check_node_version():
return
# Set up backend
if not setup_backend():
return
# Set up frontend
if not setup_frontend():
return
print("\n🎉 Setup complete!")
print("\n📋 Next steps:")
print("1. Start the backend:")
print(" cd backend")
print(" # On Windows:")
print(" venv\\Scripts\\activate")
print(" # On Unix/Linux/Mac:")
print(" source venv/bin/activate")
print(" uvicorn app.main:app --reload --host 0.0.0.0 --port 8000")
print("\n2. Start the frontend (in a new terminal):")
print(" cd frontend")
print(" npm run dev")
print("\n3. Open your browser to http://localhost:3000")
print("\n4. Register a new account and start voting!")
if __name__ == "__main__":
main()