diff --git a/misc/tools.func b/misc/tools.func index cda282629..3033d6372 100644 --- a/misc/tools.func +++ b/misc/tools.func @@ -1081,12 +1081,35 @@ function setup_uv() { rm -rf "$TMP_DIR" ensure_usr_local_bin_persist msg_ok "uv $LATEST_VERSION installed" + + # Optional: install specific Python version + if [[ -n "${PYTHON_VERSION:-}" ]]; then + $STD msg_info "Ensuring Python $PYTHON_VERSION is available via uv..." + + local VERSION_MATCH + VERSION_MATCH=$(uv python list --only-downloads | + grep -E "^cpython-${PYTHON_VERSION//./\\.}\.[0-9]+-linux" | + cut -d'-' -f2 | sort -V | tail -n1) + + if [[ -z "$VERSION_MATCH" ]]; then + msg_error "No matching Python $PYTHON_VERSION.x version found via uv" + return 1 + fi + + if uv python list | grep -q "cpython-${VERSION_MATCH}-linux.*uv/python"; then + $STD msg_ok "Python $VERSION_MATCH already installed via uv" + else + if ! $STD uv python install "$VERSION_MATCH"; then + msg_error "Failed to install Python $VERSION_MATCH via uv" + return 1 + fi + msg_ok "Installed Python $VERSION_MATCH" + fi + fi } # ------------------------------------------------------------------------------ -# Fully autonomous uv-based venv installer with pip/requirements handling -# - Requires: VENV_FOLDER, PYTHON_VERSION -# - Optional: REQUIREMENTS_FILE (default: requirements.txt) +# Creates a uv-based venv with optional Python version and installs dependencies # ------------------------------------------------------------------------------ function setup_uv_venv() {