Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Repair hint: walk uv config discovery from Desktop's installer directory
Desktop runs install.ps1 from %USERPROFILE%\.unsloth, and its mirror
check walks up from there even with no uv override set. Start there too,
so a mirror in that tree keeps the hint off when Repair cannot reach the
managed torch.
  • Loading branch information
danielhanchen committed Nov 27, 2026
commit 5e4e149351d3d050fbac16449141ba683c2957bc
19 changes: 19 additions & 0 deletions studio/backend/tests/test_windows_repair_recommendation.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,25 @@ def test_a_working_directory_override_starts_discovery(monkeypatch, tmp_path, na
assert wr._managed_route_host({name: str(work), "UV_CONFIG_FILE": "mirror.toml"}) is False


def test_discovery_walks_from_the_desktop_installer_directory(monkeypatch, tmp_path):
# Desktop starts install.ps1 in %USERPROFILE%\\.unsloth, and its discovery walks up from there
# with no override set.
monkeypatch.setattr(wr._platform, "machine", lambda: "AMD64")
profile = {"USERPROFILE": str(tmp_path)}
(tmp_path / ".unsloth" / "sub").mkdir(parents = True)
assert wr._managed_route_host(profile) is True
mirror = "index-url = 'https://mirror.example/simple'\n"
(tmp_path / ".unsloth" / "uv.toml").write_text(mirror, encoding = "utf-8")
assert wr._managed_route_host(profile) is False
assert wr._managed_route_host({**profile, "UV_NO_CONFIG": "1"}) is True
# A relative working directory resolves against it too.
assert wr._managed_route_host({**profile, "UV_WORKING_DIR": "sub"}) is False
(tmp_path / ".unsloth" / "uv.toml").unlink()
# Found walking up, in the profile itself.
(tmp_path / "uv.toml").write_text(mirror, encoding = "utf-8")
assert wr._managed_route_host(profile) is False


def test_the_mirror_gate_matches_install_ps1():
install = (Path(__file__).resolve().parents[3] / "install.ps1").read_text(encoding = "utf-8")
body = re.search(r"function Test-PypiUnslothAdmitsTorch \{.*?\n \}", install, re.S).group(0)
Expand Down
15 changes: 9 additions & 6 deletions studio/backend/utils/hardware/windows_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,14 @@ def _index_override_leaf(environ = os.environ) -> Optional[str]:
def _uv_config_files(environ) -> list[str]:
"""The uv config files install.ps1's Test-MirrorConfigured reads, in its precedence: UV_CONFIG_FILE alone
(even with UV_NO_CONFIG), else none under UV_NO_CONFIG, else the user file plus the system one unless
UV_NO_SYSTEM_CONFIG, plus the project found walking up from UV_WORKING_DIR / UV_PROJECT. Relative paths
resolve against the working-directory override, as uv's --directory does. With neither override the
installer walks its own working directory, unknown here, so no project file is read."""
UV_NO_SYSTEM_CONFIG, plus the project found walking up from the installer's working directory. Desktop
runs install.ps1 from %USERPROFILE%\\.unsloth; UV_WORKING_DIR and UV_PROJECT move the walk, and relative
paths resolve against the result, as uv's --directory does. Without a profile and an override the
installer's directory is unknown here, so no project file is read."""
home = environ.get("USERPROFILE")
installer_cwd = os.path.join(home, ".unsloth") if home else None
work_dir = environ.get("UV_WORKING_DIR") or environ.get("UV_WORKING_DIRECTORY")
base = os.path.abspath(os.path.join(os.getcwd(), work_dir)) if work_dir else os.getcwd()
base = os.path.abspath(os.path.join(installer_cwd or os.getcwd(), work_dir or ""))
if environ.get("UV_CONFIG_FILE"):
return [os.path.abspath(os.path.join(base, environ["UV_CONFIG_FILE"]))]
if str(environ.get("UV_NO_CONFIG", "")).strip().lower() in _UV_TRUE:
Expand All @@ -119,8 +122,8 @@ def _uv_config_files(environ) -> list[str]:
and str(environ.get("UV_NO_SYSTEM_CONFIG", "")).strip().lower() not in _UV_TRUE
):
files.append(os.path.join(environ["ProgramData"], "uv", "uv.toml"))
# An explicit working directory or project names where the installer's discovery walks up from.
if work_dir or environ.get("UV_PROJECT"):
# The installer's own directory, or an explicit one or project, is where its discovery walks up from.
if installer_cwd or work_dir or environ.get("UV_PROJECT"):
directory = os.path.abspath(os.path.join(base, environ.get("UV_PROJECT") or ""))
while directory:
if os.path.isfile(os.path.join(directory, "uv.toml")):
Expand Down
Loading