python/scripts/publish.sh
#!/bin/bash
# Script to publish the Claude Code SDK Python package to PyPI

set -e  # Exit on error

# Configuration
PACKAGE_NAME="claude-code-sdk"
PACKAGE_DIR="claude_code_sdk"

# Check for virtual environment
if [[ -z "${VIRTUAL_ENV}" ]]; then
    echo "WARNING: It's recommended to run this script in a virtual environment."
    read -p "Continue anyway? (y/n) " -n 1 -r
    echo
    if [[ ! $REPLY =~ ^[Yy]$ ]]; then
        exit 1
    fi
fi

# Install required tools
echo "Installing required tools..."
python -m pip install --upgrade pip
python -m pip install --upgrade build twine

# Clean previous builds
echo "Cleaning previous builds..."
rm -rf dist/ build/ *.egg-info/

# Run tests
echo "Running tests..."
pytest

# Build the package
echo "Building package..."
python -m build

# Show package info
echo "Package details:"
twine check dist/*

# Confirm upload
echo
echo "Are you sure you want to upload ${PACKAGE_NAME} to PyPI?"
echo "Version in setup.py: $(grep -o "version=\"[^\"]*\"" setup.py | cut -d'"' -f2)"
read -p "Upload to PyPI? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
    echo "Upload canceled."
    exit 1
fi

# Upload to PyPI
echo "Uploading to PyPI..."
python -m twine upload dist/*

echo "Done! ${PACKAGE_NAME} has been published to PyPI."
echo "Don't forget to create a Git tag and GitHub release!"