#!/usr/bin/env bash
set -e

if [[ -n "$PYTHON_INSTALL" ]]; then

    log-entrypoint 'Check status of PyPi.'
    http_pypi_ok=$(curl -s --head --request GET https://pypi.org/simple/ | grep 'HTTP/2 200')

    if [[ -n "$http_pypi_ok" ]]; then
        # Handle both newline and comma-separated formats
        if [[ "$PYTHON_INSTALL" == *","* ]]; then
            # Comma-separated format
            uv pip install $(echo "$PYTHON_INSTALL" | tr ',' ' ')
        else
            # Newline-separated or space-separated format
            uv pip install $PYTHON_INSTALL
        fi
    fi
fi
