Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

CLI: stop verify-install describing an unrelated venv around an editable checkout (#8308)

Daniel Han88c54835a74d
diff --git a/tests/studio/install/test_studio_deps_cli.py b/tests/studio/install/test_studio_deps_cli.py
index 7a42aacd382..dabda162509 100644
--- a/tests/studio/install/test_studio_deps_cli.py
+++ b/tests/studio/install/test_studio_deps_cli.py
@@ -277,3 +277,40 @@ def test_a_torn_tree_without_the_manifest_helper_is_incomplete(tmp_path, monkeyp
assert state["ok"] is False, state
assert state["reason"] == "studio_install_manifest_missing"
+
+
+# ── which prefix owns the manifest module ────────────────────────────
+
+
+def test_a_manifest_inside_a_venv_site_packages_is_owned_by_that_venv(tmp_path, deps):
+ """The wheel case: studio/ really is installed into that prefix."""
+ venv = tmp_path / "venv"
+ site_packages = venv / "lib" / "python3.11" / "site-packages"
+ (site_packages / "studio").mkdir(parents = True)
+ (venv / "pyvenv.cfg").write_text("home = /usr/bin\n", encoding = "utf-8")
+ module_path = site_packages / "studio" / "install_manifest.py"
+ shutil.copy(MANIFEST_PATH, module_path)
+
+ module = _load(module_path, "manifest_in_site_packages")
+
+ assert deps._venv_root_for_module(module) == venv
+
+
+def test_an_editable_checkout_is_not_owned_by_a_surrounding_venv(tmp_path, deps):
+ """`./install.sh --local` leaves studio/install_manifest.py in the repo. When the
+ clone happens to live inside some other virtualenv's directory, the first
+ pyvenv.cfg above it belongs to a venv the managed install has nothing to do
+ with. Claiming it there made verify-install walk that venv's site-packages and
+ report every managed dependency as missing, so `unsloth studio verify-install`
+ exited 1 on a healthy install and setup.sh could never take its fast path."""
+ surrounding = tmp_path / "unrelated_venv"
+ (surrounding / "lib" / "python3.11" / "site-packages").mkdir(parents = True)
+ (surrounding / "pyvenv.cfg").write_text("home = /usr/bin\n", encoding = "utf-8")
+ repo = surrounding / "repo"
+ (repo / "studio").mkdir(parents = True)
+ module_path = repo / "studio" / "install_manifest.py"
+ shutil.copy(MANIFEST_PATH, module_path)
+
+ module = _load(module_path, "manifest_in_editable_checkout")
+
+ assert deps._venv_root_for_module(module) is None
diff --git a/unsloth_cli/_studio_deps.py b/unsloth_cli/_studio_deps.py
index 186dd7f74bf..14e4af002a1 100644
--- a/unsloth_cli/_studio_deps.py
+++ b/unsloth_cli/_studio_deps.py
@@ -72,11 +72,26 @@ def load_install_manifest_module(extra_roots: Sequence[Path] = ()):
def _venv_root_for_module(module) -> Optional[Path]:
- """Prefix owning a manifest module, which may be a venv other than ours."""
- path = Path(getattr(module, "__file__", "") or "")
+ """Prefix owning a manifest module, which may be a venv other than ours.
+
+ A prefix only owns the module when the module actually lives in that
+ prefix's site-packages. An editable checkout (`./install.sh --local`) keeps
+ studio/install_manifest.py in the repo, so the first pyvenv.cfg above it is
+ whatever venv the clone happens to sit inside -- frequently an unrelated one
+ when the repo is cloned into a directory that is itself a virtualenv. Owning
+ it there would verify that venv's packages instead of the managed install and
+ report every managed dependency as missing.
+ """
+ path = _resolved(Path(getattr(module, "__file__", "") or ""))
for parent in path.parents:
if (parent / "pyvenv.cfg").is_file():
- return parent
+ for site_packages in _venv_site_packages(parent):
+ try:
+ path.relative_to(_resolved(site_packages))
+ except ValueError:
+ continue
+ return parent
+ return None
return None