From 6e2f64b3b68cd954aced4520082ad0d46d7f496f 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 --- studio/backend/utils/paths/storage_roots.py | 6 ++++++ studio/setup.ps1 | 4 ++++ unsloth_cli/commands/studio.py | 7 ++++++- 3 files changed, 16 insertions(+), 1 deletion(-) 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 4a791ef2b1..0aa7c0335f 100644 --- a/studio/setup.ps1 +++ b/studio/setup.ps1 @@ -968,6 +968,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/unsloth_cli/commands/studio.py b/unsloth_cli/commands/studio.py index a39f050d5f..933fad1c53 100644 --- a/unsloth_cli/commands/studio.py +++ b/unsloth_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 unsloth_cli/commands/studio.py -- two parents up is the package root