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
Next Next commit
Repair hint: start uv config discovery from UV_WORKING_DIR as install…
….ps1 does

install.ps1's mirror check walks up from the working-directory override
even without UV_PROJECT and resolves UV_PROJECT and UV_CONFIG_FILE
against it. Do the same, so a mirror in that directory's uv.toml is seen
and the hint is not shown when Repair cannot reach the managed torch.

[skip ci]
  • Loading branch information
danielhanchen committed Nov 27, 2026
commit 84ee1573566b1485ca20e367ab83198074c2e3d2
17 changes: 17 additions & 0 deletions studio/backend/tests/test_windows_repair_recommendation.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,23 @@ def test_an_explicit_uv_project_config_closes_the_route(monkeypatch, tmp_path, p
assert wr._managed_route_host({"UV_PROJECT": str(project / "sub"), "UV_NO_CONFIG": "1"}) is True


@pytest.mark.parametrize("name", ["UV_WORKING_DIR", "UV_WORKING_DIRECTORY"])
def test_a_working_directory_override_starts_discovery(monkeypatch, tmp_path, name):
# install.ps1's Test-MirrorConfigured walks up from the working-directory override even without
# UV_PROJECT, and resolves UV_PROJECT and UV_CONFIG_FILE against it.
monkeypatch.setattr(wr._platform, "machine", lambda: "AMD64")
work = tmp_path / "work"
(work / "proj").mkdir(parents = True)
(work / "uv.toml").write_text("index-url = 'https://mirror.example/simple'\n", encoding = "utf-8")
assert wr._managed_route_host({name: str(work)}) is False
assert wr._managed_route_host({name: str(work), "UV_PROJECT": "proj"}) is False
assert wr._managed_route_host({name: str(work), "UV_NO_CONFIG": "1"}) is True
(work / "clean.toml").write_text("cache-dir = 'D:/uv'\n", encoding = "utf-8")
assert wr._managed_route_host({name: str(work), "UV_CONFIG_FILE": "clean.toml"}) is True
(work / "mirror.toml").write_text("[[index]]\nurl = 'x'\n", encoding = "utf-8")
assert wr._managed_route_host({name: str(work), "UV_CONFIG_FILE": "mirror.toml"}) 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
16 changes: 9 additions & 7 deletions studio/backend/utils/hardware/windows_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,13 @@ 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 UV_PROJECT names. Without UV_PROJECT the installer walks its
own working directory, unknown here."""
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."""
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()
if environ.get("UV_CONFIG_FILE"):
return [environ["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:
return []
files = []
Expand All @@ -116,10 +119,9 @@ 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 UV_PROJECT names the project the installer's discovery walks up from.
if environ.get("UV_PROJECT"):
base = environ.get("UV_WORKING_DIR") or environ.get("UV_WORKING_DIRECTORY") or os.getcwd()
directory = os.path.abspath(os.path.join(base, environ["UV_PROJECT"]))
# An explicit working directory or project names where the installer's discovery walks up from.
if work_dir or environ.get("UV_PROJECT"):
directory = os.path.abspath(os.path.join(base, environ.get("UV_PROJECT") or ""))

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 Check the desktop installer's default directory for uv configs

On an otherwise eligible Windows RTX 50-series installation with a mirror-configured %USERPROFILE%\.unsloth\uv.toml and no UV_PROJECT or working-directory override, this skips project discovery and recommends Repair even though Repair cannot take the managed 2.13 route. The desktop installer explicitly starts in the profile's .unsloth directory (studio/src-tauri/src/install.rs:627–642, process.rs:1876–1888), and install.ps1's Test-MirrorConfigured walks from that directory even without overrides, causing Test-PypiUnslothAdmitsTorch to reject the upgrade. Include discovery from the desktop installer's default working directory so users are not repeatedly sent through a reinstall that cannot resolve the recommendation.

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.

Fixed in 5e4e149: with USERPROFILE known, discovery starts from %USERPROFILE%.unsloth (the directory Desktop launches install.ps1 in) and walks up as Test-MirrorConfigured does; UV_WORKING_DIR and UV_PROJECT resolve against it. New test fails on 84ee157.

while directory:
if os.path.isfile(os.path.join(directory, "uv.toml")):
files.append(os.path.join(directory, "uv.toml"))
Expand Down