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.")