Skip to content

studio update --local: refuse site-packages as the repo root - #7693

Merged
danielhanchen merged 7 commits into
mainfrom
studio-update-local-repo-root
Aug 1, 2026
Merged

danielhanchen merged 7 commits into
mainfrom
studio-update-local-repo-root

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

What happened

unsloth studio update --local failed on Windows with:

ERROR: file:///C:/Users/runneradmin/.unsloth/studio/unsloth_studio/Lib/site-packages
does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.
[FAILED] Python dependency installation failed (exit code 1)
   Re-run the installer or check the error above for details.

STUDIO_LOCAL_REPO is derived as Path(__file__).resolve().parents[2]. That is the repo root only while the CLI runs from a checkout. When the CLI is running from an installed copy, parents[2] is site-packages, and uv is then asked to install site-packages as a project.

The existing comment already anticipated this ("which may be inside site-packages"); nothing actually checked it.

The change

  • An explicitly set STUDIO_LOCAL_REPO is honoured instead of being overwritten, so a --local update can be pointed at a real checkout:
    STUDIO_LOCAL_REPO=/path/to/unsloth unsloth studio update --local
  • A root with no pyproject.toml is refused up front, naming both ways forward, rather than reaching uv and producing an error that does not identify the real problem.

Exit code 2, matching the CLI's existing usage-error convention.

Scope

--local is the source-install path used by CI and developers. The PyPI path is untouched and never looks for a checkout; a test asserts a stale STUDIO_LOCAL_REPO does not leak into a plain unsloth studio update.

This is an error-reporting and override fix. It does not claim to make repeat --local updates work on Windows, which is blocked by a separate problem: unsloth studio update --local cannot replace the running unsloth.exe. _release_self_exe_lock_windows renames it out of the way first, and that rename itself fails with WinError 32, after which pip's reinstall fails the same way. That one is reported separately.

Tests

4 new tests in unsloth_cli/tests/test_studio_update_local_repo.py. 2 of the 4 fail against main.

danielhanchen and others added 2 commits July 31, 2026 14:48
The second consecutive `unsloth studio update --local` failed on Windows:

    ERROR: file:///C:/Users/.../unsloth_studio/Lib/site-packages does not appear
    to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.
    [FAILED] Python dependency installation failed (exit code 1)

STUDIO_LOCAL_REPO was derived as Path(__file__).parents[2], which is the repo
root only while the CLI runs from a checkout. The first update replaces the
editable install with a normal one, so on the second run parents[2] is
site-packages and uv is asked to install site-packages as a project. The
existing comment already noted the path 'may be inside site-packages'; nothing
checked it.

An explicitly set STUDIO_LOCAL_REPO is now honoured, which makes repeat local
updates work, and a root with no pyproject.toml is refused with the two ways
forward instead of uv's error. Found by a Windows update matrix on staging;
the first update passes there and only the second failed.
A relative override passed the guard and then failed anyway. The check runs
against update()'s cwd, but the value is handed downstream verbatim, and
studio/setup.sh does `cd "$SCRIPT_DIR"` (line 1031) before it calls
install_python_stack (line 1105). So `STUDIO_LOCAL_REPO=.` re-resolved against
studio/, which has neither pyproject.toml nor setup.py, and uv produced exactly
the error this guard exists to replace.

Also strip and expanduser the value: a tilde path is the natural way to name a
checkout and was never expanded, and a whitespace-padded value rejected a valid
one. The sibling reader at studio.py:2744 already strips.

Three tests added; all three fail without the change.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d261dab13f

ℹ️ 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".

Comment thread unsloth_cli/commands/studio.py Outdated
typer.echo("", err = True)
typer.echo(" Point at a checkout:", err = True)
typer.echo(
" STUDIO_LOCAL_REPO=/path/to/unsloth unsloth studio update --local", err = True

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Print a Windows-valid checkout override

When this guard is reached from the native Windows/PowerShell installed-copy scenario that motivated the change, the suggested STUDIO_LOCAL_REPO=/path/to/unsloth ... command is POSIX assignment syntax and PowerShell attempts to execute it as a command name. Consequently, users who want the --local path still cannot follow the only displayed recovery instruction; select the example by platform (for example, $env:STUDIO_LOCAL_REPO = 'C:\path\to\unsloth'; unsloth studio update --local on PowerShell).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, and it is the only recovery line printed. Windows now gets \$env:STUDIO_LOCAL_REPO='C:\path\to\unsloth'; unsloth studio update --local, matching the platform branching already used for the installer hints in start.py. Kept the no-space form so the existing assertion stays valid on all three OSes.

Comment on lines +2928 to +2931
repo_root = (
Path(_explicit).expanduser().resolve()
if _explicit
else Path(__file__).resolve().parents[2]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Run setup from the selected checkout

When an installed CLI uses this new override to target a fresh checkout, _run_setup_script() still selects setup.sh/setup.ps1 relative to the installed _PACKAGE_ROOT, rather than from repo_root. Those scripts build $SCRIPT_DIR/frontend before installing STUDIO_LOCAL_REPO editable; pip then removes the installed package tree, while a fresh checkout has no tracked studio/frontend/dist because that directory is gitignored. The resulting editable Studio installation therefore cannot find its web frontend, so the override path should run the checkout's setup script (or otherwise build the checkout's frontend) instead of merely passing its path to the installed setup script.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed the whole chain and fixed in 0b1fa16. _run_setup_script did resolve the script from _PACKAGE_ROOT; studio/frontend/dist is gitignored (0 tracked files); and I reproduced the displacement with a synthetic same-shape package, where pip install --no-deps -e <checkout> removed the wheel's whole package tree including the bundled dist. _find_setup_script now takes the override checkout first, and is unchanged when there is no override.

if _explicit
else Path(__file__).resolve().parents[2]
)
if not (repo_root / "pyproject.toml").is_file():

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Verify the override is actually an Unsloth checkout

