|
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") |
|
|
|
|
|
print("β
Installing required dependencies (setuptools, wheel, twine)...") |
|
run_command(f"{sys.executable} -m pip install --upgrade setuptools wheel twine") |
|
|
|
|
|
print("ποΈ Removing old `dist/`, `build/`, and `*.egg-info` files...") |
|
run_command("rm -rf dist build *.egg-info") |
|
|
|
|
|
print("π¦ Building the package...") |
|
run_command(f"{sys.executable} setup.py sdist bdist_wheel") |
|
|
|
|
|
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.") |
|
|