Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
[Other] --data-dir never moves the model library without a choice
Niko12219d2cb4f6d223
diff --git a/docs/AI_SETUP.md b/docs/AI_SETUP.mdindex 3f8e9c988..f1bb0aba9 100644--- a/docs/AI_SETUP.md+++ b/docs/AI_SETUP.md@@ -105,7 +105,7 @@ The flags (all of them, with examples: `strata launch --help`):| `--model NAME` | the size: `q2_0`, `iq2_xs`, `iq3_xxs`, `iq3_s`, `iq1_m`, `ud-iq4_xs`, `ud-q4_k_xl`, ... (the error message for a wrong name lists them) || `--family NAME` | the model version when several have that size: `qwen`, `swift`, `coder`, `unsloth` || `--model-path PATH` | files the user already has: a folder of shards or one `.gguf` file |-| `--data-dir DIR` | where the 70-120 GB of model files go |+| `--data-dir DIR` | where new model files go. Models you already have stay where they are and stay usable; add `--move-data` to move them into DIR || `--context SIZE` | `32k`, `64k`, `128k`, `256k` or a number of tokens || `--vision off\|on\|gpu\|cpu` | read pictures. On by default when the model can read them: the reader runs on the CPU for a card under 24 GB and on the GPU from 24 GB, on NVIDIA and AMD cards. `off` turns it off || `--parallel N` | requests answered at the same time, 1 to 8 (default: fit to the card) |@@ -228,7 +228,7 @@ The flags (all of them: `START-HERE.bat --help`):| `--vision yes\|no\|gpu\|cpu` | read pictures. Pass `yes` to get the best reader for the card (the CPU under 24 GB, the GPU from 24 GB, any make); `no` turns them off || `--gpu N` / `--gpus 0,1` / `--gpus all` | one card, or several sharing the model (default: the card with the most VRAM) || `--backend cuda\|hip` | NVIDIA or AMD engine; chosen by itself on a PC with only one kind of card |-| `--data-dir PATH` | where the 70-120 GB of model files go |+| `--data-dir PATH` | where new model files go. Nothing is moved unless you add `--move-data`; the saved default folder changes only with `--move-data` or `--set-default-data-dir` || `--port N` | the server port (default 8080) || `--host H --api-key K` | listen beyond this PC; only together with a key || `--no-start` | install only, do not start the server |diff --git a/metal/setup_mac.py b/metal/setup_mac.pyindex 1d4717ade..a937b6a28 100644--- a/metal/setup_mac.py+++ b/metal/setup_mac.py@@ -332,6 +332,8 @@ def main(argv=None) -> int:ap.add_argument("--draft-vocab", choices=list(S.DRAFT_VOCABS))ap.add_argument("--no-browser", dest="browser", action="store_false", default=None)ap.add_argument("--data-dir")+ ap.add_argument("--move-data", action="store_true", help="with --data-dir: move the model files already here into the new folder")+ ap.add_argument("--set-default-data-dir", action="store_true", help="with --data-dir: remember the new folder without moving anything")ap.add_argument("--models-dir")ap.add_argument("--gguf-dir")ap.add_argument("--yes", action="store_true")@@ -354,7 +356,7 @@ def main(argv=None) -> int:if a.source:os.environ["STRATA_SOURCE"] = a.sourceS.say("Strata on a Mac (Apple Silicon, Metal)")- data, elsewhere = S.data_folder(a.data_dir)+ data, elsewhere = S.data_folder_for(a)roots = [data, *elsewhere]models_root = Path(a.models_dir) if a.models_dir else data / "models"diff --git a/setup.py b/setup.pyindex c7a2d32aa..d6fa76861 100644--- a/setup.py+++ b/setup.py@@ -5351,12 +5351,39 @@ def repoint_config(cfg_file: Path, old: Path, new: Path) -> None:write_config(cfg_file, new_cfg)-def data_folder(requested: str | None) -> tuple:- """(the data folder, folders on other drives that still hold model files). Moves the model files of this folder- and of earlier Strata folders on the same drive into the data folder, and points their configs there."""+def library_size_gb(folder: Path) -> float:+ """The GB of model files (models, packs, mtp) in a data folder."""+ total = 0+ for d in DATA_ITEMS:+ for root, _dirs, files in os.walk(folder / d):+ for f in files:+ try:+ total += os.path.getsize(os.path.join(root, f))+ except OSError:+ pass+ return total / 1e9+++def same_folder(a: Path, b: Path) -> bool:+ """The same folder, however it is spelled (a different case, a short 8.3 name, a link)."""+ try:+ return os.path.samefile(a, b)+ except OSError:+ return os.path.normcase(os.path.abspath(a)) == os.path.normcase(os.path.abspath(b))+++def data_folder(requested: str | None, move: bool = False, yes: bool = True, set_default: bool = False) -> tuple:+ """(the data folder, folders that still hold model files and are used where they are).++ A --data-dir that names a NEW folder never moves anything by itself. When model files already exist elsewhere,+ the person is asked: keep them where they are and use the new folder for new downloads (the answer with --yes+ or when nobody can answer), or move them in (`move`, --move-data, or the answer "move"). Only a move, or+ --set-default-data-dir, or a PC with no model files anywhere, changes the remembered data folder. Without+ --data-dir the model files of this folder and of earlier Strata folders on the same drive are gathered into the+ remembered data folder and their configs point there (that is the data folder's own job)."""settings = load_settings()- dest = Path(requested).expanduser().resolve() if requested else \- Path(settings["data_dir"]) if settings.get("data_dir") else home().parent / "Strata-data"+ remembered = Path(settings["data_dir"]) if settings.get("data_dir") else home().parent / "Strata-data"+ dest = Path(requested).expanduser().resolve() if requested else rememberedtry:dest.mkdir(parents=True, exist_ok=True)except OSError as e: # e.g. no write access next to the Strata folder@@ -5366,16 +5393,41 @@ def data_folder(requested: str | None) -> tuple:# #198: the data folder remembered before (a --data-dir to a new place) is a source too, and so is a Strata-data# folder nested in any of them (an install that kept its models one level down)sources = [home(), *other_installs(settings)]- if settings.get("data_dir") and Path(settings["data_dir"]) != dest:+ if settings.get("data_dir") and not same_folder(Path(settings["data_dir"]), dest):sources.append(Path(settings["data_dir"]))- sources += [f / "Strata-data" for f in list(sources) if (f / "Strata-data") != dest]+ sources += [f / "Strata-data" for f in list(sources) if not same_folder(f / "Strata-data", dest)]+ if requested and not same_folder(dest, remembered):+ sources.append(remembered)+ # a different folder than the one in use: nothing is moved unless the person says so+ held = []+ for folder in dict.fromkeys(sources):+ if not same_folder(folder, dest) and has_data(folder) and not any(same_folder(folder, h) for h in held):+ held.append(folder)+ movable = [f for f in held if same_drive(f, dest)]+ if movable and not move and not yes:+ gb = sum(library_size_gb(f) for f in movable)+ say()+ size = f"{gb:.0f} GB" if gb >= 10 else f"{gb:.1f} GB"+ say(f" Your models are in {', '.join(str(f) for f in movable)} ({size}).")+ say(f" keep) leave them there and use {dest} only for new downloads")+ say(f" move) move your {size} of models to {dest}")+ move = ask(f"Move your {size} of models to the new folder, or use the new folder only for new downloads?",+ ["keep", "move"], "keep", False) == "move"+ if held and not move:+ for folder in held:+ say(f" your model files stay in {folder}; {dest} is used for new downloads")+ if set_default:+ save_settings({**settings, "data_dir": str(dest)})+ return dest, held+ if not held:+ move = True # nothing to lose track of: the new folder becomes the defaultseen = set()for folder in sources:key = os.path.normcase(str(folder))if key in seen:continueseen.add(key)- if folder == dest or not has_data(folder):+ if same_folder(folder, dest) or not has_data(folder):continueif not same_drive(folder, dest):elsewhere.append(folder) # another drive: used where it is (no 70 GB copy)@@ -5405,6 +5457,12 @@ def data_folder(requested: str | None) -> tuple:return dest, elsewhere+def data_folder_for(a) -> tuple:+ """data_folder() with the answers on the command line (--data-dir, --move-data, --yes, --set-default-data-dir)."""+ return data_folder(getattr(a, "data_dir", None), getattr(a, "move_data", False), bool(getattr(a, "yes", True)),+ getattr(a, "set_default_data_dir", False))++def data_folder_in_place() -> tuple:"""(the data folder, []) for a start: where settings.json says the model files are, or the default place. Readsthe settings and nothing else: no folder is created, nothing is moved or copied, no setting is saved. The run@@ -6827,7 +6885,7 @@ def install_own_path(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopteok(f"vision encoder: {mmproj}")step(6, "preparing the model for Strata")- data, _ = data_folder(a.data_dir)+ data, _ = data_folder_for(a)pack = data / "packs" / tag.lower() # only the tokenizer: the engine reads the GGUF itselfif not (pack / "tokenizer" / "vocab.json").exists():run([sys.executable, str(ROOT / "tools" / "strata_tokenizer.py"), "--gguf", str(gguf), "--out", str(pack)],@@ -6960,7 +7018,7 @@ def mac_control_setup(a) -> int:problems = MF.mac_problems(info, need_compiler=False) # the app compiles nothing: no Command Line Tools neededfor p in problems:warn(p)- data, elsewhere = data_folder(a.data_dir)+ data, elsewhere = data_folder_for(a)roots = [data, *elsewhere]models_root = Path(a.models_dir) if a.models_dir else data / "models"free = free_gb(data if data.exists() else home())@@ -7148,6 +7206,11 @@ def main() -> int:help="open the chat page again when the model is ready (the default; undoes --no-browser)")ap.add_argument("--data-dir", help="where the model files go (~70-120 GB): default Strata-data next to this folder, ""remembered for every Strata folder on this PC")+ ap.add_argument("--move-data", action="store_true",+ help="with --data-dir: move the model files already on this PC into the new folder (without it nothing "+ "is moved: the old files stay usable and the new folder gets the new downloads)")+ ap.add_argument("--set-default-data-dir", action="store_true",+ help="with --data-dir: remember the new folder as the data folder without moving anything")ap.add_argument("--models-dir", help="where the GGUF files go (default: <data folder>/models)")ap.add_argument("--gguf-dir", help="use GGUF files you already have (a folder with every shard: ""<name>-00001-of-0000N.gguf ... -0000N-of-0000N.gguf)")@@ -7244,7 +7307,7 @@ def main() -> int:plain_start = bool(have) and not (a.setup or a.model or a.family or a.check or a.no_start or a.updateor a.calibrate or a.rollback_engine or a.data_dir)models_dir_given = a.models_dir is not None- data, elsewhere = data_folder_in_place() if plain_start else data_folder(a.data_dir) # the model files+ data, elsewhere = data_folder_in_place() if plain_start else data_folder_for(a) # the model filesroots = [data, *elsewhere]if a.models_dir is None:a.models_dir = str(data / "models")@@ -7327,7 +7390,7 @@ def main() -> int:return start(have[pick - 1], a.port, run_gpu, yes=a.yes, layer_split=a.layer_split,keep={"host": a.host, "api_key": a.api_key, "draft_vocab": a.draft_vocab,"vram_reserve_mib": a.vram_reserve_mib, "open_browser": a.browser})- data, elsewhere = data_folder(a.data_dir) # "install another model": now the model files are gathered+ data, elsewhere = data_folder_for(a) # "install another model": now the model files are gatheredroots = [data, *elsewhere]if not models_dir_given:a.models_dir = str(data / "models")diff --git a/strata_cli/launch/app.py b/strata_cli/launch/app.pyindex 51b0e1463..b0a8500a4 100644--- a/strata_cli/launch/app.py+++ b/strata_cli/launch/app.py@@ -42,6 +42,7 @@ class Ctx:settings: S.LaunchSettingsglyphs: Glyphs = field(default_factory=Glyphs)feed: str | None = None+ move_data: bool = Falsenotes: list[str] = field(default_factory=list)start_own_files: bool = Falsepicked_in_list: bool = False@@ -261,7 +262,8 @@ class LaunchApp(App):def run_launch(self, confirmed: bool = False) -> None:s = self.ctx.settingsself.cancel = threading.Event()- self.runner = Runner(s, catalog=self.ctx.catalog, emit=self._emit, cancel=self.cancel, feed=self.ctx.feed, confirm=self._ask_from_run)+ self.runner = Runner(s, catalog=self.ctx.catalog, emit=self._emit, cancel=self.cancel, feed=self.ctx.feed, confirm=self._ask_from_run,+ move_data=self.ctx.move_data)gb = getattr(self.runner, "download_gb", lambda: 0.0)() if not confirmed else 0.0if gb >= 1.0:free = self.ctx.catalog.disk_free(s.data_dir or self.ctx.catalog.data_dir())@@ -402,7 +404,7 @@ def run_monitor(info: dict, *, keep_default: bool = True, color: str = "auto") -def run_tui(settings: S.LaunchSettings | None, *, catalog: Catalog | None = None, feed: str | None = None, auto_run: bool = False,- save: bool = False, open_page: bool = False) -> int:+ save: bool = False, open_page: bool = False, move_data: bool = False) -> int:"""Open the launch screens. `settings` given and `auto_run`: skip the questions and go straight to the run."""catalog = catalog or Catalog()print("Looking at this computer…", flush=True)@@ -417,7 +419,7 @@ def run_tui(settings: S.LaunchSettings | None, *, catalog: Catalog | None = Nones.name = f"{s.model or 'model'} {S.context_label(s.context)}"if save:store.save(s, s.name)- ctx = Ctx(catalog=catalog, computer=computer, rows=rows, settings=s, glyphs=Glyphs(), feed=feed)+ ctx = Ctx(catalog=catalog, computer=computer, rows=rows, settings=s, glyphs=Glyphs(), feed=feed, move_data=move_data)app = LaunchApp(ctx, auto_run=auto_run)result = app.run()if getattr(app, "return_code", 0) not in (0, None) or getattr(app, "_exception", None) is not None:diff --git a/strata_cli/launch/cmd.py b/strata_cli/launch/cmd.pyindex fba341a87..a36b94b28 100644--- a/strata_cli/launch/cmd.py+++ b/strata_cli/launch/cmd.py@@ -82,6 +82,9 @@ def add_parsers(sp: argparse._SubParsersAction) -> list[argparse.ArgumentParser]g.add_argument("--family", metavar="NAME", help="the model family when a size is offered by several (qwen, swift, coder, ...)")g.add_argument("--model-path", metavar="PATH", help="use model files you already have: a folder of shards or one .gguf file")g.add_argument("--data-dir", metavar="DIR", help="where downloaded model files are stored (default: Strata's data folder)")+ g.add_argument("--move-data", action="store_true",+ help="with --data-dir: move the models you already have into the new folder. Without it nothing is moved: your models stay "+ "where they are and stay usable, and the new folder gets the new downloads")g.add_argument("--context", type=_context, metavar="SIZE", help="how much text it remembers at once: 32k, 64k, 128k, 256k or a number of tokens")g.add_argument("--kv", type=_choice("a memory format", S.KV_MODES), metavar="FORMAT", help="conversation memory format: int8 (default), q4_0 (half the memory), k8v4, fp16")g.add_argument("--vision", type=_choice("a picture setting", S.VISION_MODES), metavar="off|on|gpu|cpu",@@ -362,6 +365,23 @@ def _ask_yes(title: str, text: str) -> bool:return answer in ("", "y", "yes")+def _move_data_choice(a: argparse.Namespace, s: S.LaunchSettings, catalog, machine: bool) -> bool:+ """Whether the models already on this computer move into --data-dir. Only --move-data or the answer "move" says yes; --yes, --plan,+ --output json and a run with no keyboard keep the old library where it is (it stays usable; the new folder gets new downloads)."""+ if not a.data_dir:+ return False+ if a.move_data:+ return True+ if a.yes or machine or a.plan:+ return False+ from strata_cli.launch import library+ try:+ gb = library.movable_library(catalog.data_dir(), Path(a.data_dir).expanduser())+ except Exception: # noqa: BLE001 - no answer to "where are my models": nothing to ask about+ return False+ return library.ask_move(gb, Path(a.data_dir).expanduser()) if gb > 0 else False++def open_page(url: str) -> bool:"""Open the server's page in the browser. Only ever called for an explicit --open (or the monitor's b key)."""try:@@ -524,7 +544,9 @@ def run_launch(a: argparse.Namespace) -> int:s.api_key = access.new_key()if not s.name:s.name = f"{s.model or 'model'} {S.context_label(s.context)}"- runner = Runner(s, catalog=catalog, emit=_printer(machine), feed=a.feed, assume_yes=bool(a.yes or machine), confirm=_ask_yes)+ move_data = _move_data_choice(a, s, catalog, machine)+ runner = Runner(s, catalog=catalog, emit=_printer(machine), feed=a.feed, assume_yes=bool(a.yes or machine), confirm=_ask_yes,+ move_data=move_data)if a.plan:plan = runner.plan()plan["warnings"] = [n.line() for n in notes]@@ -550,7 +572,8 @@ def run_launch(a: argparse.Namespace) -> int:_say(f"[!] {fw}")if interactive and have_choices:from strata_cli.launch import app- return _tui(app.run_tui, s, catalog=catalog, feed=a.feed, auto_run=True, save=bool(a.save_preset), open_page=bool(a.open))+ return _tui(app.run_tui, s, catalog=catalog, feed=a.feed, auto_run=True, save=bool(a.save_preset), open_page=bool(a.open),+ move_data=move_data)try:result = runner.run()except LaunchError as e:diff --git a/strata_cli/launch/library.py b/strata_cli/launch/library.pynew file mode 100644index 000000000..39b7ec17d--- /dev/null+++ b/strata_cli/launch/library.py@@ -0,0 +1,67 @@+"""The model library when `--data-dir` names another folder: what is in the folder in use, and the one question about it.++Nothing here moves a file. `strata launch` asks (or is told with --move-data); setup.py does the moving, and only when+it is given --move-data. Without it the old folder stays where it is, stays usable, and the new folder is used for new+downloads."""+from __future__ import annotations++import os+import sys+from pathlib import Path++DATA_ITEMS = ("models", "packs", "mtp")+++def library_gb(folder: Path) -> float:+ """GB of model files (models, packs, mtp) in a data folder; 0 when there are none."""+ total = 0+ for item in DATA_ITEMS:+ for root, _dirs, files in os.walk(folder / item):+ for f in files:+ try:+ total += os.path.getsize(os.path.join(root, f))+ except OSError:+ pass+ return total / 1e9+++def same_place(a: Path, b: Path) -> bool:+ try:+ return os.path.samefile(a, b)+ except OSError:+ return os.path.normcase(os.path.abspath(a)) == os.path.normcase(os.path.abspath(b))+++def same_drive(a: Path, b: Path) -> bool:+ probe = lambda p: next((q for q in (p, *p.parents) if q.exists()), None) # noqa: E731 - the new folder may not exist yet+ pa, pb = probe(a), probe(b)+ try:+ return pa is not None and pb is not None and os.stat(pa).st_dev == os.stat(pb).st_dev+ except OSError:+ return False+++def movable_library(old: Path | None, new: Path) -> float:+ """GB of models in `old` that could be moved into `new` (same drive, a different folder); 0 when nothing is there to move."""+ if old is None or same_place(old, new) or not Path(old).is_dir() or not same_drive(Path(old), new):+ return 0.0+ return library_gb(Path(old))+++def ask_move(gb: float, new: Path, *, stdin_tty: bool | None = None, out=None) -> bool:+ """Ask: keep the models where they are (and use the new folder for new downloads), or move them. True = move.+ No keyboard (a pipe, a script) or Enter: keep, the answer that loses nothing."""+ out = out or sys.stdout+ tty = sys.stdin.isatty() if stdin_tty is None else stdin_tty+ if not tty:+ return False+ size = f"{gb:.0f} GB" if gb >= 10 else f"{gb:.1f} GB"+ out.write(f"\n[!] Move your {size} of models to {new}, or use the new folder only for new downloads?\n"+ " k) keep my models where they are; the new folder is for new downloads (default)\n"+ " m) move my models to the new folder\n")+ out.flush()+ try:+ answer = input("Keep or move? [K/m] ").strip().lower()+ except EOFError:+ return False+ return answer in ("m", "move")diff --git a/strata_cli/launch/runner.py b/strata_cli/launch/runner.pyindex 297508a53..61b4aaedb 100644--- a/strata_cli/launch/runner.py+++ b/strata_cli/launch/runner.py@@ -287,8 +287,9 @@ class Runner:def __init__(self, s: S.LaunchSettings, *, catalog: Catalog | None = None, emit: Callable[[Event], None] | None = None,cancel: threading.Event | None = None, feed: str | None = None, python: str | None = None,components_dir: str | None = None, hardware: dict | None = None,- confirm: Callable[[str, str], bool] | None = None, assume_yes: bool = False):+ confirm: Callable[[str, str], bool] | None = None, assume_yes: bool = False, move_data: bool = False):self.s = s+ self.move_data = move_data # --move-data / the answer "move": the model files already here go to the new --data-dirself.confirm = confirm # asked (title, text) before a model is downloaded with no engine; True = go onself.assume_yes = assume_yes # --yes: no questionsself.engine_problem: str | None = None@@ -501,6 +502,8 @@ class Runner:data = s.data_dir or self.existing_data_dir()if data:args += ["--data-dir", str(data)]+ if self.move_data and s.data_dir: # only when the person said so: setup moves nothing otherwise+ args.append("--move-data")if s.model_path:p = Path(s.model_path)args += ["--gguf-dir", str(p if p.is_dir() else p.parent)]@@ -508,14 +511,15 @@ class Runner:args += ["--gpus", ",".join(str(g) for g in s.gpus)] if len(s.gpus) > 1 else ["--gpu", str(s.gpus[0])]if sys.platform == "darwin":# a Mac's setup (Control mode, strata_control/mac_fit.py) takes fewer options (no --kv, --gpu, speed projection)- keep = {"--yes", "--no-start", "--family", "--model", "--context", "--vision", "--data-dir", "--gguf-dir"}+ keep = {"--yes", "--no-start", "--family", "--model", "--context", "--vision", "--data-dir", "--gguf-dir", "--move-data"}+ flags = ("--yes", "--no-start", "--move-data")out, i = [], 0while i < len(args):if args[i] in keep:out.append(args[i])- if args[i] not in ("--yes", "--no-start") and i + 1 < len(args):+ if args[i] not in flags and i + 1 < len(args):out.append(args[i + 1])- i += 2 if args[i] not in ("--yes", "--no-start") else 1+ i += 2 if args[i] not in flags else 1else:i += 2 if i + 1 < len(args) and not args[i + 1].startswith("--") else 1args = outdiff --git a/strata_cli/launch/screens.py b/strata_cli/launch/screens.pyindex 9e762bd90..d6ff5a7f3 100644--- a/strata_cli/launch/screens.py+++ b/strata_cli/launch/screens.py@@ -675,7 +675,8 @@ class FolderScreen(Base):return Text("This model is already on this computer, so the folder starts where it is. Press Enter to keep it. ""Another folder only matters for files that still have to be downloaded.", style=MUTE)return Text("Models are large files. Strata keeps them in one folder; the default is Strata's own data folder. "- "Press Enter to keep it, or type another folder (it is created if it does not exist).", style=MUTE)+ "Press Enter to keep it, or type another folder (it is created if it does not exist). Models you already have stay where "+ "they are and stay usable; the new folder is for new downloads.", style=MUTE)def commit(self) -> None:value = self.query_one("#folderpath", Input).value.strip().strip('"')diff --git a/tests/terminal/test_data_dir_choice.py b/tests/terminal/test_data_dir_choice.pynew file mode 100644index 000000000..39038ce63--- /dev/null+++ b/tests/terminal/test_data_dir_choice.py@@ -0,0 +1,214 @@+"""`--data-dir` names a new folder: the model library is never moved without a choice (0.2.1 R).++Everything lives in temporary folders: settings.json (APPDATA / XDG_CONFIG_HOME), the Strata folder (setup.ROOT) and the data folders.+"""+from __future__ import annotations++import argparse+import contextlib+import io+import json+import os+import shutil+import sys+import tempfile+import unittest+from pathlib import Path+from unittest import mock++import setup+from strata_cli.launch import cmd, library+from strata_cli.launch import settings as S+from strata_cli.launch.runner import Runner++from tests.terminal.test_launch import HW_12, Home, catalog+++def put(path: Path, size: int = 64) -> Path:+ path.parent.mkdir(parents=True, exist_ok=True)+ path.write_bytes(b"x" * size)+ return path+++class DataFolderChoice(unittest.TestCase):+ def setUp(self):+ self.tmp = tempfile.TemporaryDirectory()+ self.addCleanup(self.tmp.cleanup)+ self.base = Path(self.tmp.name)+ self.root = self.base / "Strata"+ self.root.mkdir()+ self.old = self.base / "old-data"+ self.new = self.base / "new-data"+ env = mock.patch.dict(os.environ, {"APPDATA": str(self.base / "appdata"), "XDG_CONFIG_HOME": str(self.base / "appdata"),+ "STRATA_SETTINGS_FILE": ""})+ env.start()+ self.addCleanup(env.stop)+ os.environ.pop("STRATA_SETTINGS_FILE", None)+ for patcher in (mock.patch.object(setup, "ROOT", self.root), mock.patch.object(setup, "_CONTROL_HOME", None)):+ patcher.start()+ self.addCleanup(patcher.stop)+ self.assertTrue(str(setup.settings_path()).startswith(str(self.base)), setup.settings_path())+ self.weights = put(self.old / "models" / "Q2_0" / "w-00001-of-00001.gguf", 200)+ self.pack = put(self.old / "packs" / "q2_0" / "tokenizer" / "vocab.json", 20)+ self.mtp = put(self.old / "mtp" / "rt" / "experts.bin", 30)+ setup.settings_path().parent.mkdir(parents=True, exist_ok=True)+ self.write_settings({"data_dir": str(self.old), "installs": []})++ def write_settings(self, data: dict) -> None:+ setup.settings_path().write_text(json.dumps(data), encoding="utf-8")++ def saved(self) -> dict:+ return json.loads(setup.settings_path().read_text(encoding="utf-8"))++ def call(self, *args, **kw):+ with contextlib.redirect_stdout(io.StringIO()) as out:+ res = setup.data_folder(*args, **kw)+ return res, out.getvalue()++ def assertLibraryUntouched(self):+ for f in (self.weights, self.pack, self.mtp):+ self.assertTrue(f.is_file(), f)++ def test_a_new_data_dir_with_yes_keeps_the_library_and_the_saved_default(self):+ (dest, elsewhere), _ = self.call(str(self.new), yes=True)+ self.assertEqual(dest.resolve(), self.new.resolve())+ self.assertTrue(dest.is_dir())+ self.assertEqual([Path(e).resolve() for e in elsewhere], [self.old.resolve()]) # still found: the old folder is a root+ self.assertLibraryUntouched()+ self.assertFalse((self.new / "models").exists())+ self.assertEqual(self.saved()["data_dir"], str(self.old)) # the saved default is not rewritten++ def test_the_default_answer_with_no_keyboard_keeps_everything(self):+ with mock.patch("builtins.input", side_effect=EOFError):+ with self.assertRaises(SystemExit): # ask() ends a setup with nobody to answer+ self.call(str(self.new), yes=False)+ self.assertLibraryUntouched()+ self.assertEqual(self.saved()["data_dir"], str(self.old))++ def test_asked_the_answer_keep_moves_nothing(self):+ with mock.patch("builtins.input", return_value=""):+ (dest, elsewhere), said = self.call(str(self.new), yes=False)+ self.assertIn("keep)", said)+ self.assertLibraryUntouched()+ self.assertEqual(self.saved()["data_dir"], str(self.old))+ self.assertEqual([Path(e).resolve() for e in elsewhere], [self.old.resolve()])++ def test_asked_the_answer_move_moves_and_remembers_the_new_folder(self):+ with mock.patch("builtins.input", return_value="move"):+ (dest, elsewhere), _ = self.call(str(self.new), yes=False)+ self.assertEqual(elsewhere, [])+ self.assertTrue((self.new / "models" / "Q2_0" / "w-00001-of-00001.gguf").is_file())+ self.assertTrue((self.new / "packs" / "q2_0" / "tokenizer" / "vocab.json").is_file())+ self.assertFalse(self.weights.exists())+ self.assertEqual(Path(self.saved()["data_dir"]).resolve(), self.new.resolve())++ def test_move_data_moves_without_asking(self):+ with mock.patch("builtins.input", side_effect=AssertionError("must not ask")):+ (dest, elsewhere), _ = self.call(str(self.new), move=True, yes=True)+ self.assertTrue((self.new / "mtp" / "rt" / "experts.bin").is_file())+ self.assertEqual(Path(self.saved()["data_dir"]).resolve(), self.new.resolve())++ def test_set_default_data_dir_remembers_the_folder_and_moves_nothing(self):+ (dest, elsewhere), _ = self.call(str(self.new), yes=True, set_default=True)+ self.assertLibraryUntouched()+ self.assertEqual(Path(self.saved()["data_dir"]).resolve(), self.new.resolve())+ self.assertEqual([Path(e).resolve() for e in elsewhere], [self.old.resolve()])++ def test_a_pc_with_no_models_anywhere_remembers_the_new_folder(self):+ for d in ("models", "packs", "mtp"):+ shutil.rmtree(self.old / d)+ (dest, elsewhere), _ = self.call(str(self.new), yes=True)+ self.assertEqual(elsewhere, [])+ self.assertEqual(Path(self.saved()["data_dir"]).resolve(), self.new.resolve())++ def test_the_library_in_the_strata_folder_is_asked_about_too(self):+ # no remembered data folder: the models sit next to the checkout (an old install)+ self.write_settings({})+ for d in ("models", "packs", "mtp"):+ shutil.rmtree(self.old / d)+ mine = put(self.root / "Strata-data" / "models" / "Q2_0" / "w-00001-of-00001.gguf")+ (dest, elsewhere), _ = self.call(str(self.new), yes=True)+ self.assertTrue(mine.is_file())+ self.assertEqual([Path(e).resolve() for e in elsewhere], [(self.root / "Strata-data").resolve()])+ self.assertNotIn("data_dir", self.saved())++ def test_no_data_dir_still_gathers_into_the_remembered_folder(self):+ # the data folder's own job (an earlier Strata folder's models) is not part of the --data-dir question+ other = self.base / "Strata-old"+ other.mkdir()+ (other / "setup.py").write_text("# old\n")+ put(other / "models" / "Q2_0" / "extra.gguf")+ self.write_settings({"data_dir": str(self.old), "installs": [str(other)]})+ (dest, _), _ = self.call(None, yes=True)+ self.assertEqual(dest.resolve(), self.old.resolve())+ self.assertTrue((self.old / "models" / "Q2_0" / "extra.gguf").is_file())++ def test_the_same_folder_again_is_not_a_change(self):+ (dest, elsewhere), _ = self.call(str(self.old), yes=False)+ self.assertEqual(elsewhere, [])+ self.assertLibraryUntouched()+++class TerminalQuestion(unittest.TestCase):+ def setUp(self):+ self.tmp = tempfile.TemporaryDirectory()+ self.addCleanup(self.tmp.cleanup)+ self.base = Path(self.tmp.name)+ self.old = self.base / "old"+ self.new = self.base / "new"+ put(self.old / "models" / "Q2_0" / "w.gguf", 3_000_000)+ self.cat = mock.Mock()+ self.cat.data_dir.return_value = self.old++ def args(self, **kw):+ ns = dict(data_dir=str(self.new), move_data=False, yes=False, plan=False)+ ns.update(kw)+ return argparse.Namespace(**ns)++ def test_no_data_dir_asks_nothing(self):+ self.assertFalse(cmd._move_data_choice(self.args(data_dir=None), S.LaunchSettings(), self.cat, False))++ def test_move_data_says_yes_without_asking(self):+ with mock.patch("builtins.input", side_effect=AssertionError("must not ask")):+ self.assertTrue(cmd._move_data_choice(self.args(move_data=True), S.LaunchSettings(), self.cat, False))++ def test_yes_machine_and_plan_keep_the_library(self):+ with mock.patch("builtins.input", side_effect=AssertionError("must not ask")):+ for kw, machine in (({"yes": True}, False), ({}, True), ({"plan": True}, False)):+ self.assertFalse(cmd._move_data_choice(self.args(**kw), S.LaunchSettings(), self.cat, machine), kw)++ def test_no_keyboard_keeps_the_library(self):+ with mock.patch.object(sys.stdin, "isatty", return_value=False), mock.patch("builtins.input", side_effect=AssertionError):+ self.assertFalse(cmd._move_data_choice(self.args(), S.LaunchSettings(), self.cat, False))++ def test_asked_on_a_terminal(self):+ out = io.StringIO()+ with mock.patch.object(sys.stdin, "isatty", return_value=True), contextlib.redirect_stdout(out):+ with mock.patch("builtins.input", return_value="m"):+ self.assertTrue(cmd._move_data_choice(self.args(), S.LaunchSettings(), self.cat, False))+ with mock.patch("builtins.input", return_value=""):+ self.assertFalse(cmd._move_data_choice(self.args(), S.LaunchSettings(), self.cat, False))+ self.assertIn("use the new folder only for new downloads", out.getvalue())++ def test_an_empty_or_same_library_asks_nothing(self):+ self.cat.data_dir.return_value = self.new+ with mock.patch.object(sys.stdin, "isatty", return_value=True), mock.patch("builtins.input", side_effect=AssertionError):+ self.assertFalse(cmd._move_data_choice(self.args(), S.LaunchSettings(), self.cat, False))+ self.assertEqual(library.movable_library(self.base / "nothing", self.new), 0.0)++ def test_setup_gets_move_data_only_when_chosen_and_a_folder_is_named(self):+ with Home():+ cat = catalog(HW_12)+ s = S.LaunchSettings(family="qwen", model="IQ3_XXS", context=32768, vision="off", data_dir="/d")+ self.assertNotIn("--move-data", Runner(s, catalog=cat).setup_args())+ self.assertIn("--move-data", Runner(s, catalog=cat, move_data=True).setup_args())+ s2 = S.LaunchSettings(family="qwen", model="IQ3_XXS", context=32768, vision="off")+ self.assertNotIn("--move-data", Runner(s2, catalog=cat, move_data=True).setup_args())+ with mock.patch.object(sys, "platform", "darwin"):+ mac = Runner(s, catalog=cat, move_data=True).setup_args()+ self.assertIn("--move-data", mac)+ self.assertEqual(mac[mac.index("--data-dir") + 1], "/d")+++if __name__ == "__main__":+ unittest.main()diff --git a/tools/test_setup_choices.py b/tools/test_setup_choices.pyindex 1ecf1797b..998bd900e 100644--- a/tools/test_setup_choices.py+++ b/tools/test_setup_choices.py@@ -660,7 +660,7 @@ class CalibrateWithModel(unittest.TestCase):mock.patch.object(setup, "update_installed_engine", lambda *a, **k: None), \mock.patch.object(setup, "calibrate_config", lambda c: tuned.append(c.name) or True), \mock.patch.object(setup, "start", lambda *a, **k: 0), \- mock.patch.object(setup, "data_folder", lambda d: (Path(tmp.name), [])), \+ mock.patch.object(setup, "data_folder", lambda d, *a, **k: (Path(tmp.name), [])), \mock.patch.object(setup, "step", side_effect=SystemExit("reached the plain setup")):try:code, out = quiet(setup.main)diff --git a/tools/test_setup_golden.py b/tools/test_setup_golden.pyindex a1062065c..18239701b 100644--- a/tools/test_setup_golden.py+++ b/tools/test_setup_golden.py@@ -94,7 +94,7 @@ def install(ram, found, argv, answers=None, extra=(), avx512=False, configs=()):patches = [mock.patch.object(setup, "ROOT", t),mock.patch.object(setup, "GPU_PICK", None),- mock.patch.object(setup, "data_folder", lambda d: (t / "data", [])),+ mock.patch.object(setup, "data_folder", lambda d, *a, **k: (t / "data", [])),mock.patch.object(setup, "load_settings", lambda: {}),mock.patch.object(setup, "save_settings", lambda s: None),mock.patch.object(setup, "gpus", lambda: found),diff --git a/tools/test_setup_mac.py b/tools/test_setup_mac.pyindex cabaeaacc..e796ee1c9 100644--- a/tools/test_setup_mac.py+++ b/tools/test_setup_mac.py@@ -366,7 +366,7 @@ class Source(unittest.TestCase):# the user's settings.json into --data-dir, and saves that dir as the new data folder; with a temp dir that# deletes the models on exit and leaves settings.json pointing at a deleted directorywith tempfile.TemporaryDirectory() as tmp, \- mock.patch.object(setup, "data_folder", lambda requested: (Path(tmp), [])), \+ mock.patch.object(setup, "data_folder", lambda requested, *a, **k: (Path(tmp), [])), \mock.patch("subprocess.run", fake_run(M5)), \mock.patch.object(setup, "warn", lambda *a, **k: warnings.append(" ".join(str(x) for x in a))), \mock.patch.object(setup, "say", lambda *a, **k: None), \diff --git a/tools/test_setup_qwen36.py b/tools/test_setup_qwen36.pyindex 35946db24..1af98b3ea 100644--- a/tools/test_setup_qwen36.py+++ b/tools/test_setup_qwen36.py@@ -112,7 +112,7 @@ class InstallOwnPath(unittest.TestCase):mock.patch.object(setup, "engine_step", engine_step),mock.patch.object(setup, "engine_families", lambda e: self.families),mock.patch.object(setup, "run", lambda cmd, **k: self.calls.append(("run", cmd))),- mock.patch.object(setup, "data_folder", lambda d: (self.root / "data", [])),+ mock.patch.object(setup, "data_folder", lambda d, *a, **k: (self.root / "data", [])),mock.patch.object(setup, "write_setup_config", write_cfg),mock.patch.object(setup, "write_run_script", lambda tag, p, port, o=True: self.root / f"run-{tag}.sh"),mock.patch.object(setup, "recommend_pool_workers", lambda a: a),diff --git a/tools/test_setup_unsloth.py b/tools/test_setup_unsloth.pyindex 81777b09f..b758db550 100644--- a/tools/test_setup_unsloth.py+++ b/tools/test_setup_unsloth.py@@ -177,7 +177,7 @@ class Base(unittest.TestCase):patches = [mock.patch.object(setup, "ROOT", self.t),mock.patch.object(setup, "GPU_PICK", None),- mock.patch.object(setup, "data_folder", lambda d: (self.t / "data", [])),+ mock.patch.object(setup, "data_folder", lambda d, *a, **k: (self.t / "data", [])),mock.patch.object(setup, "installed_configs", lambda: []),mock.patch.object(setup, "gpus", lambda: found),mock.patch.object(setup, "amd_gpus", lambda *a: list(amd)),