When STUDIO_LOCAL_REPO accidentally names another Python project (for example, a monorepo parent or sibling that also has a pyproject.toml), this check accepts it as an Unsloth checkout. install_python_stack.py then passes that directory to pip/uv with -e, which can succeed by installing the unrelated project while the dependency pass leaves the PyPI copy of Unsloth in place; the command reports success even though none of the requested local Unsloth code was installed. Validate an Unsloth-specific marker or the project identity rather than only the presence of a generic Python manifest.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this one. STUDIO_LOCAL_REPO is an explicit escape hatch the user types deliberately, and the message that prints it names an Unsloth checkout; reaching the state needs the user to name the wrong directory, and the outcome is a no-op on unsloth rather than a crash or data loss. An unsloth/ directory check would also mean touching three existing tests that build minimal fixtures, which is more churn than a user-error-only path earns.

…d hint

Two review findings on the STUDIO_LOCAL_REPO escape hatch this PR adds.

The override chose which repo gets installed but not which setup script
ran: _run_setup_script resolved setup.sh/setup.ps1 from _PACKAGE_ROOT.
Those scripts build the frontend under their own SCRIPT_DIR, and the
editable install of the override removes the installed tree they built
into. studio/frontend/dist is gitignored, so pointing at a fresh checkout
left Studio with no frontend and `unsloth studio run` exiting 1. The
checkout's own script now takes precedence; with no override the
resolution order is unchanged.

The guard also printed only `STUDIO_LOCAL_REPO=/path/to/unsloth ...`,
which is POSIX prefix-assignment syntax. PowerShell parses that as a
command name, so the sole recovery instruction did not work on the
platform the guard exists for. Windows now gets the $env: form.

All three regression tests fail against the unfixed source.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0b1fa1604a

ℹ️ 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".

Comment thread unsloth_cli/commands/studio.py Outdated
Comment on lines 298 to 301
if s.is_file():
return s
# 1. Relative to __file__ (site-packages or editable repo root)
s = _PACKAGE_ROOT / "studio" / name

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject checkouts missing the platform setup script

When STUDIO_LOCAL_REPO is a valid but sparse/partial Unsloth checkout whose pyproject.toml exists but studio/setup.sh or setup.ps1 does not, this new branch silently falls through to the installed copy's setup script. That recreates the wrong-tree behavior this change is intended to prevent: the installed script builds its own frontend, then the editable install can remove that installed package tree and leave the selected checkout without a frontend. Treat a missing checkout-local setup script as an invalid local source instead of falling back.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, the fallback reintroduced the exact behaviour the branch exists to stop. Fixed in b7f71b5: an explicit checkout now resolves to its own script or to nothing, and _run_setup_script reports the missing studio/setup.sh/setup.ps1 by path rather than the generic not-found message. The no-override resolution order is untouched. Regression test added and confirmed failing against the previous commit.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

2 similar comments
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 0b1fa1604a

ℹ️ 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".

Falling back to the installed copy's setup script is the behaviour the
override exists to stop: that script builds its own frontend, the
editable install then removes the tree it built into, and the selected
checkout is left without one. A sparse checkout is an unusable local
source, so say so rather than quietly running somebody else's script.
The message names the missing path; the no-override resolution order is
unchanged.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b7f71b52e8

ℹ️ 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".

Comment on lines +299 to +301
if repo_root is not None:
s = repo_root / "studio" / name
return s if s.is_file() else None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject Windows checkouts missing frontend sources

On Windows, a sparse Unsloth checkout that contains pyproject.toml and studio/setup.ps1 but omits studio/frontend passes this validation. In studio/setup.ps1, the missing frontend directory sets $IsPipInstall and skips the build as though a bundled frontend already existed; the subsequent editable install then removes the installed package containing that bundle and points Studio at the sparse checkout, leaving no frontend/dist despite a successful update. Require the checkout's frontend sources here (except where an explicitly frontend-free mode is safe) before selecting its setup script.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked this one carefully and I am not taking it, though the Windows chain you describe is mechanically accurate.

Three things decide it. studio/frontend is 1035 tracked files, so reaching this state means keeping pyproject.toml and studio/setup.ps1 while deleting the whole frontend tree, which is a hand-mutilated checkout rather than legitimate input. The end state is also unchanged by this PR: before it, --local ran the installed copy's setup.ps1 and the same pip install -e <sparse repo> uninstalled the tree it had just built into, so no frontend/dist either way. And it is not silent, run.py exits with the frontend-not-found error and a remediation list.

The check also cannot be platform-neutral: setup.sh has UNSLOTH_STUDIO_LLAMA_ONLY=1 (setup.sh:626), a supported frontend-free mode with no setup.ps1 equivalent, so requiring the sources on POSIX would break a working flow. POSIX is already safe regardless, since setup.sh aborts at cd \"$SCRIPT_DIR/frontend\" under set -e before install_python_stack.py ever runs.

Happy to revisit if you have a path to a frontend-less checkout that does not involve deleting tracked files.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: b7f71b52e8

ℹ️ 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".

@danielhanchen
danielhanchen merged commit 7869f3f into main Aug 1, 2026
82 of 83 checks passed
@danielhanchen
danielhanchen deleted the studio-update-local-repo-root branch August 1, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant