Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

macOS: stop the Xcode CLT dialog during venv creation (#8380)

BardiaKoopah9856d99bceda
diff --git a/install.sh b/install.sh
index 66eebb66e8e..a966c2d5308 100755
--- a/install.sh
+++ b/install.sh
@@ -2507,17 +2507,32 @@ if [ "$SKIP_TORCH" = true ] && [ "$MAC_INTEL" = true ] && [ -z "$_USER_PYTHON" ]
fi
fi
+# Apple Silicon venv. The arch-explicit arm64 CPython stops uv reusing a cached
+# x86_64 (Rosetta) build: torch ships no macOS x86_64 wheels since 2.2.2, so an
+# x86_64 venv cannot resolve torch. The arm64 guard below backstops older venvs.
+#
+# only-managed stops uv walking PATH and *executing* every interpreter it finds to
+# read its version. Without CLT, /usr/bin/python3 is Apple's xcode_select shim, so
+# that probe pops the "command line developer tools" dialog for tools this install
+# never needs. Spelled --python-preference, not the --managed-python alias: same
+# effect, accepted since uv 0.4.30 rather than 0.8.16.
+#
+# It also drops uv's system-interpreter fallback, so a host that is offline or has
+# UV_PYTHON_DOWNLOADS=never is left with nothing to resolve. Retry unflagged for
+# them: the dialog is worth removing, a failed install is not.
+_uv_venv_arm64() { # label
+ run_install_cmd "$1" uv venv "$VENV_DIR" \
+ --python-preference only-managed \
+ --python "cpython-${PYTHON_VERSION}-macos-aarch64-none" \
+ || run_install_cmd "$1 (system Python)" uv venv "$VENV_DIR" \
+ --python "cpython-${PYTHON_VERSION}-macos-aarch64-none"
+}
+
if [ ! -x "$VENV_DIR/bin/python" ]; then
step "venv" "creating Python ${PYTHON_VERSION} virtual environment"
substep "$VENV_DIR"
if [ "$OS" = "macos" ] && [ "$_ARCH" = "arm64" ] && [ -z "$_USER_PYTHON" ]; then
- # Apple Silicon: request an arch-explicit arm64 CPython so uv cannot
- # reuse a cached x86_64 (Rosetta) build. torch ships no macOS x86_64
- # wheels since 2.2.2, so an x86_64 venv makes the torch install
- # unresolvable. The arm64 guard below is kept as a backstop for
- # migrated / pre-existing venvs.
- run_install_cmd "create venv" uv venv "$VENV_DIR" \
- --python "cpython-${PYTHON_VERSION}-macos-aarch64-none"
+ _uv_venv_arm64 "create venv"
else
run_install_cmd "create venv" uv venv "$VENV_DIR" \
--python "$(_python_request "$PYTHON_VERSION")"
@@ -2573,8 +2588,7 @@ if [ -z "$_USER_PYTHON" ] && [ "$OS" = "macos" ] && [ "$_ARCH" = "arm64" ]; then
echo " WARNING: venv was created with an x86_64 (Rosetta) Python on Apple Silicon."
echo " Recreating venv with native arm64 Python ${PYTHON_VERSION}..."
_discard_venv_for_recreate "$VENV_DIR"
- run_install_cmd "recreate venv (arm64)" uv venv "$VENV_DIR" \
- --python "cpython-${PYTHON_VERSION}-macos-aarch64-none"
+ _uv_venv_arm64 "recreate venv (arm64)"
if [ -x "$VENV_DIR/bin/python" ]; then
: > "$VENV_DIR/.unsloth-studio-owned" 2>/dev/null || true
fi
@@ -2589,8 +2603,7 @@ if [ -z "$_USER_PYTHON" ] && [ "$OS" = "macos" ] && [ "$_ARCH" = "arm64" ]; then
echo " Recreating venv with Python 3.12..."
_discard_venv_for_recreate "$VENV_DIR"
PYTHON_VERSION="3.12"
- run_install_cmd "recreate venv" uv venv "$VENV_DIR" \
- --python "cpython-${PYTHON_VERSION}-macos-aarch64-none"
+ _uv_venv_arm64 "recreate venv"
if [ -x "$VENV_DIR/bin/python" ]; then
: > "$VENV_DIR/.unsloth-studio-owned" 2>/dev/null || true
fi
diff --git a/tests/sh/test_mac_intel_compat.sh b/tests/sh/test_mac_intel_compat.sh
index 3510176a97e..809998f02d4 100644
--- a/tests/sh/test_mac_intel_compat.sh
+++ b/tests/sh/test_mac_intel_compat.sh
@@ -571,9 +571,9 @@ echo "=== Apple Silicon x86_64 (Rosetta) venv rebuild ==="
# Extract the real guard block from install.sh so we exercise the shipped logic
# (comment header down to its column-0 closing fi).
_GUARD_FILE=$(mktemp)
-# The guard calls _python_is_skipped and _discard_venv_for_recreate, so the skip
-# list, its reader, and the replacement helpers have to come along or the version
-# check silently never fires and the recreate loses the venv it was handed.
+# The guard calls _python_is_skipped, _discard_venv_for_recreate and _uv_venv_arm64,
+# so the skip list, its reader, and the replacement helpers have to come along or the
+# version check silently never fires and the recreate loses the venv it was handed.
{
printf 'substep() { :; }\n'
sed -n '/^PYTHON_SKIP=/p' "$INSTALL_SH"
@@ -581,10 +581,11 @@ _GUARD_FILE=$(mktemp)
sed -n '/^_python_is_skipped()/,/^}/p' "$INSTALL_SH"
sed -n '/^_start_studio_venv_replacement()/,/^}/p' "$INSTALL_SH"
sed -n '/^_discard_venv_for_recreate()/,/^}/p' "$INSTALL_SH"
+ sed -n '/^_uv_venv_arm64()/,/^}/p' "$INSTALL_SH"
awk '/Guard against two independent Apple Silicon venv problems/{f=1} f{print} f&&/^fi$/{exit}' \
"$INSTALL_SH"
} > "$_GUARD_FILE"
-for _needed in _python_skip_applies _python_is_skipped _start_studio_venv_replacement _discard_venv_for_recreate; do
+for _needed in _python_skip_applies _python_is_skipped _start_studio_venv_replacement _discard_venv_for_recreate _uv_venv_arm64; do
grep -q "^$_needed()" "$_GUARD_FILE" || {
echo " FAIL: could not extract $_needed from install.sh"
FAIL=$((FAIL + 1))
diff --git a/tests/sh/test_macos_venv_python_preference.sh b/tests/sh/test_macos_venv_python_preference.sh
new file mode 100755
index 00000000000..d9adfe7741c
--- /dev/null
+++ b/tests/sh/test_macos_venv_python_preference.sh
@@ -0,0 +1,151 @@
+#!/bin/bash
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+# _uv_venv_arm64: managed-only, so uv never executes the PATH pythons (the Xcode CLT
+# dialog on a Mac without the tools), with an unflagged retry so a host that cannot
+# resolve a managed build keeps its system Python.
+set -e
+
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+INSTALL_SH="$SCRIPT_DIR/../../install.sh"
+PASS=0
+FAIL=0
+
+assert_eq() {
+ _label="$1"; _expected="$2"; _actual="$3"
+ if [ "$_actual" = "$_expected" ]; then
+ echo " PASS: $_label"
+ PASS=$((PASS + 1))
+ else
+ echo " FAIL: $_label (expected '$_expected', got '$_actual')"
+ FAIL=$((FAIL + 1))
+ fi
+}
+
+assert_contains() {
+ _label="$1"; _haystack="$2"; _needle="$3"
+ if echo "$_haystack" | grep -qF "$_needle"; then
+ echo " PASS: $_label"
+ PASS=$((PASS + 1))
+ else
+ echo " FAIL: $_label (expected to find '$_needle')"
+ FAIL=$((FAIL + 1))
+ fi
+}
+
+_FN=$(mktemp)
+sed -n '/^_uv_venv_arm64()/,/^}/p' "$INSTALL_SH" > "$_FN"
+[ -s "$_FN" ] || { echo " FAIL: _uv_venv_arm64 not found in install.sh"; exit 1; }
+
+# $1 = shell, $2 = exit code for the only-managed attempt. The stub echoes which
+# form it got, so ordering and fallback both show up in one trace.
+_run() {
+ "$1" -c '
+ . "'"$_FN"'"
+ VENV_DIR=/tmp/venv; PYTHON_VERSION=3.12
+ run_install_cmd() {
+ shift
+ case " $* " in
+ *" only-managed "*) echo "managed"; return '"$2"' ;;
+ esac
+ echo "unflagged"; return 0
+ }
+ _uv_venv_arm64 "create venv" && echo "rc=0" || echo "rc=$?"
+ ' 2>&1 | tr '\n' ' '
+}
+
+for _sh in sh bash; do
+ echo "=== _uv_venv_arm64 under $_sh ==="
+
+ _out=$(_run "$_sh" 0)
+ assert_eq "managed request succeeds, no fallback" "managed rc=0 " "$_out"
+
+ _out=$(_run "$_sh" 2)
+ assert_eq "managed request fails, falls back unflagged" "managed unflagged rc=0 " "$_out"
+
+ # Both failing must stay non-zero: the caller is under set -e and the
+ # rollback trap depends on it.
+ _out=$("$_sh" -c '
+ . "'"$_FN"'"
+ VENV_DIR=/tmp/venv; PYTHON_VERSION=3.12
+ run_install_cmd() { return 2; }
+ _uv_venv_arm64 "create venv" && echo "rc=0" || echo "rc=$?"
+ ' 2>&1)
+ assert_eq "both attempts fail, non-zero propagates" "rc=2" "$_out"
+done
+
+echo "=== install.sh call sites ==="
+
+# The last call site re-assigns PYTHON_VERSION to 3.12 first, so the helper has to
+# read it at call time.
+assert_contains "helper expands PYTHON_VERSION at call time" \
+ "$(cat "$_FN")" 'cpython-${PYTHON_VERSION}-macos-aarch64-none'
+
+_direct=$(grep -c 'uv venv .*cpython-\${PYTHON_VERSION}-macos-aarch64-none' "$INSTALL_SH" || true)
+assert_eq "arm64 sites go through the helper only" "0" "$_direct"
+
+_calls=$(grep -c '^ *_uv_venv_arm64 ' "$INSTALL_SH" || true)
+assert_eq "all three arm64 venv sites routed" "3" "$_calls"
+
+# _python_request carries a user --python or an interpreter path, which only-managed
+# would ignore.
+_out=$(grep -A 1 '_python_request "\$PYTHON_VERSION"' "$INSTALL_SH" || true)
+if echo "$_out" | grep -q 'only-managed'; then
+ echo " FAIL: only-managed leaked onto a _python_request call site"
+ FAIL=$((FAIL + 1))
+else
+ echo " PASS: _python_request call sites left unflagged"
+ PASS=$((PASS + 1))
+fi
+
+echo "=== Studio installer stream ==="
+
+# install.rs turns [TAURI:ERROR_OUTPUT] into "Installation failed" until a later
+# [TAURI:ERROR_CLEAR]. A recovered fallback must emit one or Studio reports a
+# failure it already recovered from.
+_STREAM=$(mktemp)
+{
+ printf 'C_ERR=""; TAURI_MODE=true; UNSLOTH_VERBOSE=false\n'
+ printf 'step() { :; }\ntauri_log() { :; }\n'
+ for _f in _is_verbose tauri_stream_log tauri_clear_install_error _redact_install_output \
+ run_install_cmd _uv_venv_arm64; do
+ sed -n "/^$_f()/,/^}/p" "$INSTALL_SH"
+ done
+} > "$_STREAM"
+
+_UVDIR=$(mktemp -d)
+cat > "$_UVDIR/uv" << 'UV_EOF'
+#!/bin/sh
+case " $* " in *" only-managed "*) [ "$UV_FAIL_MANAGED" = 1 ] && exit 2 ;; esac
+mkdir -p "$2/bin" && printf '#!/bin/sh\n' > "$2/bin/python" && chmod +x "$2/bin/python"
+UV_EOF
+chmod +x "$_UVDIR/uv"
+
+_emit() { # UV_FAIL_MANAGED
+ _sd=$(mktemp -d)
+ PATH="$_UVDIR:$PATH" VENV_DIR="$_sd/venv" PYTHON_VERSION=3.12 UV_FAIL_MANAGED="$1" \
+ sh -c ". '$_STREAM'; _uv_venv_arm64 'create venv'; echo RC=\$?" 2>&1
+ rm -rf "$_sd"
+}
+
+_out=$(_emit 0)
+assert_contains "managed attempt succeeds, returns 0" "$_out" "RC=0"
+if echo "$_out" | grep -q ERROR_OUTPUT; then
+ echo " FAIL: clean run must not report a failure"
+ FAIL=$((FAIL + 1))
+else
+ echo " PASS: clean run reports no failure"
+ PASS=$((PASS + 1))
+fi
+
+_out=$(_emit 1)
+assert_contains "fallback run still returns 0" "$_out" "RC=0"
+assert_contains "recovery clears the Studio failure" "$_out" "ERROR_CLEAR"
+assert_eq "ERROR_CLEAR is the last error-state line" "ERROR_CLEAR" \
+ "$(echo "$_out" | grep -o 'ERROR_OUTPUT\|ERROR_CLEAR' | tail -1)"
+
+rm -rf "$_UVDIR"
+rm -f "$_FN" "$_STREAM"
+echo ""
+echo "Passed: $PASS, Failed: $FAIL"
+[ "$FAIL" -eq 0 ]