-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
128 lines (99 loc) Β· 3.86 KB
/
setup.py
File metadata and controls
128 lines (99 loc) Β· 3.86 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
#!/usr/bin/env python
"""
Setup script for Data Lake API project.
This script helps with initial project setup and configuration.
"""
import os
import sys
import subprocess
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 successfully")
return True
except subprocess.CalledProcessError as e:
print(f"β {description} failed: {e.stderr}")
return False
def check_python_version():
"""Check if Python version is compatible."""
version = sys.version_info
if version.major < 3 or (version.major == 3 and version.minor < 8):
print("β Python 3.8+ is required")
return False
print(f"β
Python {version.major}.{version.minor}.{version.micro} is compatible")
return True
def check_dependencies():
"""Check if required system dependencies are installed."""
dependencies = {
'python': 'python --version',
'pip': 'pip --version',
'git': 'git --version'
}
for name, command in dependencies.items():
if not run_command(command, f"Checking {name}"):
return False
return True
def setup_virtual_environment():
"""Create and activate virtual environment."""
venv_path = Path("venv")
if venv_path.exists():
print("β
Virtual environment already exists")
return True
if not run_command("python -m venv venv", "Creating virtual environment"):
return False
print("π To activate the virtual environment:")
print(" Windows: venv\\Scripts\\activate")
print(" macOS/Linux: source venv/bin/activate")
return True
def install_requirements():
"""Install Python requirements."""
if not Path("requirements.txt").exists():
print("β requirements.txt not found")
return False
return run_command("pip install -r requirements.txt", "Installing Python dependencies")
def setup_database():
"""Provide database setup instructions."""
print("\nποΈ Database Setup Required:")
print("1. Install PostgreSQL if not already installed")
print("2. Create a database named 'api_project'")
print("3. Update database settings in api_project/api_project/settings.py")
print("4. Run migrations: python manage.py migrate")
print("5. Create superuser: python manage.py createsuperuser")
def main():
"""Main setup function."""
print("π Data Lake API Setup Script")
print("=" * 40)
# Check system requirements
if not check_python_version():
sys.exit(1)
if not check_dependencies():
print("β Please install missing dependencies")
sys.exit(1)
# Setup virtual environment
if not setup_virtual_environment():
sys.exit(1)
# Install requirements
print("\nπ¦ Installing Python dependencies...")
print("β οΈ Make sure to activate your virtual environment first!")
response = input("Have you activated the virtual environment? (y/n): ")
if response.lower() != 'y':
print("Please activate the virtual environment and run this script again")
sys.exit(1)
if not install_requirements():
sys.exit(1)
# Database setup instructions
setup_database()
print("\nπ Setup completed successfully!")
print("\nπ Next steps:")
print("1. Activate virtual environment")
print("2. Set up PostgreSQL database")
print("3. Update settings.py with database credentials")
print("4. Run: python manage.py migrate")
print("5. Run: python manage.py createsuperuser")
print("6. Run: python manage.py runserver")
print("7. Visit: http://127.0.0.1:8000/")
if __name__ == "__main__":
main()