Skip to content

armgit / Soup

Public Imported from GitHub
0

Fine-tune LLMs from one YAML. Layer streaming trains an 8B model on a 4 GB laptop GPU.

fix(layer-stream): show stripe path refusals as typed, not repr-doubled (#1611) (#1626)

vaputab661e1075a99
diff --git a/changelog.d/0.75.1/1626.fixed.md b/changelog.d/0.75.1/1626.fixed.md
new file mode 100644
index 00000000..51f729b9
--- /dev/null
+++ b/changelog.d/0.75.1/1626.fixed.md
@@ -0,0 +1 @@
+- **`SOUP_LAYER_STREAM_STRIPE_DIRS` refusals show the entry as typed (#1611).** Every refusal formatted the entry with `repr`, so each backslash of a Windows path was doubled, and copying the entry out of the message gave a spelling that does not work. Entries are now shown in single quotes with single backslashes. Control characters are still escaped as `\xNN`, so they never reach the terminal raw. The same applies to the Windows owner-only folder errors and the disk pre-flight message (#1611 by @vaputa in #1626).
diff --git a/src/soup_cli/trainer/stream_setup.py b/src/soup_cli/trainer/stream_setup.py
index 1a07d82a..25f907ed 100644
--- a/src/soup_cli/trainer/stream_setup.py
+++ b/src/soup_cli/trainer/stream_setup.py
@@ -30,6 +30,7 @@ from rich.console import Console
from rich.panel import Panel
from soup_cli.utils.config_bounds import DEFAULT_STREAM_READ_AHEAD, MAX_STREAM_READ_AHEAD
+from soup_cli.utils.paths import quote_path
from soup_cli.utils.stripe_roots import ReadAheadDecision, effective_read_ahead
console = Console()
@@ -294,7 +295,7 @@ def _existing_disk_anchor(path: str) -> str:
while not os.path.exists(anchor):
parent = os.path.dirname(anchor)
if parent == anchor:
- raise OSError(f"cannot locate an existing filesystem ancestor for {path!r}")
+ raise OSError(f"cannot locate an existing filesystem ancestor for {quote_path(path)}")
anchor = parent
return anchor
diff --git a/src/soup_cli/utils/owner_only_dir.py b/src/soup_cli/utils/owner_only_dir.py
index a410b05d..821a54a3 100644
--- a/src/soup_cli/utils/owner_only_dir.py
+++ b/src/soup_cli/utils/owner_only_dir.py
@@ -28,6 +28,8 @@ import os
import stat
from typing import Any, List
+from soup_cli.utils.paths import quote_path
+
#: The DACL on Windows: this account and SYSTEM, full control, inherited by files and folders.
_SYSTEM_SID = "S-1-5-18"
_ADMINISTRATORS_SID = "S-1-5-32-544"
@@ -291,7 +293,10 @@ def _win_create_dir(path: str) -> bool:
code = api.ctypes.get_last_error()
if code == _ERROR_ALREADY_EXISTS:
return False
- raise OSError(code, f"CreateDirectoryW({path!r}) failed: {api.ctypes.FormatError(code)}")
+ raise OSError(
+ code,
+ f"CreateDirectoryW({quote_path(path)}) failed: {api.ctypes.FormatError(code)}",
+ )
def _win_owner_sid(path: str) -> str:
@@ -304,7 +309,10 @@ def _win_owner_sid(path: str) -> str:
ctypes.byref(owner), None, None, None, ctypes.byref(descriptor),
)
if code:
- raise OSError(code, f"GetNamedSecurityInfoW({path!r}) failed: {ctypes.FormatError(code)}")
+ raise OSError(
+ code,
+ f"GetNamedSecurityInfoW({quote_path(path)}) failed: {ctypes.FormatError(code)}",
+ )
try:
return _win_sid_string(owner)
finally:
@@ -328,7 +336,10 @@ def _win_protect(path: str) -> None:
None, None, dacl, None,
)
if code:
- raise OSError(code, f"SetNamedSecurityInfoW({path!r}) failed: {ctypes.FormatError(code)}")
+ raise OSError(
+ code,
+ f"SetNamedSecurityInfoW({quote_path(path)}) failed: {ctypes.FormatError(code)}",
+ )
def _win_dacl_sddl(path: str) -> str:
@@ -341,7 +352,10 @@ def _win_dacl_sddl(path: str) -> str:
None, None, None, None, ctypes.byref(descriptor),
)
if code:
- raise OSError(code, f"GetNamedSecurityInfoW({path!r}) failed: {ctypes.FormatError(code)}")
+ raise OSError(
+ code,
+ f"GetNamedSecurityInfoW({quote_path(path)}) failed: {ctypes.FormatError(code)}",
+ )
try:
text = wintypes.LPWSTR()
if not api.advapi32.ConvertSecurityDescriptorToStringSecurityDescriptorW(
diff --git a/src/soup_cli/utils/paths.py b/src/soup_cli/utils/paths.py
index 8ae2519c..51f936fa 100644
--- a/src/soup_cli/utils/paths.py
+++ b/src/soup_cli/utils/paths.py
@@ -21,6 +21,23 @@ from pathlib import Path
from typing import Iterable, Optional, Union
+def quote_path(path: str) -> str:
+ """Quote a path for an error message as it was typed, not as ``repr`` renders it.
+
+ ``repr`` doubles every backslash of a Windows path, and an operator who copies the
+ entry out of the message copies the doubled, non-working spelling back into the
+ variable (#1611). The path is shown inside single quotes so leading and trailing
+ spaces stay visible, backslashes stay single, and the control characters the
+ validation rules refuse (C0, DEL, C1) are escaped as ``\\xNN`` so they never reach
+ the terminal as raw bytes.
+ """
+ escaped = "".join(
+ f"\\x{ord(ch):02x}" if (ord(ch) < 0x20 or 0x7F <= ord(ch) <= 0x9F) else ch
+ for ch in path
+ )
+ return f"'{escaped}'"
+
+
def is_under(path: Union[str, Path], base: Union[str, Path]) -> bool:
"""Return True when ``path`` resolves inside ``base``."""
try:
diff --git a/src/soup_cli/utils/stripe_roots.py b/src/soup_cli/utils/stripe_roots.py
index b86ab4f8..194aea72 100644
--- a/src/soup_cli/utils/stripe_roots.py
+++ b/src/soup_cli/utils/stripe_roots.py
@@ -23,7 +23,7 @@ from soup_cli.utils.config_bounds import (
MAX_STREAM_READ_AHEAD,
MIN_STREAM_READ_AHEAD,
)
-from soup_cli.utils.paths import is_under
+from soup_cli.utils.paths import is_under, quote_path
STRIPE_DIRS_ENV = "SOUP_LAYER_STREAM_STRIPE_DIRS"
@@ -123,7 +123,7 @@ def _nearest_existing(path: str) -> str:
while not os.path.exists(anchor):
parent = os.path.dirname(anchor)
if parent == anchor:
- raise StripeRootError(f"cannot find an existing folder above {path!r}")
+ raise StripeRootError(f"cannot find an existing folder above {quote_path(path)}")
anchor = parent
return anchor
@@ -185,7 +185,7 @@ def validate_stripe_root(entry: str, *, primary_root: str, accepted: Sequence[st
"""
resolved, reason = check_stripe_root(entry, primary_root=primary_root, accepted=accepted)
if reason is not None:
- raise StripeRootError(f"{STRIPE_DIRS_ENV} entry {entry!r}: {reason}")
+ raise StripeRootError(f"{STRIPE_DIRS_ENV} entry {quote_path(entry)}: {reason}")
assert resolved is not None
return resolved
@@ -266,7 +266,7 @@ def validate_early_stripe_roots(
accepted: List[str] = []
for entry, resolved, reason in iter_early_stripe_roots(primary_root, entries):
if reason is not None:
- raise StripeRootError(f"{STRIPE_DIRS_ENV} entry {entry!r}: {reason}")
+ raise StripeRootError(f"{STRIPE_DIRS_ENV} entry {quote_path(entry)}: {reason}")
assert resolved is not None
accepted.append(resolved)
return tuple(accepted)
@@ -293,9 +293,9 @@ def resolve_stripe_roots(
kind = disk_kind(resolved)
if kind != "nvme":
raise StripeRootError(
- f"{STRIPE_DIRS_ENV} entry {entry!r}: the disk tier streams from NVMe only, and "
- f"this volume classifies as {kind!r}. If the probe is wrong, "
- f"training.stream_disk_kind overrides it."
+ f"{STRIPE_DIRS_ENV} entry {quote_path(entry)}: the disk tier streams "
+ f"from NVMe only, and this volume classifies as {kind!r}. If the probe "
+ f"is wrong, training.stream_disk_kind overrides it."
)
return accepted
diff --git a/tests/test_disk_tier_stripe_roots.py b/tests/test_disk_tier_stripe_roots.py
index 378d8963..178a6fd5 100644
--- a/tests/test_disk_tier_stripe_roots.py
+++ b/tests/test_disk_tier_stripe_roots.py
@@ -6,6 +6,7 @@ import sys
import pytest
+from soup_cli.utils.paths import quote_path
from soup_cli.utils.stripe_roots import (
MAX_STRIPE_DIRS,
STRIPE_DIRS_ENV,
@@ -184,6 +185,106 @@ class TestPlacement:
layer_roots_for(3, 0)
+class TestQuotePath:
+ """#1611 — a path in a refusal message reads as it was typed."""
+
+ @pytest.mark.parametrize("typed", [
+ "D:\\folder\\sub", # a drive-letter path
+ "\\\\server\\share\\dir", # a UNC path
+ "my dir", # a space survives, quoted
+ "trailing\\", # a trailing separator
+ "/posix/path", # a POSIX path comes out unchanged
+ "relative\\path", # a relative path with backslashes
+ ])
+ def test_shown_as_typed_inside_single_quotes(self, typed):
+ assert quote_path(typed) == f"'{typed}'"
+
+ @pytest.mark.parametrize("code", [0x00, 0x07, 0x1B, 0x7F, 0x9B, 0x9F])
+ def test_control_characters_are_escaped_not_raw(self, code):
+ assert quote_path(f"a{chr(code)}b") == f"'a\\x{code:02x}b'"
+
+
+class TestRefusalSpellings:
+ """#1611 — every refusal names the entry as typed, not in repr's doubled form."""
+
+ def test_a_backslash_entry_is_not_doubled(self, layout):
+ primary, _ = layout
+ with pytest.raises(StripeRootError) as err:
+ validate_stripe_root("folder\\sub", primary_root=primary)
+ message = str(err.value)
+ assert "'folder\\sub'" in message
+ assert "'folder\\\\sub'" not in message
+
+ @pytest.mark.parametrize("typed", ["folder\\sub", "\\\\server\\share\\dir"])
+ def test_the_relative_path_refusal_names_the_entry_as_typed(self, layout, typed):
+ primary, _ = layout
+ with pytest.raises(StripeRootError) as err:
+ validate_stripe_root(typed, primary_root=primary)
+ assert f"'{typed}'" in str(err.value)
+
+ @pytest.mark.parametrize("code", [0x1B, 0x7F, 0x9B])
+ def test_control_characters_are_shown_as_escapes(self, layout, code):
+ primary, _ = layout
+ entry = f"stripe{chr(code)}"
+ with pytest.raises(StripeRootError) as err:
+ validate_stripe_root(entry, primary_root=primary)
+ message = str(err.value)
+ assert chr(code) not in message, "a raw control character reached the message"
+ assert f"\\x{code:02x}" in message, "the message does not show which character it was"
+
+ @pytest.mark.skipif(os.name != "nt", reason="needs a drive-letter spelling")
+ def test_a_missing_drive_letter_folder_is_shown_as_typed(self, tmp_path):
+ primary = tmp_path / "cache"
+ primary.mkdir()
+ with pytest.raises(StripeRootError) as err:
+ validate_stripe_root("D:\\does-not-exist-xyz", primary_root=str(primary))
+ message = str(err.value)
+ assert "'D:\\does-not-exist-xyz'" in message
+ assert "'D:\\\\does-not-exist-xyz'" not in message
+
+ @pytest.mark.skipif(os.name != "nt", reason="needs two folders on one drive")
+ def test_the_same_volume_refusal_names_the_entry_as_typed(self, layout):
+ primary, stripe = layout
+ with pytest.raises(StripeRootError) as err:
+ resolve_stripe_roots(primary, disk_kind=lambda path: "nvme", environ=_env(stripe))
+ message = str(err.value)
+ assert f"'{stripe}'" in message
+ assert repr(stripe) not in message
+
+ def test_the_nvme_refusal_names_the_entry_as_typed(self, layout, monkeypatch):
+ import soup_cli.utils.stripe_roots as mod
+
+ primary, stripe = layout
+ ids = {os.path.realpath(primary): 1, os.path.realpath(stripe): 2}
+ monkeypatch.setattr(mod, "volume_of", lambda path: ids[os.path.realpath(path)])
+ with pytest.raises(StripeRootError) as err:
+ resolve_stripe_roots(
+ primary, disk_kind=lambda path: "ssd", environ=_env(stripe),
+ )
+ # A POSIX path has no spelling for repr to change, so as-typed is all
+ # there is to pin here; the doubled form is covered on Windows above.
+ assert f"'{stripe}'" in str(err.value)
+
+
+def test_the_other_message_sites_use_quote_path():
+ """#1611 — the Windows API refusals and the disk pre-flight quote paths too."""
+ import pathlib
+
+ import soup_cli
+
+ root = pathlib.Path(soup_cli.__file__).parent
+ owner = (root / "utils" / "owner_only_dir.py").read_text(encoding="utf-8")
+ setup = (root / "trainer" / "stream_setup.py").read_text(encoding="utf-8")
+ roots = (root / "utils" / "stripe_roots.py").read_text(encoding="utf-8")
+ assert "path!r" not in owner, "owner_only_dir still renders a path with repr"
+ assert "path!r" not in setup, "stream_setup still renders a path with repr"
+ assert "entry!r" not in roots and "path!r" not in roots, (
+ "stripe_roots still renders an entry or path with repr"
+ )
+ assert owner.count("quote_path(path)") == 4
+ assert "quote_path(path)" in setup
+
+
def test_the_module_does_not_import_torch():
code = "import sys, soup_cli.utils.stripe_roots; sys.exit(int('torch' in sys.modules))"
assert subprocess.run([sys.executable, "-c", code], check=False).returncode == 0