#!/bin/bash # build_wheel.sh - Build wheel distribution for Agravity Client # # Usage: # ./build_wheel.sh [--clean] [--upload] # # Options: # --clean Clean previous builds before building # --upload Upload to PyPI after building # # Requires: # - Python 3.9+ # - setuptools>=65.0 # - wheel # - build (recommended) set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Functions print_success() { echo -e "${GREEN}✓ $1${NC}" } print_error() { echo -e "${RED}✗ $1${NC}" } print_header() { echo "========================================================================" echo "$1" echo "========================================================================" } print_subheader() { echo "------------------------------------------------------------------------" echo "$1" echo "------------------------------------------------------------------------" } # Parse arguments CLEAN=false UPLOAD=false while [[ $# -gt 0 ]]; do case $1 in --clean) CLEAN=true shift ;; --upload) UPLOAD=true shift ;; *) echo "Unknown option: $1" echo "Usage: $0 [--clean] [--upload]" exit 1 ;; esac done # Get project root PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" DIST_DIR="$PROJECT_ROOT/dist" BUILD_DIR="$PROJECT_ROOT/build" EGG_INFO_DIR="$PROJECT_ROOT/agravity_client.egg-info" print_header "Agravity Client - Wheel Builder" # Clean if requested if [ "$CLEAN" = true ]; then echo "" echo "Cleaning previous builds..." for dir in "$DIST_DIR" "$BUILD_DIR" "$EGG_INFO_DIR"; do if [ -d "$dir" ]; then rm -rf "$dir" print_success "Removed $dir" fi done fi # Clean dist directory for fresh build if [ -d "$DIST_DIR" ]; then rm -rf "$DIST_DIR" print_success "Removed old distributions" fi # Check build dependencies echo "" echo "Checking build dependencies..." if ! python3 -m pip list 2>/dev/null | grep -q "^build "; then echo "Installing build tools..." python3 -m pip install -q build setuptools wheel if [ $? -eq 0 ]; then print_success "Build tools installed" else print_error "Failed to install build tools" exit 1 fi fi # Build print_subheader "Building distributions..." echo "" cd "$PROJECT_ROOT" if ! python3 -m build; then print_error "Build failed" exit 1 fi # Verify output print_subheader "Build Results" echo "" if [ ! -d "$DIST_DIR" ]; then print_error "dist directory not created" exit 1 fi # Count wheels and sdists WHEEL_COUNT=$(find "$DIST_DIR" -maxdepth 1 -name "*.whl" 2>/dev/null | wc -l) SDIST_COUNT=$(find "$DIST_DIR" -maxdepth 1 -name "*.tar.gz" 2>/dev/null | wc -l) if [ $WHEEL_COUNT -eq 0 ] && [ $SDIST_COUNT -eq 0 ]; then print_error "No distributions created" exit 1 fi print_success "Build successful!" echo "" if [ $WHEEL_COUNT -gt 0 ]; then echo "Wheels:" for wheel in "$DIST_DIR"/*.whl; do SIZE=$(du -h "$wheel" | cut -f1) echo " • $(basename "$wheel") ($SIZE)" done fi if [ $SDIST_COUNT -gt 0 ]; then echo "" echo "Source Distributions:" for sdist in "$DIST_DIR"/*.tar.gz; do SIZE=$(du -h "$sdist" | cut -f1) echo " • $(basename "$sdist") ($SIZE)" done fi echo "" print_success "Distributions saved to: $DIST_DIR" # Installation instructions print_subheader "Installation Instructions" echo "" if [ $WHEEL_COUNT -gt 0 ]; then WHEEL=$(ls "$DIST_DIR"/*.whl | head -1) echo "Install the wheel locally:" echo " pip install \"$WHEEL\"" echo "" echo "Or upload to PyPI:" echo " pip install twine" echo " twine upload dist/*" echo "" fi # Optional upload if [ "$UPLOAD" = true ]; then print_subheader "Uploading to PyPI..." echo "" if ! python3 -m pip list 2>/dev/null | grep -q "^twine "; then echo "Installing twine..." python3 -m pip install -q twine fi echo "Running twine upload..." cd "$PROJECT_ROOT" if python3 -m twine upload dist/*; then print_success "Upload complete!" else print_error "Upload failed" exit 1 fi fi echo "" echo "Done!" echo "" exit 0