From 40c5b86005187cc3540e8473e413f75bb30427a5 Mon Sep 17 00:00:00 2001 From: Roland Tannous Date: Tue, 17 Mar 2026 19:20:14 +0000 Subject: [PATCH] fix: persist studio home path across server restarts --- cli/commands/studio.py | 7 ++++++- studio/backend/utils/paths/storage_roots.py | 6 ++++++ studio/setup.ps1 | 4 ++++ studio/setup.sh | 3 +++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cli/commands/studio.py b/cli/commands/studio.py index 33375a89dd..2ec7e8c885 100644 --- a/cli/commands/studio.py +++ b/cli/commands/studio.py @@ -14,10 +14,15 @@ studio_app = typer.Typer(help = "Unsloth Studio commands.") def _studio_home() -> Path: - """Studio root, overridable via UNSLOTH_STUDIO_HOME.""" + """Studio root: env var > config file > default.""" custom = os.environ.get("UNSLOTH_STUDIO_HOME") if custom: return Path(custom).expanduser().resolve() + conf = Path.home() / ".unsloth" / "studio_home" + if conf.is_file(): + saved = conf.read_text().strip() + if saved: + return Path(saved).expanduser().resolve() return Path.home() / ".unsloth" / "studio" # __file__ is cli/commands/studio.py — two parents up is the package root diff --git a/studio/backend/utils/paths/storage_roots.py b/studio/backend/utils/paths/storage_roots.py index caed95639d..dab68a6852 100644 --- a/studio/backend/utils/paths/storage_roots.py +++ b/studio/backend/utils/paths/storage_roots.py @@ -9,9 +9,15 @@ import tempfile def studio_root() -> Path: + """Studio root: env var > config file > default.""" custom = os.environ.get("UNSLOTH_STUDIO_HOME") if custom: return Path(custom).expanduser().resolve() + conf = Path.home() / ".unsloth" / "studio_home" + if conf.is_file(): + saved = conf.read_text().strip() + if saved: + return Path(saved).expanduser().resolve() return Path.home() / ".unsloth" / "studio" diff --git a/studio/setup.ps1 b/studio/setup.ps1 index 2966b2ed39..36b9990f24 100644 --- a/studio/setup.ps1 +++ b/studio/setup.ps1 @@ -828,6 +828,10 @@ Write-Host "[OK] Using $PythonCmd ($(& $PythonCmd --version 2>&1))" -ForegroundC # ── Studio home (configurable via UNSLOTH_STUDIO_HOME) ── $StudioHome = if ($env:UNSLOTH_STUDIO_HOME) { $env:UNSLOTH_STUDIO_HOME } else { Join-Path $env:USERPROFILE ".unsloth\studio" } +# Persist for future `unsloth studio` runs (survives shell restarts) +$UnslothDir = Join-Path $env:USERPROFILE ".unsloth" +if (-not (Test-Path $UnslothDir)) { New-Item -ItemType Directory -Path $UnslothDir -Force | Out-Null } +Set-Content -Path (Join-Path $UnslothDir "studio_home") -Value $StudioHome -NoNewline $VenvDir = Join-Path $StudioHome ".venv" if (-not (Test-Path $VenvDir)) { diff --git a/studio/setup.sh b/studio/setup.sh index caf15d40c9..b92a5930cb 100755 --- a/studio/setup.sh +++ b/studio/setup.sh @@ -231,6 +231,9 @@ else # Configurable via UNSLOTH_STUDIO_HOME; defaults to ~/.unsloth/studio STUDIO_HOME="${UNSLOTH_STUDIO_HOME:-$HOME/.unsloth/studio}" echo " Studio home: $STUDIO_HOME" + # Persist for future `unsloth studio` runs (survives shell restarts) + mkdir -p "$HOME/.unsloth" + echo "$STUDIO_HOME" > "$HOME/.unsloth/studio_home" VENV_DIR="$STUDIO_HOME/.venv" VENV_T5_DIR="$STUDIO_HOME/.venv_t5" mkdir -p "$STUDIO_HOME"