-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupload.py
More file actions
58 lines (45 loc) · 1.38 KB
/
upload.py
File metadata and controls
58 lines (45 loc) · 1.38 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
"""Upload unisonai-sdk to PyPI."""
import subprocess
import sys
import shutil
import os
def clean():
"""Remove previous build artifacts."""
for folder in ("build", "dist", "unisonai_sdk.egg-info"):
if os.path.exists(folder):
shutil.rmtree(folder)
print(f" Removed {folder}/")
def build():
"""Build source and wheel distributions."""
print("\n[1/3] Building package...")
subprocess.check_call([sys.executable, "setup.py", "sdist", "bdist_wheel"])
print(" Build complete.")
def upload(token: str):
"""Upload distributions to PyPI using twine."""
print("\n[2/3] Uploading to PyPI...")
subprocess.check_call([
sys.executable, "-m", "twine", "upload",
"dist/*",
"-u", "__token__",
"-p", token,
])
print(" Upload complete.")
def main():
token = input("Enter your PyPI API token: ").strip()
if not token:
print("Error: token cannot be empty.")
sys.exit(1)
# Ensure build tools are installed
print("[0/3] Checking dependencies...")
subprocess.check_call(
[sys.executable, "-m", "pip", "install", "--upgrade", "setuptools", "wheel", "twine"],
stdout=subprocess.DEVNULL,
)
clean()
build()
upload(token)
print("\n[3/3] Cleaning up...")
clean()
print("\nDone! Package uploaded to PyPI.")
if __name__ == "__main__":
main()