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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Installers: resolve studio from the venv, never from the caller's directory (#12682)
Daniel Han4a6ec2e7a5a5
diff --git a/.github/workflows/desktop-app-clean-machine-ci.yml b/.github/workflows/desktop-app-clean-machine-ci.ymlindex 521832878a1..a1bd8628655 100644--- a/.github/workflows/desktop-app-clean-machine-ci.yml+++ b/.github/workflows/desktop-app-clean-machine-ci.yml@@ -243,10 +243,15 @@ jobs:# installer. Invoke it as src-tauri/src/install.rs does: --tauri, stdin closed,# no tty. --tauri rejects a custom studio home (install.sh:102-114).SH="$APP/Contents/Resources/install.sh"+ # Run it from outside the checkout, as the app does: a user launches Unsloth from the+ # desktop, not from a clone of this repository. Released bundles up to v0.1.902 resolve+ # `studio` against the cwd when locating setup.sh (fixed with -I in install.sh), so a+ # run from the checkout installed THIS ref's requirement pins into a released wheel+ # and preflight read studio_deps_missing (#12656 moved pyjwt).rc=0- env -u UNSLOTH_STUDIO_HOME \+ (cd "$RUNNER_TEMP" && env -u UNSLOTH_STUDIO_HOME \bash "$SH" --tauri \- < /dev/null 2>&1 | tee logs/bundled-install.log || rc=$?+ < /dev/null 2>&1) | tee logs/bundled-install.log || rc=$?echo "bundled installer exit code: $rc"[ "$rc" -eq 0 ] || {echo "::error::bundled installer exited $rc"@@ -277,7 +282,8 @@ jobs:set -a; [ -f ./clean-machine.env ] && . ./clean-machine.env; set +aAPP="$(ls -d /Applications/*Unsloth*.app | head -1)"BIN="$APP/Contents/MacOS/$(/usr/libexec/PlistBuddy -c 'Print :CFBundleExecutable' "$APP/Contents/Info.plist")"- "$BIN" > logs/app-stdout.log 2>&1 &+ # From outside the checkout, like a desktop launch (see the install step).+ (cd "$RUNNER_TEMP" && exec "$BIN") > logs/app-stdout.log 2>&1 &APP_PID=$!# 90s: long enough to clear preflight and start the bundled installer.for i in $(seq 1 90); do@@ -553,9 +559,15 @@ jobs:echo "bundled installer: $SH"# --tauri rejects a custom studio home (install.sh:102-114), so drop the# workspace-scoped override; close stdin as install.rs does.+ SH="$(cd "$(dirname "$SH")" && pwd)/$(basename "$SH")"+ # Run it from outside the checkout, as the app does: a user launches Unsloth from the+ # desktop, not from a clone of this repository. Released bundles up to v0.1.902 resolve+ # `studio` against the cwd when locating setup.sh (fixed with -I in install.sh), so a+ # run from the checkout installed THIS ref's requirement pins into a released wheel+ # and preflight read studio_deps_missing (#12656 moved pyjwt).rc=0- env -u UNSLOTH_STUDIO_HOME \- bash "$SH" --tauri < /dev/null 2>&1 | tee logs/bundled-install.log || rc=$?+ (cd "$RUNNER_TEMP" && env -u UNSLOTH_STUDIO_HOME \+ bash "$SH" --tauri < /dev/null 2>&1) | tee logs/bundled-install.log || rc=$?echo "bundled installer exit code: $rc"[ "$rc" -eq 0 ] || {echo "::error::bundled installer exited $rc"@@ -583,8 +595,10 @@ jobs:set -a; [ -f ./clean-machine.env ] && . ./clean-machine.env; set +a# The one platform where a hosted runner can give the app a real display, so this# is the strongest "does the UI come up" check without self-hosted hardware.- xvfb-run -a --server-args="-screen 0 1440x900x24" \- "$BIN" > logs/app-stdout.log 2>&1 &+ # From outside the checkout, like a desktop launch (see the install step).+ BIN="$(cd "$(dirname "$BIN")" && pwd)/$(basename "$BIN")"+ (cd "$RUNNER_TEMP" && exec xvfb-run -a --server-args="-screen 0 1440x900x24" \+ "$BIN") > logs/app-stdout.log 2>&1 &APP_PID=$!for i in $(seq 1 90); dokill -0 "$APP_PID" 2>/dev/null || breakdiff --git a/install.ps1 b/install.ps1index b122f1073af..9a48e4c70b5 100644--- a/install.ps1+++ b/install.ps1@@ -11304,7 +11304,7 @@ main()}}- $installedPackageVersion = (& $VenvPython -c "+ $installedPackageVersion = (& $VenvPython -I -c "import systry:from studio.install_manifest import installed_version_probe@@ -11551,7 +11551,7 @@ sys.exit(2 if conflict else (0 if installed else 1))if ($script:WoaNativeCudaTorch) {$WoaStudioSetup = $nulltry {- $WoaStudioSetup = (& $VenvPython -c "import pathlib, studio; print(pathlib.Path(studio.__file__).parent / 'setup.ps1')" 2>$null | Select-Object -First 1)+ $WoaStudioSetup = (& $VenvPython -I -c "import pathlib, studio; print(pathlib.Path(studio.__file__).parent / 'setup.ps1')" 2>$null | Select-Object -First 1)} catch {}$WoaStudioAware = $falseif ($WoaStudioSetup -and (Test-Path -LiteralPath $WoaStudioSetup -PathType Leaf)) {diff --git a/install.sh b/install.shindex 016d08b757c..33b769d58ac 100755--- a/install.sh+++ b/install.sh@@ -8172,7 +8172,7 @@ fi# Same probe as install.ps1: version() answers from whichever record the finder yields first, so a duplicate would be reported here as an ordinary version._installed_package_version_exit=0-if _installed_package_version=$("$_VENV_PY" -c '+if _installed_package_version=$("$_VENV_PY" -I -c 'import systry:from studio.install_manifest import installed_version_probe@@ -8387,7 +8387,10 @@ if [ "$STUDIO_LOCAL_INSTALL" = true ] && [ -f "$_REPO_ROOT/studio/setup.sh" ]; tfiif [ -z "$SETUP_SH" ] || [ ! -f "$SETUP_SH" ]; then- SETUP_SH=$("$VENV_DIR/bin/python" -c "+ # -I: a bare -c puts the caller's cwd first on sys.path, so launching from an unsloth+ # checkout resolved `studio` to the checkout and ran ITS setup.sh, which installed the+ # checkout's requirement pins while the wheel's verify_install read the wheel's.+ SETUP_SH=$("$VENV_DIR/bin/python" -I -c "import importlib.resourcesprint(importlib.resources.files('studio') / 'setup.sh')" 2>/dev/null || echo "")diff --git a/tests/studio/install/test_installer_python_probes_are_isolated.py b/tests/studio/install/test_installer_python_probes_are_isolated.pynew file mode 100644index 00000000000..d5ed048d061--- /dev/null+++ b/tests/studio/install/test_installer_python_probes_are_isolated.py@@ -0,0 +1,101 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""Every installer probe that imports `studio` through `python -c` runs isolated (-I).++A bare `-c` puts the caller's working directory first on sys.path. Launched from an unsloth+checkout, `importlib.resources.files('studio')` then answered with the checkout instead of the+venv's wheel, so install.sh ran the checkout's setup.sh and installed the checkout's requirement+pins, while the wheel's verify_install compared against the wheel's. After #12656 moved pyjwt+to 2.15.1 in the repo, every desktop clean-machine leg (which runs the bundled installer from+the repository checkout) came up `studio_deps_missing` on a released wheel pinning 2.13.0.+"""++from __future__ import annotations++import re+from pathlib import Path++import pytest++_ROOT = Path(__file__).resolve().parents[3]+_INSTALLERS = ("install.sh", "install.ps1", "studio/setup.sh", "studio/setup.ps1")++# `-c` and its quoted program, with the flags written before it on the same logical line.+_DASH_C = re.compile(r"(?P<flags>(?:[ \t]+-[A-Za-z]+)*)[ \t]+-c[ \t]+(?P<q>['\"])")+_IMPORTS_STUDIO = re.compile(+ r"\bimport studio\b|\bfrom studio\b|files\(\s*['\"]studio['\"]\s*\)|import [\w ,]*\bstudio\b"+)+# The word before the flags names the interpreter: a python path or a variable holding one.+_INTERPRETER = re.compile(r"(?i)(python[\w.]*\"?|\$\w*py\w*\"?|\$\{?\w*py\w*\}?\"?)$")+++def _probes(text: str) -> list[tuple[str, str]]:+ """(flags, program) for every `<python> [flags] -c '<program>'` in an installer."""+ joined = re.sub(+ r"[\\`]\r?\n[ \t]*", " ", text+ ) # bash `\` and PowerShell backtick continuations+ found = []+ for match in _DASH_C.finditer(joined):+ before = joined[: match.start()].rsplit("\n", 1)[-1].rstrip()+ if not _INTERPRETER.search(before):+ continue+ quote = match.group("q")+ end = joined.find(quote, match.end())+ if end == -1:+ continue+ found.append((match.group("flags"), joined[match.end() : end]))+ return found+++def _offenders(text: str) -> list[str]:+ return [+ program.strip().splitlines()[0][:80]+ for flags, program in _probes(text)+ if _IMPORTS_STUDIO.search(program) and not re.search(r"(^|\s)-I\b", flags)+ ]++[email protected]("rel", _INSTALLERS)+def test_every_studio_probe_ignores_the_callers_directory(rel):+ path = _ROOT / rel+ if not path.is_file():+ pytest.skip(f"{rel} is not in this tree")+ offenders = _offenders(path.read_text(encoding = "utf-8"))+ assert not offenders, (+ f"{rel} imports `studio` through `python -c` without -I, so a run from an unsloth "+ f"checkout resolves the checkout's studio package instead of the venv's: {offenders}"+ )+++def test_the_scan_finds_the_probes_it_guards():+ """The sweep must actually see install.sh's setup.sh lookup, or it would pass by finding+ nothing at all."""+ programs = [p for _, p in _probes((_ROOT / "install.sh").read_text(encoding = "utf-8"))]+ assert any("files('studio') / 'setup.sh'" in p for p in programs)+ assert any("installed_version_probe" in p for p in programs)+++ "snippet, bad",+ [+ (+ 'SETUP_SH=$("$VENV_DIR/bin/python" -c "\nimport importlib.resources\nprint(importlib.resources.files(\'studio\'))\n")',+ True,+ ),+ (+ 'SETUP_SH=$("$VENV_DIR/bin/python" -I -c "\nprint(importlib.resources.files(\'studio\'))\n")',+ False,+ ),+ ("v=$(\"$_VENV_PY\" -c '\nfrom studio.install_manifest import x\n')", True),+ ('$x = (& $VenvPython -c "import pathlib, studio; print(studio.__file__)")', True),+ ('$x = (& $VenvPython -I -c "import pathlib, studio; print(studio.__file__)")', False),+ (+ '"$VENV_DIR/bin/python" -I \\\n -c "import importlib.resources as r; print(r.files(\'studio\'))"',+ False,+ ),+ ('"$PY" -c "import torch; print(torch.__version__)"', False),+ ],+)+def test_the_scan_tells_an_isolated_probe_from_a_bare_one(snippet, bad):+ assert bool(_offenders(snippet)) is bad