File size: 1,606 Bytes
4c6a68b |
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 |
import os
import subprocess
import sys
def run_command(command):
"""Run a shell command and check for errors."""
result = subprocess.run(command, shell=True, check=True, text=True)
return result
def main():
print("π Starting the PIP package build & upload process...\n")
# Step 1: Ensure dependencies are installed
print("β
Installing required dependencies (setuptools, wheel, twine)...")
run_command(f"{sys.executable} -m pip install --upgrade setuptools wheel twine")
# Step 2: Remove old build directories if they exist
print("ποΈ Removing old `dist/`, `build/`, and `*.egg-info` files...")
run_command("rm -rf dist build *.egg-info")
# Step 3: Build the package
print("π¦ Building the package...")
run_command(f"{sys.executable} setup.py sdist bdist_wheel")
# Step 4: Upload the package to PyPI (or TestPyPI)
upload_option = input("Upload to (1) PyPI or (2) TestPyPI? [1/2]: ").strip()
if upload_option == "2":
print("π Uploading package to TestPyPI...")
run_command("twine upload --repository testpypi dist/*")
print("β
Package uploaded to TestPyPI!")
else:
print("π Uploading package to PyPI...")
run_command("twine upload dist/*")
print("β
Package uploaded to PyPI!")
print("\nπ Done! Your package is now available online.")
if __name__ == "__main__":
try:
main()
except subprocess.CalledProcessError as e:
print(f"\nβ Error: {e}")
print("β οΈ Make sure you are logged in with `twine` before uploading.")
|