setup: honour --source on a Mac, whose hand-over skips setup.py's parser (#2363)

setup.py returns from mac_setup() before its own argparse runs, so a Mac never
sees the --source that sets STRATA_SOURCE, and the Mac parser did not define it
either: the flag the download failure recommends landed in parse_known_args'
leftovers and was dropped with "not used on a Mac".

Define it in the Mac parser and set STRATA_SOURCE from it, mirroring setup.py.
This commit is contained in:
nekomario28 authored and Niko1221 committed 2026-10-14 06:52:38 +02:00
1 parent 2e98a86344
commit be225ae20c
2 files changed
+32

No files matched your search

+8
View File
@@ -498,6 +498,9 @@ def main(argv=None) -> int:
ap.add_argument("--models-dir")
ap.add_argument("--gguf-dir")
ap.add_argument("--yes", action="store_true")
ap.add_argument("--source", choices=S.SOURCES, default=None,
help="where model files come from: auto (huggingface), huggingface, modelscope; "
"same as STRATA_SOURCE")
ap.add_argument("--setup", action="store_true")
ap.add_argument("--no-start", action="store_true")
ap.add_argument("--check", action="store_true")
@@ -508,6 +511,11 @@ def main(argv=None) -> int:
a, rest = ap.parse_known_args(argv)
if rest:
S.warn("not used on a Mac: " + " ".join(rest))
# setup.py hands a Mac over before its own parser runs, so --source has to be honoured here too:
# source_hint() recommends it on every platform, and a Mac that dropped it failed the download
# with the same unreachable host (#2363).
if a.source:
os.environ["STRATA_SOURCE"] = a.source
S.say("Strata on a Mac (Apple Silicon, Metal)")
data, elsewhere = S.data_folder(a.data_dir)
roots = [data, *elsewhere]
+24
View File
@@ -6,8 +6,10 @@ PC: sysctl / sw_vers / xcode-select are mocked. No GPU, no network.
"""
from __future__ import annotations
import os
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
from unittest import mock
@@ -249,5 +251,27 @@ class RepackGuard(unittest.TestCase):
self.assertNotIn("mmap", src) # no dirty mapping of the output
class Source(unittest.TestCase):
"""setup.py hands a Mac over before its own parser runs, so the Mac parser has to know --source:
source_hint() recommends it on every platform (#2363)."""
def test_the_source_flag_reaches_strata_source(self):
env = mock.patch.dict(os.environ, {}, clear=False)
env.start()
self.addCleanup(env.stop)
os.environ.pop("STRATA_SOURCE", None)
warnings = []
with tempfile.TemporaryDirectory() as 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), \
mock.patch.object(setup, "ok", lambda *a, **k: None), \
mock.patch.object(setup, "step", lambda *a, **k: None):
M.main(["--source", "modelscope", "--yes", "--check", "--data-dir", tmp])
self.assertEqual(os.environ.get("STRATA_SOURCE"), "modelscope")
self.assertFalse([w for w in warnings if "--source" in w],
f"--source was not used: {warnings}")
if __name__ == "__main__":
unittest.main()