Repository navigation
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·175 lines (148 loc) · 5.43 KB
/
Copy pathsetup.py
File metadata and controls
executable file
·175 lines (148 loc) · 5.43 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
#!/usr/bin/env python3
"""
Setup script for Task Manager with Claude Code CI/CD Integration
"""
import os
import sys
import subprocess
import platform
def run_command(command, description, check=True):
"""Run a shell command with error handling."""
print(f"🔧 {description}...")
try:
result = subprocess.run(command, shell=True, check=check, capture_output=True, text=True)
if result.returncode == 0:
print(f"✅ {description} completed successfully")
return True
else:
print(f"❌ {description} failed:")
print(result.stderr)
return False
except subprocess.CalledProcessError as e:
print(f"❌ {description} failed with error: {e}")
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} detected")
return True
def setup_virtual_environment():
"""Create and activate virtual environment."""
if os.path.exists('venv'):
print("✅ Virtual environment already exists")
return True
success = run_command('python -m venv venv', 'Creating virtual environment')
if success:
print("💡 To activate the virtual environment:")
if platform.system() == "Windows":
print(" venv\\Scripts\\activate")
else:
print(" source venv/bin/activate")
return success
def install_dependencies():
"""Install Python dependencies."""
# Check if we're in a virtual environment
if hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix):
print("✅ Virtual environment detected")
else:
print("⚠️ Not in a virtual environment. Consider activating venv first.")
commands = [
('pip install --upgrade pip', 'Upgrading pip'),
('pip install -r requirements.txt', 'Installing dependencies')
]
for command, description in commands:
if not run_command(command, description):
return False
return True
def run_tests():
"""Run the test suite."""
return run_command('pytest -v', 'Running tests', check=False)
def check_code_quality():
"""Run code quality checks."""
commands = [
('flake8 --select=E9,F63,F7,F82 .', 'Checking syntax errors'),
('black --check .', 'Checking code formatting'),
('isort --check-only .', 'Checking import order')
]
all_passed = True
for command, description in commands:
if not run_command(command, description, check=False):
all_passed = False
return all_passed
def create_env_file():
"""Create a sample .env file."""
env_content = """# Environment variables for Task Manager
# Copy this file to .env and update the values
# Flask Configuration
FLASK_ENV=development
SECRET_KEY=your-secret-key-here
# Claude Code Integration (optional)
ANTHROPIC_API_KEY=your-anthropic-api-key-here
# GitHub Actions (for CI/CD)
GITHUB_TOKEN=your-github-token
WEBHOOK_URL=http://localhost:5000/webhook/build-failure
# Render Deployment (optional)
RENDER_SERVICE_ID=your-render-service-id
RENDER_API_KEY=your-render-api-key
RENDER_SERVICE_URL=your-deployed-app-url
"""
if not os.path.exists('.env.example'):
with open('.env.example', 'w') as f:
f.write(env_content)
print("✅ Created .env.example file")
print("💡 Copy .env.example to .env and update the values")
else:
print("✅ .env.example already exists")
def main():
"""Main setup function."""
print("🚀 Setting up Task Manager with Claude Code CI/CD Integration")
print("=" * 60)
# Check Python version
if not check_python_version():
sys.exit(1)
# Setup virtual environment
if not setup_virtual_environment():
print("❌ Failed to setup virtual environment")
sys.exit(1)
# Install dependencies
if not install_dependencies():
print("❌ Failed to install dependencies")
sys.exit(1)
# Create environment file
create_env_file()
# Run tests
print("\n🧪 Running tests...")
if run_tests():
print("✅ All tests passed!")
else:
print("⚠️ Some tests failed. Check the output above.")
# Check code quality
print("\n🔍 Checking code quality...")
if check_code_quality():
print("✅ Code quality checks passed!")
else:
print("⚠️ Code quality issues found. Run the following to fix:")
print(" black .")
print(" isort .")
print("\n" + "=" * 60)
print("🎉 Setup completed!")
print("\nNext steps:")
print("1. Activate virtual environment:")
if platform.system() == "Windows":
print(" venv\\Scripts\\activate")
else:
print(" source venv/bin/activate")
print("2. Copy .env.example to .env and update values")
print("3. Run the application:")
print(" python app.py")
print("4. Open http://localhost:5000 in your browser")
print("\nFor CI/CD integration:")
print("- Push to GitHub repository")
print("- Configure GitHub secrets")
print("- Set up Render deployment")
print("\nSee README.md for detailed instructions.")
if __name__ == '__main__':
main()