-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
177 lines (138 loc) · 4.6 KB
/
setup.sh
File metadata and controls
177 lines (138 loc) · 4.6 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
177
#!/bin/bash
# ============= Python CI/CD Project Setup Script =============
# Automated setup for the complete project environment
# Sets up virtual environment, installs dependencies, and verifies setup
set -e # Exit on error
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# ============= HELPER FUNCTIONS =============
print_header() {
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}$1${NC}"
echo -e "${BLUE}========================================${NC}"
}
print_success() {
echo -e "${GREEN}✅ $1${NC}"
}
print_error() {
echo -e "${RED}❌ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_step() {
echo -e "${BLUE}→ $1${NC}"
}
# ============= PRE-FLIGHT CHECKS =============
print_header "Pre-Flight Checks"
# Check Python installation
print_step "Checking Python installation..."
if ! command -v python3 &> /dev/null; then
print_error "Python is not installed. Please install Python 3.9+"
exit 1
fi
python_version=$(python3 --version | awk '{print $2}')
print_success "Python $python_version found"
# Check Git installation
print_step "Checking Git installation..."
if ! command -v git &> /dev/null; then
print_warning "Git is not installed. Some features may not work."
else
print_success "Git found"
fi
# ============= DIRECTORY STRUCTURE =============
# print_header "Creating Directory Structure"
# print_step "Creating app directory..."
# mkdir -p app
# print_success "app/ directory ready"
# print_step "Creating tests directory..."
# mkdir -p tests
# print_success "tests/ directory ready"
# print_step "Creating .github/workflows directory..."
# mkdir -p .github/workflows
# print_success ".github/workflows/ directory ready"
# ============= VIRTUAL ENVIRONMENT =============
print_header "Setting Up Virtual Environment"
if [ -d "venv" ]; then
print_warning "Virtual environment already exists. Skipping creation."
else
print_step "Creating virtual environment..."
python3 -m venv venv
print_success "Virtual environment created"
fi
print_step "Activating virtual environment..."
source venv/bin/activate
print_success "Virtual environment activated"
# ============= DEPENDENCY INSTALLATION =============
print_header "Installing Dependencies"
print_step "Upgrading pip..."
pip install --upgrade pip > /dev/null 2>&1
print_success "pip upgraded"
if [ -f "requirements.txt" ]; then
print_step "Installing dependencies from requirements.txt..."
pip install -r requirements.txt > /dev/null 2>&1
print_success "Dependencies installed"
else
print_warning "requirements.txt not found. Skipping dependency installation."
fi
# ============= GIT SETUP =============
print_header "Git Configuration"
if command -v git &> /dev/null; then
if [ -d ".git" ]; then
print_warning "Git repository already initialized. Skipping."
else
print_step "Initializing Git repository..."
git init > /dev/null 2>&1
print_success "Git repository initialized"
fi
if [ -f ".gitignore" ]; then
print_success ".gitignore found and configured"
fi
else
print_warning "Git not found. Skipping Git setup."
fi
# ============= VERIFICATION =============
print_header "Verifying Installation"
# Check Python
print_step "Verifying Python..."
python --version
print_success "Python verified"
# Check pip packages
print_step "Verifying installed packages..."
pip list | grep -E "Flask|pytest|requests" > /dev/null 2>&1
print_success "Key packages installed"
# Check directory structure
print_step "Verifying directory structure..."
if [ -d "app" ] && [ -d "tests" ] && [ -d ".github/workflows" ]; then
print_success "Directory structure verified"
else
print_error "Directory structure incomplete!"
exit 1
fi
# Check files
print_step "Checking for required files..."
required_files=("app/__init__.py" "tests/__init__.py" "Dockerfile" "requirements.txt")
for file in "${required_files[@]}"; do
if [ -f "$file" ]; then
print_success "$file found"
else
print_warning "$file not found (will be created separately)"
fi
done
# ============= SUMMARY =============
print_header "Setup Complete!"
echo ""
print_success "Project setup completed successfully!"
echo ""
echo -e "${BLUE}Next Steps:${NC}"
echo "1. Activate environment: ${YELLOW}source venv/bin/activate${NC}"
echo "2. Run tests: ${YELLOW}pytest tests/ -v${NC}"
echo "3. Start app: ${YELLOW}python -m flask run${NC}"
echo "4. Visit: ${YELLOW}http://localhost:5000${NC}"
echo ""
print_success "Ready to start learning! 🚀"
echo ""