-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_and_deploy.py
More file actions
executable file
·86 lines (70 loc) · 2.5 KB
/
Copy pathbuild_and_deploy.py
File metadata and controls
executable file
·86 lines (70 loc) · 2.5 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
#!/usr/bin/env python3
import re
import subprocess
import sys
from pathlib import Path
def read_current_version():
"""Read the current version from setup.py"""
setup_path = Path("setup.py")
if not setup_path.exists():
print("Error: setup.py file not found")
sys.exit(1)
content = setup_path.read_text()
version_match = re.search(r'version="([^"]+)"', content)
if not version_match:
print("Error: Could not find version in setup.py")
sys.exit(1)
return version_match.group(1)
def update_version(new_version):
"""Update the version in setup.py"""
setup_path = Path("setup.py")
content = setup_path.read_text()
updated_content = re.sub(
r'version="[^"]+"',
f'version="{new_version}"',
content
)
setup_path.write_text(updated_content)
print(f"Updated version to {new_version} in setup.py")
def build_and_deploy():
"""Build and deploy the package"""
print("\nBuilding the package...")
subprocess.run(["python", "setup.py", "sdist", "bdist_wheel"], check=True)
print("\nUploading to PyPI...")
subprocess.run(["twine", "upload", "dist/*"], check=True)
print("\n✅ Package successfully built and deployed!")
def main():
current_version = read_current_version()
print(f"Current version: {current_version}")
# Ask for new version
new_version = input(f"Enter new version (leave empty to keep {current_version}): ").strip()
if not new_version:
new_version = current_version
# Validate semantic version format
if not re.match(r'^\d+\.\d+\.\d+$', new_version):
print("Warning: Version doesn't match semantic versioning (X.Y.Z)")
proceed = input("Continue anyway? (y/n): ").lower()
if proceed != 'y':
print("Aborting.")
return
# Confirmation
print("\nReady to build with the following details:")
print(f"- Version: {new_version}")
confirmation = input("\nProceed with build and deploy? (y/n): ").lower()
if confirmation != 'y':
print("Build and deploy canceled.")
return
# Update version in setup.py
if new_version != current_version:
update_version(new_version)
# Build and deploy
build_and_deploy()
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\nOperation canceled by user.")
sys.exit(1)
except Exception as e:
print(f"\nError: {e}")
sys.exit(1)