-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdeploy.py
More file actions
152 lines (126 loc) · 4.64 KB
/
deploy.py
File metadata and controls
152 lines (126 loc) · 4.64 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
#!/usr/bin/env python3
"""
PyPI Deployment Script for BinomoAPI
This script helps with building and uploading the package to PyPI.
Run with: python deploy.py [test|prod]
"""
import subprocess
import sys
import os
import shutil
from pathlib import Path
def clean_build():
"""Clean previous build artifacts"""
print("🧹 Cleaning previous build artifacts...")
dirs_to_clean = ['build', 'dist', 'BinomoAPI.egg-info']
for dir_name in dirs_to_clean:
if os.path.exists(dir_name):
shutil.rmtree(dir_name)
print(f" Removed {dir_name}/")
# Clean __pycache__ directories
for root, dirs, files in os.walk('.'):
for dir_name in dirs:
if dir_name == '__pycache__':
pycache_path = os.path.join(root, dir_name)
shutil.rmtree(pycache_path)
print(f" Removed {pycache_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")
if result.stdout.strip():
print(f" Output: {result.stdout.strip()}")
return True
except subprocess.CalledProcessError as e:
print(f" ❌ {description} failed")
print(f" Error: {e.stderr}")
return False
def check_prerequisites():
"""Check if required tools are installed"""
print("🔍 Checking prerequisites...")
tools = ['build', 'twine']
missing_tools = []
for tool in tools:
try:
subprocess.run([tool, '--version'], capture_output=True, check=True)
print(f" ✅ {tool} is installed")
except (subprocess.CalledProcessError, FileNotFoundError):
missing_tools.append(tool)
print(f" ❌ {tool} is not installed")
if missing_tools:
print(f"\n📦 Installing missing tools: {', '.join(missing_tools)}")
for tool in missing_tools:
if not run_command(f"pip install {tool}", f"Installing {tool}"):
return False
return True
def build_package():
"""Build the package"""
return run_command("python -m build", "Building package")
def check_package():
"""Check the built package"""
return run_command("python -m twine check dist/*", "Checking package")
def upload_to_test_pypi():
"""Upload to Test PyPI"""
print("🚀 Uploading to Test PyPI...")
print(" Note: You'll need to enter your Test PyPI credentials")
return run_command(
"python -m twine upload --repository testpypi dist/*",
"Uploading to Test PyPI"
)
def upload_to_pypi():
"""Upload to production PyPI"""
print("🚀 Uploading to PyPI...")
print(" Note: You'll need to enter your PyPI credentials")
response = input(" Are you sure you want to upload to production PyPI? (yes/no): ")
if response.lower() != 'yes':
print(" Upload cancelled")
return False
return run_command(
"python -m twine upload dist/*",
"Uploading to PyPI"
)
def main():
"""Main deployment function"""
if len(sys.argv) != 2 or sys.argv[1] not in ['test', 'prod']:
print("Usage: python deploy.py [test|prod]")
print(" test: Upload to Test PyPI")
print(" prod: Upload to production PyPI")
sys.exit(1)
target = sys.argv[1]
print("🎯 BinomoAPI PyPI Deployment Script")
print(f" Target: {'Test PyPI' if target == 'test' else 'Production PyPI'}")
print()
# Check prerequisites
if not check_prerequisites():
print("❌ Prerequisites check failed")
sys.exit(1)
# Clean previous builds
clean_build()
# Build package
if not build_package():
print("❌ Package build failed")
sys.exit(1)
# Check package
if not check_package():
print("❌ Package check failed")
sys.exit(1)
# Upload package
if target == 'test':
success = upload_to_test_pypi()
if success:
print("\n🎉 Successfully uploaded to Test PyPI!")
print(" You can test install with:")
print(" pip install --index-url https://test.pypi.org/simple/ BinomoAPI")
else:
success = upload_to_pypi()
if success:
print("\n🎉 Successfully uploaded to PyPI!")
print(" Users can now install with:")
print(" pip install BinomoAPI")
if not success:
print("❌ Upload failed")
sys.exit(1)
if __name__ == "__main__":
main()