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.

Copy uv constraint files to a space-free path on Windows volumes without 8.3 names (#14507)

Daniel Handeaf619d9da3
diff --git a/studio/backend/utils/uv_path_safety.py b/studio/backend/utils/uv_path_safety.py
index 3680f8d23d8..7d10d620c65 100644
--- a/studio/backend/utils/uv_path_safety.py
+++ b/studio/backend/utils/uv_path_safety.py
@@ -4,9 +4,9 @@
"""Hand uv a space-free `-c`/`--override`/`-r` file path (issue #6503).
uv splits `-c`/`--override` (and UV_OVERRIDE) on whitespace, so a path with a
-space truncates. Windows uses the 8.3 short form; POSIX uses a space-free temp
-path (removed at exit). Falls back to the original path on error. Shared by
-install_python_stack and utils.mlx_repair.
+space truncates. Windows tries the 8.3 short form first; otherwise (and on POSIX)
+a space-free temp path is used (removed at exit). Falls back to the original path
+on error. Shared by install_python_stack and utils.mlx_repair.
"""
from __future__ import annotations
@@ -28,30 +28,41 @@ def _cleanup_uv_safe_path_tmpdirs() -> None:
shutil.rmtree(_UV_SAFE_PATH_TMPDIRS.pop(), ignore_errors = True)
+def _windows_short_path(s: str) -> str | None:
+ """The 8.3 alias of ``s``, or None when the volume has none (common off the system drive)."""
+ try:
+ import ctypes
+ from ctypes import wintypes
+
+ get_short = ctypes.windll.kernel32.GetShortPathNameW
+ get_short.argtypes = [wintypes.LPCWSTR, wintypes.LPWSTR, wintypes.DWORD]
+ get_short.restype = wintypes.DWORD
+ buf = ctypes.create_unicode_buffer(32768)
+ rc = get_short(s, buf, 32768)
+ # A space-free alias can still fail to resolve (#11290).
+ if 0 < rc < 32768 and " " not in buf.value and os.path.exists(buf.value):
+ return buf.value
+ except Exception:
+ pass
+ return None
+
+
def uv_safe_path(path: object) -> str:
s = str(path)
if " " not in s:
return s
if IS_WINDOWS:
- try:
- import ctypes
- from ctypes import wintypes
-
- get_short = ctypes.windll.kernel32.GetShortPathNameW
- get_short.argtypes = [wintypes.LPCWSTR, wintypes.LPWSTR, wintypes.DWORD]
- get_short.restype = wintypes.DWORD
- buf = ctypes.create_unicode_buffer(32768)
- rc = get_short(s, buf, 32768)
- if 0 < rc < 32768 and " " not in buf.value:
- return buf.value
- except Exception:
- pass
- return s
+ short = _windows_short_path(s)
+ if short is not None:
+ return short
+ # No 8.3 name (often off on non-system volumes): copy, as install.ps1's Get-UvSafeRequirementsPath does.
tmp_dir = None
try:
if not os.path.isfile(s):
return s
tmp_dir = tempfile.mkdtemp(prefix = "unsloth_uv_")
+ if " " in tmp_dir and IS_WINDOWS:
+ tmp_dir = _windows_short_path(tmp_dir) or tmp_dir
if " " in tmp_dir:
shutil.rmtree(tmp_dir, ignore_errors = True)
return s
diff --git a/tests/python/test_install_python_stack.py b/tests/python/test_install_python_stack.py
index 92aa2c4d3f1..ede35af3828 100644
--- a/tests/python/test_install_python_stack.py
+++ b/tests/python/test_install_python_stack.py
@@ -365,6 +365,109 @@ class TestUvSafePathHardening:
assert Path(value).read_text() == "transformers>=4.57.6\n"
+class TestUvSafePathWindowsNo8dot3:
+ """Windows volumes without 8.3 names (#14487: D:\\Program Files) must still get a space-free path."""
+
+ def _spaced_constraints(self, tmp_path):
+ src = tmp_path / "Program Files" / "constraints.txt"
+ src.parent.mkdir(parents = True)
+ src.write_text("idna<4\n")
+ return src
+
+ def test_no_short_name_copies_to_a_space_free_path(self, tmp_path, monkeypatch):
+ from backend.utils import uv_path_safety as uvps
+
+ src = self._spaced_constraints(tmp_path)
+ monkeypatch.setattr(uvps, "IS_WINDOWS", True)
+ monkeypatch.setattr(uvps, "_windows_short_path", lambda s: None, raising = False)
+ out = uvps.uv_safe_path(str(src))
+
+ assert " " not in out, f"uv would split this -c path: {out!r}"
+ assert Path(out).read_text() == "idna<4\n"
+ assert any(out.startswith(d) for d in uvps._UV_SAFE_PATH_TMPDIRS)
+
+ def test_resolving_short_name_is_used_without_a_copy(self, tmp_path, monkeypatch):
+ from backend.utils import uv_path_safety as uvps
+
+ src = self._spaced_constraints(tmp_path)
+ monkeypatch.setattr(uvps, "IS_WINDOWS", True)
+ monkeypatch.setattr(uvps, "_windows_short_path", lambda s: "C:\\PROGRA~1\\constraints.txt")
+ before = list(uvps._UV_SAFE_PATH_TMPDIRS)
+
+ assert uvps.uv_safe_path(str(src)) == "C:\\PROGRA~1\\constraints.txt"
+ assert uvps._UV_SAFE_PATH_TMPDIRS == before
+
+ def test_spaced_temp_without_short_name_keeps_the_original(self, tmp_path, monkeypatch):
+ from backend.utils import uv_path_safety as uvps
+
+ src = self._spaced_constraints(tmp_path)
+ spaced_tmp = tmp_path / "First Last" / "Temp"
+ spaced_tmp.mkdir(parents = True)
+ monkeypatch.setattr(uvps, "IS_WINDOWS", True)
+ monkeypatch.setattr(uvps, "_windows_short_path", lambda s: None, raising = False)
+ monkeypatch.setattr(uvps.tempfile, "mkdtemp", lambda *a, **k: str(spaced_tmp))
+
+ assert uvps.uv_safe_path(str(src)) == str(src)
+
+ def test_uv_accepts_the_returned_constraint_path(self, tmp_path, monkeypatch):
+ """End to end against the real uv: the spaced path is refused, the returned one is read."""
+ import shutil
+ import subprocess
+ import sys
+
+ from backend.utils import uv_path_safety as uvps
+
+ if shutil.which("uv") is None:
+ pytest.skip("uv not available")
+ src = self._spaced_constraints(tmp_path)
+ monkeypatch.setattr(uvps, "IS_WINDOWS", True)
+ monkeypatch.setattr(uvps, "_windows_short_path", lambda s: None, raising = False)
+
+ def dry_run(constraint):
+ return subprocess.run(
+ [
+ "uv",
+ "pip",
+ "install",
+ "--dry-run",
+ "--offline",
+ "--python",
+ sys.executable,
+ "-c",
+ constraint,
+ "pip",
+ ],
+ capture_output = True,
+ text = True,
+ )
+
+ refused = dry_run(str(src))
+ assert "File not found" in refused.stderr, refused.stderr
+ accepted = dry_run(uvps.uv_safe_path(str(src)))
+ assert "File not found" not in accepted.stderr, accepted.stderr
+
+ @pytest.mark.skipif(not ips.IS_WINDOWS, reason = "real NTFS 8.3 names")
+ def test_real_directory_without_a_short_name(self, tmp_path):
+ """A real spaced directory whose 8.3 alias was stripped, as on a D: with 8.3 creation off."""
+ import subprocess
+
+ from backend.utils import uv_path_safety as uvps
+
+ src = self._spaced_constraints(tmp_path)
+ if uvps._windows_short_path(str(src)) is not None:
+ # Needs admin (SeRestorePrivilege), which CI runners have.
+ subprocess.run(
+ ["fsutil", "file", "setshortname", str(src.parent), ""], capture_output = True
+ )
+ if uvps._windows_short_path(str(src)) is not None:
+ pytest.skip("could not remove the 8.3 name on this volume")
+
+ out = uvps.uv_safe_path(str(src))
+
+ assert " " not in out, f"uv would split this -c path: {out!r}"
+ assert Path(out).read_text() == "idna<4\n"
+
+
class TestPinnedIndexClearsUvEnv:
"""Pinned installs must clear inherited UV_INDEX and UV_EXTRA_INDEX_URL, so the pinned index wins."""