-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdeploy.py
More file actions
57 lines (45 loc) · 1.23 KB
/
deploy.py
File metadata and controls
57 lines (45 loc) · 1.23 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
import os
import sys
import shutil
import subprocess
from pathlib import Path
ROOT = Path(__file__).parent
DIST = ROOT / "dist"
def run(cmd):
print("\n>>", cmd)
result = subprocess.run(cmd, shell=True)
if result.returncode != 0:
print("❌ Command failed")
sys.exit(result.returncode)
def clean():
print("🧹 Cleaning old builds...")
shutil.rmtree(ROOT / "build", ignore_errors=True)
shutil.rmtree(ROOT / "dist", ignore_errors=True)
for p in ROOT.glob("*.egg-info"):
shutil.rmtree(p, ignore_errors=True)
def build():
print("📦 Building package...")
run("python -m build")
def upload_test():
print("🚀 Uploading to TestPyPI...")
run("twine upload -r testpypi dist/*")
def upload_prod():
print("🚀 Uploading to PyPI...")
run("twine upload dist/*")
def main():
if len(sys.argv) < 2:
print("Usage: python deploy.py [test | prod]")
sys.exit(1)
target = sys.argv[1].lower()
clean()
build()
if target == "test":
upload_test()
elif target == "prod":
upload_prod()
else:
print("Invalid target. Use 'test' or 'prod'")
sys.exit(1)
print("\n✅ Deploy complete!")
if __name__ == "__main__":
main()