# build_wheel.ps1 # Build wheel distribution for Agravity Client (PowerShell) # # Usage: # .\build_wheel.ps1 # # Requires: # - Python 3.9+ # - setuptools>=65.0 # - wheel # - build (recommended) param( [switch]$Clean = $false, [switch]$Upload = $false ) # Define symbols as variables to avoid encoding issues $symSuccess = "[OK]" $symError = "[!]" $symBullet = "[*]" # Color functions for output function Write-Success { Write-Host "$symSuccess $args" -ForegroundColor Green } function Write-Error-Custom { Write-Host "$symError $args" -ForegroundColor Red } function Write-Header { Write-Host ("=" * 70) Write-Host $args Write-Host ("=" * 70) } function Write-SubHeader { Write-Host ("-" * 70) Write-Host $args Write-Host ("-" * 70) } # Main script $projectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path $distDir = Join-Path $projectRoot "dist" $buildDir = Join-Path $projectRoot "build" $eggInfoDir = Join-Path $projectRoot "agravity_client.egg-info" Write-Header "Agravity Client - Wheel Builder (PowerShell)" # Clean if requested if ($Clean) { Write-Host "" Write-Host "Cleaning previous builds..." @($distDir, $buildDir, $eggInfoDir) | ForEach-Object { if (Test-Path $_) { Remove-Item $_ -Recurse -Force -ErrorAction SilentlyContinue Write-Success "Removed $_" } } } # Check if build directory exists from previous build if (Test-Path $distDir) { Write-Host "" Write-Host "Cleaning dist directory..." Remove-Item $distDir -Recurse -Force -ErrorAction SilentlyContinue Write-Success "Removed old distributions" } # Install build requirements if needed Write-Host "" Write-Host "Checking build dependencies..." $buildCheck = python -m pip list 2>$null | Select-String "build" if (-not $buildCheck) { Write-Host "Installing build tools..." python -m pip install -q build setuptools wheel if ($LASTEXITCODE -eq 0) { Write-Success "Build tools installed" } else { Write-Error-Custom "Failed to install build tools" exit 1 } } # Build Write-SubHeader "Building distributions..." Write-Host "" Push-Location $projectRoot try { python -m build if ($LASTEXITCODE -ne 0) { Write-Error-Custom "Build failed" exit 1 } } finally { Pop-Location } # Verify output Write-SubHeader "Build Results" Write-Host "" if (!(Test-Path $distDir)) { Write-Error-Custom "dist directory not created" exit 1 } $wheels = @(Get-ChildItem -Path $distDir -Filter "*.whl" -ErrorAction SilentlyContinue) $sdists = @(Get-ChildItem -Path $distDir -Filter "*.tar.gz" -ErrorAction SilentlyContinue) if ($wheels.Count -eq 0 -and $sdists.Count -eq 0) { Write-Error-Custom "No distributions created" exit 1 } Write-Success "Build successful!" Write-Host "" if ($wheels.Count -gt 0) { Write-Host "Wheels:" $wheels | ForEach-Object { $sizeMB = [Math]::Round($_.Length / 1MB, 2) Write-Host " $symBullet $($_.Name) ($sizeMB MB)" } } if ($sdists.Count -gt 0) { Write-Host "" Write-Host "Source Distributions:" $sdists | ForEach-Object { $sizeMB = [Math]::Round($_.Length / 1MB, 2) Write-Host " $symBullet $($_.Name) ($sizeMB MB)" } } Write-Host "" Write-Success "Distributions saved to: $distDir" # Installation instructions Write-SubHeader "Installation Instructions" Write-Host "" if ($wheels.Count -gt 0) { $wheel = $wheels[0] Write-Host "Install the wheel locally:" Write-Host " pip install `"$($wheel.FullName)`"" Write-Host "" Write-Host "Or upload to PyPI:" Write-Host " pip install twine" Write-Host " twine upload dist/*" Write-Host "" } # Optional upload if ($Upload) { Write-SubHeader "Uploading to PyPI..." Write-Host "" $twineCheck = python -m pip list 2>$null | Select-String "twine" if (-not $twineCheck) { Write-Host "Installing twine..." python -m pip install -q twine } Write-Host "Running twine upload..." Push-Location $projectRoot try { python -m twine upload dist/* if ($LASTEXITCODE -eq 0) { Write-Success "Upload complete!" } else { Write-Error-Custom "Upload failed" exit 1 } } finally { Pop-Location } } Write-Host "" Write-Host "Done!" Write-Host "" exit 0