Repository navigation
install: support STUDIO_HOME / UNSLOTH_STUDIO_HOME for custom install paths - #5190
Conversation
… paths Currently install.sh and install.ps1 hardcode all install paths off $HOME / $env:USERPROFILE with no env-var fallback. This blocks workspace-isolated installs (CI sandboxes, per-PR test environments, multi-tenant boxes) unless the entire HOME / USERPROFILE is faked, which also relocates ~/.gitconfig, ~/.ssh, and other unrelated state. Add an opt-in env-var override that does only what is needed. Resolution priority (highest first): 1. HOME / USERPROFILE explicitly redirected vs the password-database default. Detected via getent (Linux), dscl (macOS), or [Environment]::GetFolderPath (Windows). Best-effort: when the detection mechanism is unavailable the check is skipped and we fall through to step 2. 2. UNSLOTH_STUDIO_HOME, if set. 3. STUDIO_HOME, if set (alias for convenience; the variable name already matches the internal var install.sh sets). 4. Default: legacy $HOME/.unsloth/studio (or $USERPROFILE\.unsloth\studio on Windows). Identical to today's behavior when no env var is set. When an env var override fires: * DATA_DIR is nested inside ($STUDIO_HOME/share, or $StudioHome\share on Windows) so the runtime launcher and shortcuts find studio.conf in the same place install-time wrote it. * The unsloth CLI shim lands at $STUDIO_HOME/bin/unsloth (Unix) or $StudioHome\bin\unsloth.exe (Windows). On Windows the shim already lives under $StudioHome; the change only redirects DATA_DIR and skips the persistent registry PATH update. * Persistent shell PATH modifications are skipped (no .bashrc / .zshrc / .profile append on Unix; no Add-ToUserPath on Windows). Caller is expected to invoke via absolute path or add the bin dir to PATH explicitly. Avoids polluting the user's profile with a workspace-scoped path that may be deleted. The Unix launcher script is the only piece that must read DATA_DIR at runtime (it sources studio.conf from there). The hardcoded DATA_DIR inside the LAUNCHER_EOF heredoc is replaced with an @@DATA_DIR@@ placeholder substituted via sed at install time, using the same approach the script already uses for other install-time substitutions. Default path behavior is unchanged: when no env var is set and HOME is not redirected, install.sh / install.ps1 produce exactly the same file layout as today. Test scenarios verified locally on install.sh: * Default (no env vars) -> $HOME/.unsloth/studio (legacy) * HOME=/tmp/x -> /tmp/x/.unsloth/studio * UNSLOTH_STUDIO_HOME=/tmp/y -> /tmp/y as STUDIO_HOME root * STUDIO_HOME=/tmp/z (alias) -> /tmp/z as STUDIO_HOME root * HOME redirect + env var (HOME wins) -> install follows HOME * Unwritable override -> exits with clear ERROR message
There was a problem hiding this comment.
Code Review
This pull request introduces support for custom installation directories via environment variables (UNSLOTH_STUDIO_HOME and STUDIO_HOME) and handles redirected home directories in both the PowerShell and Shell installers. It also modifies PATH management to avoid persistent system changes when using these overrides. Review feedback identified a bug in the PowerShell script where an invalid property access on a GUID object would prevent unique probe file creation, and suggested using the -- delimiter in shell commands to safely handle paths starting with dashes.
| Write-Host "ERROR: STUDIO_HOME=$envOverride cannot be created or accessed." -ForegroundColor Red | ||
| exit 1 | ||
| } | ||
| $probe = Join-Path $StudioHome (".unsloth-write-probe-" + [guid]::NewGuid().Guid) |
There was a problem hiding this comment.
The property .Guid does not exist on the System.Guid object returned by [guid]::NewGuid(). This results in the probe filename always being .unsloth-write-probe- without a unique suffix, which could lead to collisions if multiple installers run concurrently. Removing .Guid will allow PowerShell to use the default string representation of the GUID, ensuring uniqueness.
$probe = Join-Path $StudioHome (".unsloth-write-probe-" + [guid]::NewGuid())
| mkdir -p "$_override" 2>/dev/null || { echo "ERROR: STUDIO_HOME=$_override cannot be created." >&2; exit 1; } | ||
| [ -w "$_override" ] || { echo "ERROR: STUDIO_HOME=$_override is not writable." >&2; exit 1; } | ||
| STUDIO_HOME="$(cd "$_override" && pwd)" |
There was a problem hiding this comment.
It is safer to use -- with mkdir and cd to prevent paths starting with a dash from being interpreted as command-line options. This is particularly important for environment variables that might be user-controlled.
| mkdir -p "$_override" 2>/dev/null || { echo "ERROR: STUDIO_HOME=$_override cannot be created." >&2; exit 1; } | |
| [ -w "$_override" ] || { echo "ERROR: STUDIO_HOME=$_override is not writable." >&2; exit 1; } | |
| STUDIO_HOME="$(cd "$_override" && pwd)" | |
| mkdir -p -- "$_override" 2>/dev/null || { echo "ERROR: STUDIO_HOME=$_override cannot be created." >&2; exit 1; } | |
| [ -w "$_override" ] || { echo "ERROR: STUDIO_HOME=$_override is not writable." >&2; exit 1; } | |
| STUDIO_HOME="$(cd -- "$_override" && pwd)" |
Flip the resolution order so explicit env vars take precedence over HOME / USERPROFILE redirection. New priority (highest first): 1. UNSLOTH_STUDIO_HOME, if set. 2. STUDIO_HOME, if set. 3. HOME / USERPROFILE explicitly redirected. 4. Default. Rationale: the env vars are explicit single-purpose signals (the user typed UNSLOTH_STUDIO_HOME=... specifically to redirect Studio). HOME redirection is broader and incidental -- the user may have redirected HOME for unrelated reasons (workspace tools, container builds) without wanting Studio to follow it. When both are set, the more specific signal should win. When only HOME is redirected (no env var), behavior is unchanged from the previous commit: install follows $HOME.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 64b384b804
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| $StudioRedirectMode = 'env' | ||
| } else { | ||
| $StudioHome = Join-Path $env:USERPROFILE ".unsloth\studio" | ||
| $StudioDataDir = Join-Path $env:LOCALAPPDATA "Unsloth Studio" |
There was a problem hiding this comment.
Guard LOCALAPPDATA before building StudioDataDir
The new destination-resolution block computes $StudioDataDir with Join-Path $env:LOCALAPPDATA ... before any availability check, and this runs under $ErrorActionPreference = "Stop". In environments where LOCALAPPDATA is unset (for example, some service/CI contexts), Join-Path throws and aborts the installer, whereas the previous flow only skipped shortcut creation when LOCALAPPDATA was unavailable. Please null-check (or defer this assignment) so installs can continue without shortcuts.
Useful? React with 👍 / 👎.
|
|
||
| # Substitute @@DATA_DIR@@ with the resolved DATA_DIR. Use | as the | ||
| # sed delimiter so absolute paths (which contain /) are safe. | ||
| sed -i.bak "s|@@DATA_DIR@@|$DATA_DIR|g" "$_css_launcher" && rm -f "${_css_launcher}.bak" |
There was a problem hiding this comment.
Escape DATA_DIR before sed template substitution
This substitution inserts raw $DATA_DIR into sed's replacement string; with custom install paths containing replacement metacharacters (notably &), the generated launcher gets a corrupted DATA_DIR (e.g., /tmp/a&b expands to include the matched placeholder text). That breaks launch-studio.sh at runtime because it reads studio.conf from the wrong path. Escape replacement metacharacters before running sed.
Useful? React with 👍 / 👎.
… edge cases) Fixes from gemini-code-assist + chatgpt-codex-connector + reviewer.py 20-parallel run on the open PR. install.sh: * Escape sed replacement metacharacters before substituting @@DATA_DIR@@. Two-stage escape: ' -> '\'' for safe single-quote shell embedding, then \, &, | for sed replacement string + chosen delimiter. Heredoc switched to single-quoted DATA_DIR='@@DATA_DIR@@' so we only need single-quote escaping at runtime. Verified end-to-end with paths containing & and | (the sed delimiter). * Pass UNSLOTH_STUDIO_HOME into both setup.sh invocations (--local and PyPI paths) so the downstream install resolves the same Studio root install.sh picked. * macOS .app stub: replace hardcoded exec "$HOME/.local/share/unsloth/launch-studio.sh" with exec "$_css_data_dir/launch-studio.sh" so the .app launches the resolved launcher even in env-override mode. * Use mkdir -p -- and cd -- when validating the env override so paths starting with - cannot be misread as flags. install.ps1: * Drop .Guid from [guid]::NewGuid().Guid: the property does not exist; the probe filename was always identical and not unique. Default ToString() on System.Guid produces the canonical UUID string we want. * Guard LOCALAPPDATA before Join-Path to avoid aborting the installer in service / CI contexts where LOCALAPPDATA is unset (Join-Path under $ErrorActionPreference='Stop' would otherwise throw). Computed once into $defaultDataDir; both 'profile' and 'default' branches reuse it. * Set $env:UNSLOTH_STUDIO_HOME for the duration of the 'unsloth studio setup' subprocess so studio/setup.ps1 and unsloth_cli see the same install root install.ps1 picked. Restored in a finally block. studio/setup.sh: * Honor UNSLOTH_STUDIO_HOME / STUDIO_HOME (alias) when resolving STUDIO_HOME, VENV_DIR, VENV_T5_*_DIR. Falls back to the legacy $HOME/.unsloth/studio when no override is set. studio/setup.ps1: * Same change in PowerShell: honor $env:UNSLOTH_STUDIO_HOME / $env:STUDIO_HOME for $StudioHome / $VenvDir resolution. unsloth_cli/commands/studio.py: * Replace the module-level constant STUDIO_HOME = Path.home() / ".unsloth" / "studio" with a resolver that honors UNSLOTH_STUDIO_HOME / STUDIO_HOME before falling through to the legacy default. Same precedence the installers use. Verified locally: 6 install.sh scenarios still produce correct paths (default, HOME redirect, env var, alias, both, bad override). New sed-escape unit tests pass for paths containing & and |. Python resolver matches priority: UNSLOTH_STUDIO_HOME > STUDIO_HOME > default.
|
Pushed install.sh
install.ps1
studio/setup.sh, studio/setup.ps1, unsloth_cli/commands/studio.py
Local verification:
|
|
/gemini review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 570e6d323d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| override = os.environ.get("UNSLOTH_STUDIO_HOME") or os.environ.get("STUDIO_HOME") | ||
| if override: | ||
| return Path(override).expanduser().resolve() | ||
| return Path.home() / ".unsloth" / "studio" |
There was a problem hiding this comment.
Resolve studio home from active venv when override is unset
This fallback hard-codes ~/.unsloth/studio whenever UNSLOTH_STUDIO_HOME/STUDIO_HOME is not exported, but the new installer flow advertises launching from a custom shim path (for example <custom>/bin/unsloth) without requiring users to export env vars each time. In that case studio_default compares sys.prefix against STUDIO_HOME/unsloth_studio, treats the process as outside the Studio venv, then looks for a venv under ~/.unsloth/studio and exits with “Studio not set up,” so custom-path installs cannot launch reliably unless users manually set an env var on every run.
Useful? React with 👍 / 👎.
| cat > "$_css_macos_dir/launch-studio" << STUB_EOF | ||
| #!/bin/sh | ||
| exec "$HOME/.local/share/unsloth/launch-studio.sh" "\$@" | ||
| exec "$_css_data_dir/launch-studio.sh" "\$@" |
There was a problem hiding this comment.
Escape custom data dir before writing macOS launch stub
The macOS .app stub embeds $_css_data_dir directly into a double-quoted shell string, so custom install paths containing shell metacharacters (notably $) are expanded at runtime. For example, a path like /tmp/a$B produces a launcher that resolves to the wrong location and fails to execute launch-studio.sh. The main Unix launcher already escapes DATA_DIR; the macOS stub needs the same escaping to keep custom paths literal.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Code Review
This pull request introduces the ability to override the default installation directory using the UNSLOTH_STUDIO_HOME or STUDIO_HOME environment variables. These changes are implemented across the PowerShell and Bash installers, setup scripts, and the Python CLI to ensure consistent path resolution. The update also includes logic to handle session-specific PATH modifications and permission validation for custom directories. Feedback was provided regarding the portability of a sed command in the Bash installer to ensure compatibility across different systems.
| # 2) \, &, | for sed replacement-string + chosen delimiter | ||
| _sq_escaped=$(printf '%s' "$DATA_DIR" | sed "s/'/'\\\\''/g") | ||
| _sed_safe=$(printf '%s' "$_sq_escaped" | sed 's/[\\&|]/\\&/g') | ||
| sed -i.bak "s|@@DATA_DIR@@|$_sed_safe|g" "$_css_launcher" && rm -f "${_css_launcher}.bak" |
There was a problem hiding this comment.
The use of sed -i.bak is not POSIX-compliant and its behavior varies between GNU and BSD (macOS) versions of sed. For a #!/bin/sh script, a more portable approach is to redirect the output to a temporary file and then move it back to the original location. This avoids reliance on the -i flag which may not be available in minimal environments like BusyBox.
| sed -i.bak "s|@@DATA_DIR@@|$_sed_safe|g" "$_css_launcher" && rm -f "${_css_launcher}.bak" | |
| sed "s|@@DATA_DIR@@|$_sed_safe|g" "$_css_launcher" > "$_css_launcher.tmp" && mv "$_css_launcher.tmp" "$_css_launcher" |
GNU sed -i.bak vs BSD/macOS sed -i.bak vs BusyBox sed have subtly different semantics. Use the POSIX-portable redirect-then-mv pattern instead. Functionally identical, runs everywhere.
Without this, a custom-root install (UNSLOTH_STUDIO_HOME=/work/studio bash install.sh --local) only worked in the same shell that ran the installer. Closing the terminal and reopening lost the env var, the PATH was deliberately not persisted, and the Python CLI fell back to ~/.unsloth/studio. Result: 'Studio not set up' or quietly operating on a stale legacy install. Three persistence layers, all backwards-compatible (default installs emit zero changes): 1. Unix studio.conf install.sh now writes 'export UNSLOTH_STUDIO_HOME=...' next to UNSLOTH_EXE in studio.conf when in env-override mode. The launcher sources studio.conf at startup so the exec'd binary gets the var. Default installs do not write this line; studio.conf stays byte-identical to before. 2. Windows launch-studio.ps1 install.ps1 prepends '$env:UNSLOTH_STUDIO_HOME = ...' to the generated launcher when in env-override mode. Default installs produce the same launcher content as before. 3. Python sys.prefix inference storage_roots.studio_root() and unsloth_cli/commands/studio.py now infer the install root from sys.prefix when no env var is set (Path(sys.prefix).parent for unsloth_studio venvs). Catches direct invocations of <STUDIO_HOME>/bin/unsloth that bypass the launcher entirely. unsloth_cli/commands/studio.py also re-exports the resolved UNSLOTH_STUDIO_HOME via os.environ.setdefault so child processes (setup script, backend run.py) inherit it. Backend storage roots (storage_roots.studio_root, cache_root) now respect the env var via the shared resolver. run.py PID file, transformers_version.py T5 venvs, and model_config.py vision-check venv all switch to studio_root() so custom installs are self-contained. studio/setup.ps1: T5 sidecar venvs now resolve under $StudioHome (was $env:USERPROFILE\.unsloth\studio\.venv_t5_*). studio/setup.sh + studio/setup.ps1: llama.cpp build dir nests under $STUDIO_HOME / $StudioHome when env-override is active, otherwise keeps the legacy ~/.unsloth/llama.cpp. Verified locally: * studio.conf write block: env-override mode emits the export line; default mode does not (byte-identical to today). * PowerShell heredoc interpolation: correct output for both modes. * studio_root() resolver: default, UNSLOTH_STUDIO_HOME, STUDIO_HOME alias, and sys.prefix-based inference all return correct paths. * cache_root() now derives from studio_root().
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bad168e182
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if [ -n "${UNSLOTH_STUDIO_HOME:-}" ] || [ -n "${STUDIO_HOME:-}" ]; then | ||
| UNSLOTH_HOME="$STUDIO_HOME" |
There was a problem hiding this comment.
Gate llama.cpp relocation on real override state
STUDIO_HOME is always populated earlier in setup.sh, so this condition is always true and default installs now place llama.cpp under $HOME/.unsloth/studio/llama.cpp instead of the legacy $HOME/.unsloth/llama.cpp. The backend binary lookup (_find_llama_server_binary in studio/backend/core/inference/llama_cpp.py) still searches the legacy path unless UNSLOTH_LLAMA_CPP_PATH is set, so fresh default installs can fail to find llama-server for GGUF inference. Please key this branch off actual override mode (for example _studio_override) so non-override installs keep the old location.
Useful? React with 👍 / 👎.
Two fixes from running a 25-scenario simulation sweep against install.sh
across path edge cases (spaces, apostrophes, ampersands, pipes,
backslashes, dollar signs, Unicode, trailing slash, relative paths).
1. UNSLOTH_STUDIO_HOME=~/foo was landing as literal '~/foo' (env vars
are not subject to tilde expansion). Added a POSIX-portable case
block in install.sh, install.ps1, studio/setup.sh, studio/setup.ps1
that expands a leading ~ or ~/ to $HOME / $env:USERPROFILE.
The prefix-removal pattern is single-quoted ('${var#'~/'}') so the
shell does not tilde-expand the pattern back to $HOME/ before
matching -- a subtle dash/bash gotcha.
2. macOS .app stub used an unquoted heredoc ('<< STUB_EOF'), so any
$VAR / backtick / etc in the path would expand at .app launch time.
Switched to single-quoted heredoc ('<< 'STUB_EOF'') with a
placeholder + sed substitution + single-quoted shell embedding,
matching the @@DATA_DIR@@ pattern already used for launch-studio.sh.
Verified: 25/25 simulation scenarios pass on Linux dash + bash,
including paths with $VAR, &, |, \\, ', spaces, and Unicode. End-to-end
install in env-mode + fresh-shell launcher invocation confirmed: studio
binds to /api/health from a clean env, and sys.prefix-based inference
correctly returns the workspace root.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for custom installation directories via the UNSLOTH_STUDIO_HOME and STUDIO_HOME environment variables across Windows and Unix-like systems. The changes include updated logic in the installation and setup scripts to resolve, validate, and persist these custom paths, as well as centralized path resolution in the backend and CLI components. Feedback was provided to improve the robustness of shell scripts by adding explicit exit checks for subshell assignments, ensuring the scripts terminate correctly if directory resolution fails in shells like dash.
| if [ -n "$_override" ]; then | ||
| mkdir -p -- "$_override" 2>/dev/null || { echo "ERROR: STUDIO_HOME=$_override cannot be created." >&2; exit 1; } | ||
| [ -w "$_override" ] || { echo "ERROR: STUDIO_HOME=$_override is not writable." >&2; exit 1; } | ||
| STUDIO_HOME="$(cd -- "$_override" && pwd)" |
There was a problem hiding this comment.
In many shells (including dash, the default /bin/sh on Ubuntu), set -e does not trigger an exit when a subshell fails during a variable assignment. If cd fails here, STUDIO_HOME will be empty, which could lead to DATA_DIR being incorrectly set to /share. Adding || exit 1 ensures the script terminates on failure.
| STUDIO_HOME="$(cd -- "$_override" && pwd)" | |
| STUDIO_HOME="$(cd -- "$_override" && pwd)" || exit 1 |
| esac | ||
| if [ -n "$_studio_override" ]; then | ||
| mkdir -p -- "$_studio_override" | ||
| STUDIO_HOME="$(cd -- "$_studio_override" && pwd)" |
There was a problem hiding this comment.
Adding || exit 1 to the subshell assignment ensures the script exits if the directory cannot be resolved, preventing STUDIO_HOME from becoming empty and causing downstream path issues.
| STUDIO_HOME="$(cd -- "$_studio_override" && pwd)" | |
| STUDIO_HOME="$(cd -- "$_studio_override" && pwd)" || exit 1 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ee28571611
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if ($env:UNSLOTH_STUDIO_HOME -or $env:STUDIO_HOME) { | ||
| $UnslothHome = $StudioHome |
There was a problem hiding this comment.
Gate Windows llama.cpp relocation on true override mode
In studio/setup.ps1, the new if ($env:UNSLOTH_STUDIO_HOME -or $env:STUDIO_HOME) condition is true during normal installs because install.ps1 now always sets UNSLOTH_STUDIO_HOME before invoking studio setup. That relocates llama.cpp to $StudioHome\llama.cpp even for default installs, while backend discovery still defaults to %USERPROFILE%\.unsloth\llama.cpp unless UNSLOTH_LLAMA_CPP_PATH is set, so GGUF inference can fail to find llama-server on fresh Windows setups. This branch should key off actual override state, not mere env-var presence.
Useful? React with 👍 / 👎.
Reviewer.py 20-runs cycle 1 found a unanimous P1 regression: a default
'unsloth studio update' relocates llama.cpp from ~/.unsloth/llama.cpp
to ~/.unsloth/studio/llama.cpp, because the CLI was re-exporting
UNSLOTH_STUDIO_HOME unconditionally and install.sh / install.ps1 were
passing it into setup.{sh,ps1} unconditionally. The setup scripts
treated the var's mere presence as "env-override mode" and relocated
the llama.cpp build dir away from the legacy path, breaking the
runtime backend's _find_llama_server_binary lookup on default installs.
Fixes:
* unsloth_cli/commands/studio.py: _resolve_studio_home now returns
(path, is_custom). Re-export only when is_custom -- a real env
override or a sys.prefix inference that resolves to a non-legacy
path. Default installs leave UNSLOTH_STUDIO_HOME unset.
* install.sh: gate UNSLOTH_STUDIO_HOME on $_STUDIO_HOME_REDIRECT == env
before calling setup.sh. Use 'env $VARS bash setup.sh' so the var
is set only for the subprocess, never leaked.
* install.ps1: gate $env:UNSLOTH_STUDIO_HOME on $StudioRedirectMode
-eq 'env' before invoking 'unsloth studio setup'. Restore prior
value in finally block (unset if it wasn't set).
* studio/setup.sh + setup.ps1: decide llama.cpp install root from
the resolved $STUDIO_HOME (not from env-var presence). If the
resolved path equals the legacy default ($HOME/.unsloth/studio),
fall back to ~/.unsloth/llama.cpp. This makes setup robust against
a stale UNSLOTH_STUDIO_HOME inherited from a parent process that
happens to point at the legacy default.
* studio/backend/core/inference/llama_cpp.py:
- _find_llama_server_binary() now searches studio_root() / llama.cpp
AND the legacy ~/.unsloth/llama.cpp (de-duped). Custom-root
installs become discoverable; default installs unaffected.
- kill_orphaned_servers ownership allowlist also includes
studio_root() / llama.cpp so custom-root processes are cleanable.
Verified locally:
* 25/25 sim scenarios still pass (path edge cases unchanged).
* setup.sh unit test: default-mode lands UNSLOTH_HOME at $HOME/.unsloth;
env-mode lands at $STUDIO_HOME.
* Python CLI unit test: default-mode returns is_custom=False and does
NOT setdefault UNSLOTH_STUDIO_HOME; env-mode sets is_custom=True.
Gemini review feedback: in dash, set -e does not trigger on subshell failures inside variable assignments. If 'cd -- "$_override" && pwd' fails, STUDIO_HOME stays empty and DATA_DIR collapses to /share. Add explicit '|| exit 1' on both install.sh:187 and setup.sh:413.
|
Cycle-1 fixes pushed:
Default behavior is now byte-identical to today when no env var is set. |
|
/gemini review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 02ff12c529
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| _STUDIO_ENV_FOR_SETUP="UNSLOTH_STUDIO_HOME=$STUDIO_HOME" | ||
| fi | ||
| if [ "$STUDIO_LOCAL_INSTALL" = true ]; then | ||
| env $_STUDIO_ENV_FOR_SETUP \ |
There was a problem hiding this comment.
Quote custom STUDIO_HOME when passing env to setup.sh
The setup invocation uses env $_STUDIO_ENV_FOR_SETUP ... with an unquoted assignment string, so custom roots containing spaces or shell metacharacters are split before env runs. For example, UNSLOTH_STUDIO_HOME="/tmp/My Studio" becomes separate argv tokens and env fails before setup.sh executes, breaking the new custom-install flow for valid paths. Pass the variable as a quoted assignment (or set it inline with a quoted value) so the full path is preserved.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Code Review
This pull request introduces support for custom installation directories via the UNSLOTH_STUDIO_HOME and STUDIO_HOME environment variables. The changes include updating the PowerShell and Bash installers to resolve and persist these paths, modifying the Python backend to use a centralized studio_root helper, and updating the CLI to propagate these settings to child processes. Review feedback highlighted a potential issue in the Bash installer where unquoted environment variables could cause failures if paths contain spaces, suggesting a more robust assignment method.
| _STUDIO_ENV_FOR_SETUP="" | ||
| if [ "$_STUDIO_HOME_REDIRECT" = "env" ]; then | ||
| _STUDIO_ENV_FOR_SETUP="UNSLOTH_STUDIO_HOME=$STUDIO_HOME" | ||
| fi | ||
| if [ "$STUDIO_LOCAL_INSTALL" = true ]; then | ||
| env $_STUDIO_ENV_FOR_SETUP \ | ||
| SKIP_STUDIO_BASE="$_SKIP_BASE" \ | ||
| SKIP_STUDIO_FRONTEND="$_SKIP_FRONTEND" \ | ||
| STUDIO_PACKAGE_NAME="$PACKAGE_NAME" \ |
There was a problem hiding this comment.
The use of env $_STUDIO_ENV_FOR_SETUP without quotes is not space-safe. If STUDIO_HOME contains spaces, the shell will split the variable assignment into multiple arguments, causing env to fail (it will try to execute the second part of the path as a command). Additionally, for consistency with the PowerShell installer, UNSLOTH_STUDIO_HOME should be explicitly reset (set to an empty string) when not in env-override mode to prevent inheriting stale values from the parent shell. Using direct variable assignments before the command is a safer and more standard approach in POSIX sh.
| _STUDIO_ENV_FOR_SETUP="" | |
| if [ "$_STUDIO_HOME_REDIRECT" = "env" ]; then | |
| _STUDIO_ENV_FOR_SETUP="UNSLOTH_STUDIO_HOME=$STUDIO_HOME" | |
| fi | |
| if [ "$STUDIO_LOCAL_INSTALL" = true ]; then | |
| env $_STUDIO_ENV_FOR_SETUP \ | |
| SKIP_STUDIO_BASE="$_SKIP_BASE" \ | |
| SKIP_STUDIO_FRONTEND="$_SKIP_FRONTEND" \ | |
| STUDIO_PACKAGE_NAME="$PACKAGE_NAME" \ | |
| _STUDIO_HOME_VAL="" | |
| if [ "$_STUDIO_HOME_REDIRECT" = "env" ]; then | |
| _STUDIO_HOME_VAL="$STUDIO_HOME" | |
| fi | |
| if [ "$STUDIO_LOCAL_INSTALL" = true ]; then | |
| UNSLOTH_STUDIO_HOME="$_STUDIO_HOME_VAL" \ | |
| SKIP_STUDIO_BASE="$_SKIP_BASE" \ | |
| SKIP_STUDIO_FRONTEND="$_SKIP_FRONTEND" \ | |
| STUDIO_PACKAGE_NAME="$PACKAGE_NAME" \ |
| env $_STUDIO_ENV_FOR_SETUP \ | ||
| SKIP_STUDIO_BASE="$_SKIP_BASE" \ | ||
| SKIP_STUDIO_FRONTEND="$_SKIP_FRONTEND" \ | ||
| STUDIO_PACKAGE_NAME="$PACKAGE_NAME" \ |
There was a problem hiding this comment.
Applying the same space-safe assignment and explicit reset for the non-local install path to ensure UNSLOTH_STUDIO_HOME is correctly propagated or cleared.
| env $_STUDIO_ENV_FOR_SETUP \ | |
| SKIP_STUDIO_BASE="$_SKIP_BASE" \ | |
| SKIP_STUDIO_FRONTEND="$_SKIP_FRONTEND" \ | |
| STUDIO_PACKAGE_NAME="$PACKAGE_NAME" \ | |
| UNSLOTH_STUDIO_HOME="$_STUDIO_HOME_VAL" \ | |
| SKIP_STUDIO_BASE="$_SKIP_BASE" \ | |
| SKIP_STUDIO_FRONTEND="$_SKIP_FRONTEND" \ | |
| STUDIO_PACKAGE_NAME="$PACKAGE_NAME" \ |
Cycle 2 reviewer.py 20-runs found a unanimous P1: passing the env-var through 'env $_STUDIO_ENV_FOR_SETUP' word-splits on whitespace, so a custom root like '/tmp/Unsloth Studio' becomes 'UNSLOTH_STUDIO_HOME= /tmp/Unsloth' followed by env trying to exec 'Studio'. Replaced with a tiny helper that prepends the env-var directly to the argv (no string-form intermediary), so spaces are preserved as a single argument. Default-mode invocation skips the env-var entirely. Verified: 'UNSLOTH_STUDIO_HOME=/tmp/test space/studio' now reaches setup.sh as a single value.
|
Cycle-2 fix: argv-safe setup handoff. The unanimous P1 was that |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements support for custom installation roots using the UNSLOTH_STUDIO_HOME and STUDIO_HOME environment variables. The changes span the PowerShell and Shell installers, the CLI, and the backend path resolution utilities, ensuring that virtual environments, data directories, and binaries are correctly located in custom workspaces while preserving backward compatibility for default installations. I have no feedback to provide.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME (#5190) already moves the Studio root, the share dir, the shim and the native runtimes, and suppresses the shell-rc and desktop-entry writes, but two things were missing: nothing tells anyone the mode exists, and uv still writes its wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is the largest single thing landing in the home directory. --portable contains the install where it already is; --root DIR relocates it. Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a cache after the fact. Verified against uv directly: a venv, a pip install and a managed CPython download leave zero files in the home directory. The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so bin/unsloth from a fresh shell would find the interpreter (the backend infers STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until the first update, then not. studio.conf restates the same roots for the launcher. --tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio in Rust and never sees a per-session variable, so it would launch a Studio that is not there. Default installs are unchanged.
…r asked for Five defects found by reviewing the stack against its own acceptance criteria. Each fix was checked by removing it again and watching the new test fail. 1. Uninstalling no longer empties ~/.unsloth. --portable with no --root selects that directory for the user, so it is the one root they never named, and anything they keep beside Unsloth is theirs. The master-root loop rm -rf'd it whole; it now takes the portable children by name and leaves the rest to the default block's rmdir, which refuses a non-empty directory. A root the user DID name still goes in one piece, as it always has for UNSLOTH_STUDIO_HOME. Before: a file at ~/.unsloth/important.txt was deleted. After: it survives. 2. The portable shim, share/studio.conf and _export_portable_roots defaulted the cache locations instead of seizing them. storage_roots._setup_cache_env() has always yielded to an explicit value and main's _configure_uv_cache reports "preserving custom UV_CACHE_DIR", so the same install honoured or discarded a user's multi-GB wheel cache depending on the entry point. Identity stays forced, and so does UV_NO_MODIFY_PATH, which is a promise rather than a path. The installer now names any cache it kept, since one outside the root means rm -rf on the root no longer removes everything. 3. Converting a pre-#5190 install with --portable is no longer refused. The ownership guard wants a sentinel under STUDIO_HOME, and #5190 shipped all three of them alongside custom-root support, so an install last refreshed before 2026-05-05 has none: its studio.conf went to ~/.local/share/unsloth. That tree was accepted by a plain upgrade and refused by the same upgrade plus --portable. The legacy location now counts, but only for the legacy default root, never for a directory the user named. 4. .unsloth-master-root is written through a temporary and renamed. The redirection truncated on open, so a write that then failed left a previous valid record empty, and the error arm cleared its own rollback slot. A full volume is exactly what a portable root on a removable disk meets. The -d test in front is not redundant: mv moves a file INTO a directory rather than failing, which would have reported success and left no record. 5. A plain re-run keeps a portable install portable. The documented update is `curl ... | sh` with no arguments, and the shim's environment does not reach a fresh shell, so that read as a request for a normal install: the markers went, and every cache moved back under $HOME. The installer now adopts the marker a previous run left. Converting back is still available and now has to be asked for, with UNSLOTH_PORTABLE=0. This changes a contract four tests asserted deliberately. What those tests protect is that a marker cannot leave the tree reading as portable with no way out; that still holds, because UNSLOTH_PORTABLE=0 makes the installer normal, which clears the marker, which makes the runtime normal. Only the default moved, from converting silently to preserving what is there. Also: portable mode moves the Hugging Face cache under the root, which costs a re-download rather than a recompile, so the installer now says so when it finds a warm ~/.cache/huggingface and the user named no HF variable of their own. tests/sh: 0 failures across the directory.
Each was reproduced before it was fixed, and each fix proven by removing it and watching the new checks fail. Publish the parent portable marker through a rename. A redirection truncates before printf runs, so a write that died partway left a zero-byte marker at the path every reader tests with -f, and the failure arm cleared the rollback slot so nothing removed it. Measured: install.sh and storage_roots.portable_mode() both reported portable=true off an empty marker, on an install that had already exited 1. Re-publication over a real portable install truncated its root away. Staging and renaming gives both answers: nothing on a first failure, the previous bytes on a later one. A symlink at the marker path is now replaced rather than followed, which also stops the old in-place write truncating whatever it named. Tell a typed --tauri from an adopted portable layout. Since portable mode is adopted from markers on disk, a desktop repair, which passes --tauri and nothing else, was refused with a message naming --portable and --root on a machine where neither was supplied. Reachable by following the documented instructions, since --portable with no --root selects $HOME/.unsloth, the directory the desktop app uses. Still a refusal, since installing over a portable tree would leave the desktop launching a Studio that is not there, but the message now describes the install and gives the way out. Compare the venv ownership evidence canonically. Installers before #5190 wrote UNSLOTH_EXE with the lexical $HOME spelling while env-mode canonicalizes STUDIO_HOME, so on a symlinked HOME our own config stopped vouching for our own venv and the upgrade died with does not look like an Unsloth Studio install. main accepted any existing studio.conf, so this refusal came in with the tightening. The comparison is canonicalized, not dropped: a config naming another venv, or another program, still fails. Retire the portable configuration a conversion leaves behind. A nested portable run writes share/studio.conf and launch-studio.sh at <root>/share, one level above the tree it owns, and converting back wrote a new pair into <root>/studio/share while retiring only <root>/bin/unsloth. Two otherwise-valid launchers over one install, and whichever path the user kept decided where the HF caches and the projects root went. Moved aside like the wrapper, only when the config is ours and names this install, and never in the flat layout where that share/ is the one being written. Resolve the HF stranding notice through XDG_CACHE_HOME, the way huggingface_hub resolves it. Hardcoding $HOME/.cache looked in the wrong place for anyone who sets it, so exactly the users whose cache is somewhere unusual got no warning it was about to be stranded. Register the generated shim's staging file with the cleanup trap. Its inline failure arm cannot run when a signal diverts into the trap, which left .unsloth.shim.<pid> in the user's ~/.local/bin, where a successful retry never looks and nothing prunes it.
The ordering ones are mine, from the two commits before this. _epr_default was added to stop portable mode overriding a cache location the user chose, but _export_portable_roots is CALLED after the block that seeds UV_CACHE_DIR, so it read the installer's own seed back as a caller's choice: a nested install filled <root>/studio/cache/uv while the shim, studio.conf and storage_roots all read <root>/cache/uv, and a user who had set nothing was told their cache locations were being kept. Both halves are fixed, the seed is portable-aware and the equality case is not counted as a choice. The conversion escape hatch cleared only the private copy of the root. Nothing unsets UNSLOTH_HOME, and setup.sh inherits it and prefers it over a custom Studio root for node, llama.cpp and whisper.cpp, so a conversion could report success while the runtimes it installed sat under the old master root. The flat-vs-nested test during conversion used bare directory existence, where _resolve_studio_destinations and the parent-marker guard both require ownership sentinels; a flat root with a leftover studio/ converted the wrong tree. The legacy launcher record is matched byte-exact against a path written with a logical pwd while env-mode canonicalizes with cd -P, so under a symlinked HOME the installer refused a pre-#5190 install of its own. studio/setup.sh run directly recovered the master root after choosing the uv cache rather than before, and derived neither UV_INSTALL_DIR, UV_NO_MODIFY_PATH nor NPM_CONFIG_CACHE, so uv landed in ~/.local/bin, shell startup files gained permanent PATH lines and npm wrote ~/.npm. The uninstaller never named the default portable root, so the documented flagless uninstall left bin/, share/, cache/ and the marker behind while reporting success; a symlinked studio/ had its database recorded lexically and reported gone while intact on another volume; and a flat root's studio.db was removed without recording it, closing with no studio.db was found. README no longer promises that a flagless update finds every portable install. It cannot find one made with --root, and said so nowhere.
Summary
install.shandinstall.ps1hardcode all install paths off$HOME/$env:USERPROFILEwith no env-var fallback. This blocks workspace-isolated installs (CI sandboxes, per-PR test environments, multi-tenant boxes) unless the entireHOME/USERPROFILEis faked, which also relocates~/.gitconfig,~/.ssh, and other unrelated state.This PR adds an opt-in env-var override that does only what is needed. Default behavior is unchanged when no env var is set.
Scope
This PR covers shell-launched installs and the Python backend only. The Tauri desktop app is intentionally out of scope (see "Limitations" below).
Resolution priority
Highest to lowest:
UNSLOTH_STUDIO_HOME, if set.STUDIO_HOME, if set. Convenience alias since the variable name already matches the internal var install.sh sets.HOME/USERPROFILEexplicitly redirected vs the password-database default. Detected viagetent(Linux),dscl(macOS), or[Environment]::GetFolderPath("UserProfile")(Windows). Best-effort: when the detection mechanism is unavailable the check is skipped and we fall through to step 4.$HOME/.unsloth/studio(or$USERPROFILE\.unsloth\studioon Windows). Identical to today's behavior.The env vars are explicit single-purpose signals (the user typed
UNSLOTH_STUDIO_HOME=...specifically to redirect Studio).HOMEredirection is broader and incidental: the user may have redirectedHOMEfor unrelated reasons without wanting Studio to follow it. When both are set, the more specific signal wins.What changes when an env-var override fires
STUDIO_HOME$HOME/.unsloth/studioDATA_DIR$HOME/.local/share/unsloth$STUDIO_HOME/share_LOCAL_BIN(unsloth shim)$HOME/.local/bin$STUDIO_HOME/bin$HOME/.unsloth/llama.cpp$STUDIO_HOME/llama.cpp(unless override resolves to the legacy default, in which case it stays at$HOME/.unsloth/llama.cppto keep one shared build across legacy installs)Persistent shell-profile and registry PATH writes are skipped under env-override mode so the user's profile is not polluted with a workspace-scoped path that may later be deleted. Caller is expected to invoke via absolute path or add the bin dir to PATH explicitly.
Generated runtime launcher
The Unix launcher script (
launch-studio.sh) is the only piece that readsDATA_DIRat runtime (it sourcesstudio.conffrom there). The hardcodedDATA_DIRinside theLAUNCHER_EOFheredoc is replaced with an@@DATA_DIR@@placeholder substituted viasedat install time, so the runtime launcher readsstudio.conffrom the same place install-time wrote it.The PowerShell launcher already bakes the absolute exe path directly into the launcher script, so no analogous heredoc substitution is needed there.
In env-override mode,
studio.confalso exportsUNSLOTH_STUDIO_HOMEandUNSLOTH_LLAMA_CPP_PATHso a fresh shell launching the binary directly (no shell rc inheritance) still resolves the same Studio root and llama.cpp build dir as the install.Python CLI / backend
unsloth_cli/commands/studio.pyandstudio/backend/utils/paths/storage_roots.pyresolve the Studio root with the same priority chain (UNSLOTH_STUDIO_HOME->STUDIO_HOME->sys.prefixinference with installer sentinel -> legacy default). The Python CLI re-exportsUNSLOTH_STUDIO_HOMEandUNSLOTH_LLAMA_CPP_PATHonly when the resolved root is a real custom override (not the legacy default), so downstream subprocesses (setup.sh, backendrun.py) and unsloth-zoo's import-time GGUF binding all see the same custom root.Limitations
The Tauri desktop app does NOT honor
UNSLOTH_STUDIO_HOME/STUDIO_HOME. It continues to use the legacy~/.unsloth/studiopath for:unslothbinary lookup (process.rs::find_unsloth_binary).desktop_secretfor desktop login (desktop_auth.rs)tauri.loglocation (main.rs::setup_logging)commands.rs::open_logs_dir)install.rs)This is intentional. The desktop app launches from Finder / Start Menu / Desktop without inheriting the launching shell's environment, so a per-session env var doesn't reach the app process. Bridging that gap requires a persistence mechanism (marker file, registry entry, or app-config setting) with its own cleanup / validation surface, which is out of scope for this PR.
If you need workspace-isolated Studio installs that the Tauri desktop app can also pick up, either:
UNSLOTH_STUDIO_HOMEin your shell rc / system environment so the desktop app inherits it on every login.A separate, focused PR can add proper Tauri-side custom-root support later.
Examples
Test plan
$HOME/.unsloth/studio,$HOME/.local/share/unsloth,$HOME/.local/bin. Byte-identical to pre-PR.HOME=/tmp/x bash install.sh --local: paths resolve under/tmp/x/.UNSLOTH_STUDIO_HOME=/tmp/y bash install.sh --local: paths resolve under/tmp/y/{share,bin}.STUDIO_HOME=/tmp/z bash install.sh --local(alias): same as above.HOMEredirect andUNSLOTH_STUDIO_HOMEset: env var wins, install follows the override.UNSLOTH_STUDIO_HOME=/proc/1/cantwrite: exits with clearERROR: STUDIO_HOME=... cannot be created.message.UNSLOTH_STUDIO_HOME=$HOME/.unsloth/studio(override equals legacy default): llama.cpp resolves to$HOME/.unsloth/llama.cpp(legacy-equality branch).bash -n install.shclean; PowerShell parser clean oninstall.ps1,setup.sh,setup.ps1.test_unsloth_studio.py --pr 5190 --temp-workspace: clones PR branch, installs Studio withUNSLOTH_STUDIO_HOMEpinned to a temp workspace, starts the backend, drives the UI via Playwright MCP. PR code resolves under the workspace, /chat and /studio render, all API calls return 200.cargo test --bins -- --test-threads=1-> 34/34 pass (pre-PR baseline; Tauri code unchanged).Backwards compatibility
When no env var is set and
HOMEis at the password-DB default, the produced file layout, the shell rc PATH append, the Windows registry PATH update, and all desktop /unsloth studio updateflows are byte-identical to today. Existing--local,--no-torch,--package,--python,--tauri,--verboseflags are untouched.