-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathbuild_and_publish.py
More file actions
141 lines (115 loc) · 4.58 KB
/
build_and_publish.py
File metadata and controls
141 lines (115 loc) · 4.58 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
#!/usr/bin/env python3
"""
Build and publish script for AxiomTradeAPI-py
This script helps build and publish the package to PyPI
"""
import os
import sys
import subprocess
import shutil
def run_command(command, description, capture=False):
"""Run a command and handle errors"""
print(f"\n🔧 {description}")
print(f"Running: {command}")
if capture:
result = subprocess.run(command, shell=True, capture_output=True, text=True)
if result.returncode == 0:
print(f"✅ {description} completed successfully")
if result.stdout:
print(result.stdout)
else:
print(f"❌ {description} failed")
print(f"Error: {result.stderr}")
return False
else:
# Don't capture output for interactive commands (like twine upload)
# or when we want to see output in real-time
result = subprocess.run(command, shell=True)
if result.returncode == 0:
print(f"✅ {description} completed successfully")
else:
print(f"❌ {description} failed")
return False
return True
def clean_build():
"""Clean previous build artifacts"""
print("\n🧹 Cleaning previous build artifacts...")
dirs_to_clean = ['build', 'dist', 'axiomtradeapi.egg-info']
for dir_name in dirs_to_clean:
if os.path.exists(dir_name):
shutil.rmtree(dir_name)
print(f" Removed {dir_name}/")
print("✅ Build artifacts cleaned")
def check_requirements():
"""Check if required tools are installed"""
print("\n🔍 Checking requirements...")
required_packages = ['build', 'twine']
missing_packages = []
for package in required_packages:
result = subprocess.run(f"pip show {package}", shell=True, capture_output=True)
if result.returncode != 0:
missing_packages.append(package)
if missing_packages:
print(f"❌ Missing required packages: {missing_packages}")
print("Installing missing packages...")
for package in missing_packages:
if not run_command(f"pip install {package}", f"Installing {package}"):
return False
print("✅ All requirements satisfied")
return True
def build_package():
"""Build the package"""
return run_command("python -m build", "Building package")
def check_package():
"""Check the package with twine"""
return run_command("python -m twine check dist/*", "Checking package")
def upload_test():
"""Upload to Test PyPI"""
print("\n🚀 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_production():
"""Upload to Production PyPI"""
print("\n🚀 Uploading to Production PyPI...")
print("Note: You'll need to enter your PyPI credentials")
return run_command("python -m twine upload dist/*", "Uploading to Production PyPI")
def main():
"""Main build and publish workflow"""
print("🎉 AxiomTradeAPI-py Build & Publish Script")
print("=" * 50)
# Check current directory
if not os.path.exists("setup.py"):
print("❌ setup.py not found. Please run this script from the project root.")
sys.exit(1)
# Step 1: Check requirements
if not check_requirements():
sys.exit(1)
# Step 2: Clean previous builds
clean_build()
# Step 3: Build package
if not build_package():
sys.exit(1)
# Step 4: Check package
if not check_package():
sys.exit(1)
print("\n" + "=" * 50)
print("🎉 Package built successfully!")
print("\nNext steps:")
print("1. Test upload: python build_and_publish.py --test")
print("2. Production upload: python build_and_publish.py --prod")
print("\nOr run individual commands:")
print(" Test PyPI: python -m twine upload --repository testpypi dist/*")
print(" Prod PyPI: python -m twine upload dist/*")
# Handle command line arguments
if len(sys.argv) > 1:
if "--test" in sys.argv:
upload_test()
elif "--prod" in sys.argv:
upload_production()
elif "--help" in sys.argv:
print("\nUsage:")
print(" python build_and_publish.py # Build only")
print(" python build_and_publish.py --test # Build and upload to Test PyPI")
print(" python build_and_publish.py --prod # Build and upload to Production PyPI")
if __name__ == "__main__":
main()