-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy_helper.py
More file actions
217 lines (183 loc) · 6.04 KB
/
deploy_helper.py
File metadata and controls
217 lines (183 loc) · 6.04 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/usr/bin/env python3
"""
Deployment Helper Script
This script helps prepare the Option Pricing Platform for deployment
by setting up git repository and providing deployment instructions.
"""
import os
import subprocess
import sys
from pathlib import Path
def run_command(command, description):
"""Run a shell command and handle errors"""
print(f"\n🔄 {description}...")
try:
result = subprocess.run(command, shell=True, capture_output=True, text=True, cwd=os.getcwd())
if result.returncode == 0:
print(f"✅ {description} completed successfully")
if result.stdout.strip():
print(f"Output: {result.stdout.strip()}")
return True
else:
print(f"❌ {description} failed")
print(f"Error: {result.stderr.strip()}")
return False
except Exception as e:
print(f"❌ Error running command: {e}")
return False
def check_git_status():
"""Check if git is initialized and configured"""
print("\n📋 Checking Git status...")
# Check if git is initialized
if not os.path.exists('.git'):
print("⚠️ Git repository not initialized")
return False
# Check git config
try:
result = subprocess.run(['git', 'config', 'user.name'], capture_output=True, text=True)
if result.returncode != 0:
print("⚠️ Git user.name not configured")
return False
result = subprocess.run(['git', 'config', 'user.email'], capture_output=True, text=True)
if result.returncode != 0:
print("⚠️ Git user.email not configured")
return False
print("✅ Git is properly configured")
return True
except:
print("❌ Git not found or not configured")
return False
def initialize_git():
"""Initialize git repository if not already done"""
if not check_git_status():
print("\n🚀 Initializing Git repository...")
# Initialize git
if not run_command("git init", "Initializing git repository"):
return False
# Create .gitignore if it doesn't exist
gitignore_content = """
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
# Environment
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# IDE
.vscode/
.idea/
*.swp
*.swo
*~
# OS
.DS_Store
Thumbs.db
# Project specific
market_data.db
*.log
test_results/
"""
if not os.path.exists('.gitignore'):
with open('.gitignore', 'w') as f:
f.write(gitignore_content.strip())
print("✅ Created .gitignore file")
return True
return True
def prepare_for_deployment():
"""Prepare the project for deployment"""
print("🚀 Advanced Option Pricing Platform - Deployment Helper")
print("=" * 60)
# Check current directory
current_dir = Path.cwd()
print(f"📁 Current directory: {current_dir}")
# Check if we're in the right directory
if not os.path.exists('requirements.txt') or not os.path.exists('vercel.json'):
print("❌ This doesn't appear to be the Option Pricing Platform directory")
print("Please run this script from the project root directory")
return False
# Initialize git if needed
if not initialize_git():
return False
# Stage all files
if not run_command("git add .", "Staging all files"):
return False
# Create initial commit if no commits exist
result = subprocess.run(['git', 'log', '--oneline'], capture_output=True, text=True)
if result.returncode != 0: # No commits exist
if not run_command('git commit -m "Initial commit: Advanced Option Pricing Platform v2.0"',
"Creating initial commit"):
return False
else:
print("✅ Git repository already has commits")
# Display next steps
print("\n🎉 Repository prepared successfully!")
print("\n📋 Next Steps for Deployment:")
print("\n1. Create a new repository on GitHub/GitLab")
print("2. Add remote origin:")
print(" git remote add origin <your-repository-url>")
print("\n3. Push to remote:")
print(" git branch -M main")
print(" git push -u origin main")
print("\n4. Deploy to Vercel:")
print(" - Install Vercel CLI: npm i -g vercel")
print(" - Login: vercel login")
print(" - Deploy: vercel")
print("\n5. Or deploy via Vercel Dashboard:")
print(" - Connect your GitHub/GitLab repository")
print(" - Vercel will auto-detect Python and deploy")
print(f"\n🔗 Your app will be available at: https://<your-app-name>.vercel.app")
return True
def test_deployment_readiness():
"""Test if the application is ready for deployment"""
print("\n🧪 Testing deployment readiness...")
# Test Python imports
try:
sys.path.append('api')
from option_pricing import AdvancedOptionPricer
pricer = AdvancedOptionPricer()
result = pricer.black_scholes(100, 100, 0.25, 0.05, 0.2, 'call')
print(f"✅ Core option pricing working: {result:.4f}")
except Exception as e:
print(f"❌ Core option pricing failed: {e}")
return False
# Test Flask app import
try:
from app import app
print("✅ Flask app imports successfully")
except Exception as e:
print(f"❌ Flask app import failed: {e}")
return False
print("✅ Application is ready for deployment!")
return True
if __name__ == "__main__":
success = prepare_for_deployment()
if success:
# Test deployment readiness
test_deployment_readiness()
print("\n🎊 All checks passed! Ready to deploy to Vercel.")
print("\nSee DEPLOYMENT_GUIDE.md for detailed instructions.")
else:
print("\n❌ Deployment preparation failed. Please check the errors above.")
sys.exit(1)