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