Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
The launcher finds the Pythons uv installs, and never builds its venv from a path that cannot run
seeddsa3612f9fdfb7
diff --git a/frontend-qt/README.md b/frontend-qt/README.mdindex 8c72012e..46ee2785 100644--- a/frontend-qt/README.md+++ b/frontend-qt/README.md@@ -35,6 +35,9 @@ wherever `NSPB_REPO` points, and the repository group lets you pick it by hand.- Dependency detection per platform: Python + packages, .NET SDK, and either **Xcode + iOS SDK +Metal toolchain** (macOS) or the **Windows cross toolchain** (see [Windows build](#windows-build)),plus xcodegen / zstd / spirv-cross. Each row has an install button when a command can fix it.+ The interpreter search covers the Pythons **uv** installs (`~/.local/share/uv/python`,+ `~/.local/bin`, `UV_PYTHON_INSTALL_DIR`; `%LOCALAPPDATA%\uv\python` on Windows) and picks the+ newest one that runs at 3.12 or newer — the script's own floor — with the build packages.- Pick a game folder (or its four inputs separately); base / update / DLC / `prod.keys` arerecognised from the dump names.- Build: runs the same script the SwiftUI app runs, streams its stage lines and log, then packsdiff --git a/frontend-qt/nspb_qt/model.py b/frontend-qt/nspb_qt/model.pyindex fd999500..41bf0eab 100644--- a/frontend-qt/nspb_qt/model.py+++ b/frontend-qt/nspb_qt/model.py@@ -202,7 +202,7 @@ class Model(QObject):"""if py_ok:return Dep('python', 'dep.python', 'dep.python.hint', DepState.OK, py)- if py_ver and pu._ver_tuple(py_ver) >= (3, 9):+ if py_ver and pu._ver_tuple(py_ver) >= pu.MIN_PYTHON:return Dep('python', 'dep.python', 'dep.python.hint', DepState.MISSING,f'dep.python.missing:{py} ({py_ver})',install=[py, '-m', 'pip', 'install', 'lz4', 'capstone', 'fonttools',@@ -754,6 +754,13 @@ class Model(QObject):"""Create or reuse the app's venv and install the build packages into it."""vpy = pu.venv_python()if not Path(vpy).is_file():+ # The panel's last resort is /usr/bin/python3 (3.9) or the venv path itself, and+ # neither can run `-m venv`: the row used to stay red however often Install ran.+ base = pu.venv_base(base)+ if base is None:+ self.log(f'no Python {pu.MIN_PYTHON[0]}.{pu.MIN_PYTHON[1]} or newer to create '+ f'{pu.venv_dir()} from\n')+ return Falsevdir = pu.venv_dir()vdir.parent.mkdir(parents=True, exist_ok=True)self.log(f'$ {base} -m venv {vdir}\n')diff --git a/frontend-qt/nspb_qt/platform_util.py b/frontend-qt/nspb_qt/platform_util.pyindex 7fbd3c6b..35cde9bf 100644--- a/frontend-qt/nspb_qt/platform_util.py+++ b/frontend-qt/nspb_qt/platform_util.py@@ -6,6 +6,7 @@ the window never branch on sys.platform themselves.from __future__ import annotationsimport os+import reimport shutilimport subprocessimport sys@@ -14,6 +15,12 @@ from pathlib import PathIS_WIN = sys.platform.startswith('win')IS_MAC = sys.platform == 'darwin'+#: The build script's own floor: `build_ipa_from_nsp.py` raises below 3.12 for a direct RomFS+#: image build, and its f-strings do not parse on 3.9. `/usr/bin/python3` is 3.9 on a stock Mac,+#: and pip-installing into it produced a build that died inside the script (issue #53 in the+#: SwiftUI front end) instead of a row that said why.+MIN_PYTHON = (3, 12)+# ---------------------------------------------------------------- tool discovery@@ -28,23 +35,47 @@ def _which(name: str, extra: list[str] | None = None) -> str | None:return None-def find_python(extra_candidates: list[str] | None = None) -> tuple[str, bool, str]:- """The interpreter to build with: (path, has_packages, version_or_empty).+def uv_pythons() -> list[str]:+ """The interpreters `uv python install` manages.- The build scripts need lz4, capstone, fontTools, zstd and (for compressed dumps) nsz. A- system interpreter rarely has them, so the venv the app manages is checked first, then- every python on the machine. `extra_candidates` puts paths ahead of the system probes- without this module knowing about Windows specifics: the caller passes the interpreter the- app installed for itself (toolchain.python_dir), which a machine with no system Python is- exactly the one that has to be found again.+ uv downloads its own Pythons into a store (`~/.local/share/uv/python`, or+ `UV_PYTHON_INSTALL_DIR`) and links shims into `~/.local/bin`. Neither directory is on a GUI+ process's PATH and neither was in the probe list, so a uv user with a working 3.12 and the+ packages was told no interpreter had been found. Windows keeps the store under+ `%LOCALAPPDATA%\\uv\\python` and puts the exe straight in the install folder.+ """+ # The interpreter itself, not `python3-config` and friends that share the prefix.+ name_re = re.compile(r'^python(3(\.\d+)?)?\.exe$' if IS_WIN else r'^python3(\.\d+)?$')++ def named(d: Path, pattern: str) -> list[str]:+ return sorted(str(p) for p in d.glob(pattern) if name_re.match(p.name))++ out: list[str] = []+ home = Path.home()+ shim_dir = home / '.local' / 'bin'+ if shim_dir.is_dir():+ out += named(shim_dir, 'python*.exe' if IS_WIN else 'python3*')+ local = Path(os.environ.get('LOCALAPPDATA', str(home / 'AppData' / 'Local')))+ roots = [os.environ.get('UV_PYTHON_INSTALL_DIR') or '',+ str(local / 'uv' / 'python') if IS_WIN else str(home / '.local' / 'share' / 'uv' / 'python')]+ for root in roots:+ if not root or not Path(root).is_dir():+ continue+ for install in sorted(Path(root).iterdir(), reverse=True):+ if install.is_dir():+ out += named(install if IS_WIN else install / 'bin',+ 'python*.exe' if IS_WIN else 'python3*')+ return out+++def python_candidates(extra_candidates: list[str] | None = None) -> list[str]:+ """Every interpreter a build could run under, best first.++ The app's own venv, then whatever the caller passes (the interpreter the app installed for+ itself, which a machine with no system Python is exactly the one that has to be found again),+ then the platform's usual installs, uv's store, and last what `which` can see — which, in a+ GUI launch, is next to nothing."""- probe = (- "import lz4, capstone, fontTools\n"- "try:\n"- " from compression import zstd\n"- "except ImportError:\n"- " from backports import zstd\n"- )cands: list[str] = [venv_python()] + [c for c in (extra_candidates or []) if c]if IS_WIN:cands += [@@ -58,27 +89,73 @@ def find_python(extra_candidates: list[str] | None = None) -> tuple[str, bool, sfor v in sorted(os.listdir(fw), reverse=True):cands.append(f'{fw}/{v}/bin/python3')cands += ['/opt/homebrew/bin/python3', '/usr/local/bin/python3', '/usr/bin/python3']+ cands += uv_pythons()if w := _which('python3' if not IS_WIN else 'python'):cands.append(w)+ return cands+++def find_python(extra_candidates: list[str] | None = None) -> tuple[str, bool, str]:+ """The interpreter to build with: (path, has_packages, version_or_empty).- fallback: tuple[str, str] | None = None+ The build scripts need lz4, capstone, fontTools, zstd and (for compressed dumps) nsz. A+ system interpreter rarely has them, so the venv the app manages is checked first, then+ every python on the machine (see python_candidates for the order).+ """+ probe = (+ "import lz4, capstone, fontTools\n"+ "try:\n"+ " from compression import zstd\n"+ "except ImportError:\n"+ " from backports import zstd\n"+ )++ ready: tuple[str, str] | None = None # newest that already has the packages+ fallback: tuple[str, str] | None = None # newest that runs at all: 安装 finishes itseen: set[str] = set()- for c in cands:+ for c in python_candidates(extra_candidates):if not c or c in seen or not Path(c).is_file():continueseen.add(c)ver = _python_version(c)- if not ver or _ver_tuple(ver) < (3, 9):+ if not ver or _ver_tuple(ver) < MIN_PYTHON:continueif _runs(c, ['-c', probe]):- return (c, True, ver)- if fallback is None:+ if ready is None or _ver_tuple(ver) > _ver_tuple(ready[1]):+ ready = (c, ver)+ elif fallback is None or _ver_tuple(ver) > _ver_tuple(fallback[1]):fallback = (c, ver)+ if ready:+ return (ready[0], True, ready[1])if fallback:return (fallback[0], False, fallback[1])return ('python' if IS_WIN else '/usr/bin/python3', False, '')+def venv_base(preferred: str) -> str | None:+ """The interpreter to create the app's venv from, or None when the machine has none.++ `preferred` is what the panel picked; when find_python() found nothing that is `/usr/bin/+ python3` (3.9, below MIN_PYTHON) or the venv path it hopes to create — neither can run+ `-m venv`, and the Python row never recovered from it. So a base that does not run at the+ required version falls back to the newest candidate that does.+ """+ if Path(preferred).is_file() and os.access(preferred, os.X_OK):+ v = _python_version(preferred)+ if v and _ver_tuple(v) >= MIN_PYTHON:+ return preferred+ best: tuple[str, str] | None = None+ for c in python_candidates():+ if not c or not Path(c).is_file() or not os.access(c, os.X_OK):+ continue+ v = _python_version(c)+ if not v or _ver_tuple(v) < MIN_PYTHON:+ continue+ if best is None or _ver_tuple(v) > _ver_tuple(best[1]):+ best = (c, v)+ return best[0] if best else None++def _python_version(py: str) -> str:try:r = subprocess.run([py, '-c', 'import sys;print("%d.%d"%sys.version_info[:2])'],diff --git a/frontend-qt/tests/test_win.py b/frontend-qt/tests/test_win.pyindex 22c4407d..dcaa8fe4 100644--- a/frontend-qt/tests/test_win.py+++ b/frontend-qt/tests/test_win.py@@ -1211,6 +1211,89 @@ class PythonInstallTest(unittest.TestCase):self.assertEqual(py, str(fake / 'python.exe'))self.assertFalse(ok) # the packages are not installed in it (yet)+ def test_python_candidates_include_uvs_managed_interpreters(self) -> None:+ """`uv python install` keeps its Pythons outside every location the app used to probe.++ Reported from a Mac whose only 3.12 was uv's: `uv` had the packages, the panel said no+ interpreter was found. A GUI launch's PATH has neither uv's store nor ~/.local/bin.+ """+ from nspb_qt import platform_util as pu+ with tempfile.TemporaryDirectory() as td:+ store = Path(td) / 'python'+ exe = store / 'cpython-3.12.13-macos-aarch64-none' / 'bin' / 'python3.12'+ exe.parent.mkdir(parents=True)+ exe.write_text('#!/bin/sh\n')+ exe.chmod(0o755)+ shim = Path(td) / '.local' / 'bin' / 'python3'+ shim.parent.mkdir(parents=True)+ shim.write_text('#!/bin/sh\n')+ with mock.patch.object(pu, 'IS_WIN', False), \+ mock.patch.dict(os.environ, {'UV_PYTHON_INSTALL_DIR': str(store), 'HOME': td}):+ cands = pu.uv_pythons()+ self.assertIn(str(exe), cands, "uv's store holds the real interpreter")+ self.assertIn(str(shim), cands, "uv links a python3 shim in ~/.local/bin")++ def test_find_python_takes_a_uv_interpreter_when_it_is_the_only_one(self) -> None:+ """The room's report: uv had a 3.12 with the packages and the panel still found nothing."""+ from nspb_qt import platform_util as pu+ with tempfile.TemporaryDirectory() as td:+ store = Path(td) / 'python'+ exe = store / 'cpython-3.12.13-macos-aarch64-none' / 'bin' / 'python3.12'+ exe.parent.mkdir(parents=True)+ exe.write_text('#!/bin/sh\n')+ exe.chmod(0o755)+ with mock.patch.object(pu, 'IS_WIN', False), \+ mock.patch.object(pu, 'venv_python', return_value=str(Path(td) / 'no-venv')), \+ mock.patch.object(pu, '_which', return_value=None), \+ mock.patch.object(pu, '_python_version', return_value='3.12.13'), \+ mock.patch.object(pu, '_runs', return_value=True), \+ mock.patch.object(pu.Path, 'is_file', lambda self: str(self) == str(exe)), \+ mock.patch.dict(os.environ, {'UV_PYTHON_INSTALL_DIR': str(store)}):+ py, ok, ver = pu.find_python()+ self.assertEqual(py, str(exe))+ self.assertTrue(ok)+ self.assertEqual(ver, '3.12.13')++ def test_find_python_prefers_the_newest_interpreter_that_has_the_packages(self) -> None:+ """A 3.9 with the packages must not win over a 3.12: the script needs 3.12.++ Apple's /usr/bin/python3 is 3.9 and sits above uv's store in the candidate list, so the+ old first-match-wins loop picked the one interpreter that cannot run the build.+ """+ from nspb_qt import platform_util as pu+ with tempfile.TemporaryDirectory() as td:+ old = Path(td) / 'python3.9'+ new = Path(td) / 'python3.12'+ for p in (old, new):+ p.write_text('x')+ versions = {str(old): '3.9', str(new): '3.12.13'}+ with mock.patch.object(pu, 'python_candidates', return_value=[str(old), str(new)]), \+ mock.patch.object(pu, '_python_version', side_effect=lambda p: versions[p]), \+ mock.patch.object(pu, '_runs', return_value=True):+ py, ok, ver = pu.find_python()+ self.assertEqual((py, ok), (str(new), True))+ self.assertEqual(ver, '3.12.13')++ def test_venv_base_is_never_the_venv_it_has_to_create(self) -> None:+ """The row's Install used to run `-m venv` on a path that does not exist yet."""+ from nspb_qt import platform_util as pu+ with tempfile.TemporaryDirectory() as td:+ wanted = str(Path(td) / 'no-venv' / 'bin' / 'python3')+ real = Path(td) / 'python3.12'+ real.write_text('x')+ real.chmod(0o755)+ with mock.patch.object(pu, 'python_candidates', return_value=[wanted, str(real)]), \+ mock.patch.object(pu, '_python_version', return_value='3.12.13'):+ self.assertEqual(pu.venv_base(wanted), str(real))+ self.assertEqual(pu.venv_base(str(real)), str(real))++ def test_venv_base_reports_no_interpreter_instead_of_a_broken_base(self) -> None:+ from nspb_qt import platform_util as pu+ with tempfile.TemporaryDirectory() as td:+ wanted = str(Path(td) / 'no-venv' / 'bin' / 'python3')+ with mock.patch.object(pu, 'python_candidates', return_value=[wanted]):+ self.assertIsNone(pu.venv_base(wanted))+class XcodeBetaTest(unittest.TestCase):"""Xcode detection asks xcode-select, not a fixed /Applications/Xcode.app path.diff --git a/frontend/README.md b/frontend/README.mdindex 2dee5b48..aed7a13d 100644--- a/frontend/README.md+++ b/frontend/README.md@@ -221,6 +221,13 @@ and picks the first interpreter that can really import`lz4 capstone fontTools backports.zstd`. That same interpreter then runs thebuild.+The interpreters uv installs (`uv python install`) count as well: they live in+`~/.local/share/uv/python` (or `UV_PYTHON_INSTALL_DIR`) with shims in+`~/.local/bin`, neither of which a GUI launch's PATH contains, and a uv user+often has no Homebrew and no python.org framework at all. When no interpreter is+found, **Install** creates the app's venv from the newest one that does run at+3.12 or newer rather than from the venv path it is about to create.+## LanguageThe interface follows the system language at every launch: any Chinese variantdiff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swiftindex d15f735d..d39f8dc3 100644--- a/frontend/Sources/NSPortBuilder/ContentView.swift+++ b/frontend/Sources/NSPortBuilder/ContentView.swift@@ -1893,6 +1893,18 @@ final class BuildModel: ObservableObject {nonisolated static func venvPython() -> String { venvDir + "/bin/python3" }+ /// Where uv keeps the Pythons it installs (`uv python install`): the shims in `~/.local/bin`+ /// and the store the real binaries live in, which `UV_PYTHON_INSTALL_DIR` moves. A uv user+ /// often has neither python.org's framework nor Homebrew, and a GUI launch's PATH is+ /// /usr/bin:/bin:/usr/sbin:/sbin, so neither `which` nor the locations below see them: a+ /// working uv Python 3.12 was reported as "No Python 3.12 or newer found". Injectable so a+ /// test can point them at a scratch tree.+ nonisolated static var uvShimDir = NSHomeDirectory() + "/.local/bin"+ nonisolated static var uvPythonRoot: String = {+ let dir = ProcessInfo.processInfo.environment["UV_PYTHON_INSTALL_DIR"] ?? ""+ return dir.isEmpty ? NSHomeDirectory() + "/.local/share/uv/python" : dir+ }()+nonisolated static func importsOK(_ py: String) -> Bool { runOK(py, ["-c", importProbe]) }/// backports.zstd declares Python < 3.14, so it is only installed where it is needed.@@ -1925,9 +1937,16 @@ final class BuildModel: ObservableObject {}let vpy = venvPython()if !FileManager.default.isExecutableFile(atPath: vpy) {- log += "$ \(base) -m venv \(venvDir)\n"+ // findPython() returns the venv path it hopes to create when no interpreter was+ // found, and the panel hands that to this function. It cannot be a base: `-m venv`+ // failed with "could not start …" and the Python row never recovered.+ guard let interp = venvBase(preferred: base) else {+ return (false, log + "no Python \(minPython.0).\(minPython.1) or newer to create \(venvDir) from\n")+ }+ if interp != base { log += "\(base) is not a usable interpreter; using \(interp)\n" }+ log += "$ \(interp) -m venv \(venvDir)\n"try? FileManager.default.createDirectory(atPath: (venvDir as NSString).deletingLastPathComponent, withIntermediateDirectories: true)- guard run(base, ["-m", "venv", venvDir]) else { return (false, log + "venv creation failed\n") }+ guard run(interp, ["-m", "venv", venvDir]) else { return (false, log + "venv creation failed\n") }}let pkgs = pipPackages(pythonVersion(vpy) ?? minPython).joined(separator: " ")log += "$ \(vpy) -m pip install \(pkgs)\n"@@ -1952,9 +1971,47 @@ final class BuildModel: ObservableObject {return (a, b)}- /// Every python3 on this Mac, newest-looking first, each tried for a usable version and the- /// packages. Returns the one to build with, plus why the others were rejected for the message.- nonisolated static func findPython() -> (path: String, ok: Bool) {+ /// The interpreter to create the venv from. `preferred` is what the panel picked; when+ /// findPython() found nothing that is the venv path it hopes to create, which cannot be a+ /// base (see makeVenv). So a base that does not run at the required version falls back to+ /// the newest candidate that does. nil when this Mac has no such interpreter at all.+ nonisolated static func venvBase(preferred: String) -> String? {+ if FileManager.default.isExecutableFile(atPath: preferred),+ let v = pythonVersion(preferred), v >= minPython {+ return preferred+ }+ return pythonCandidates().first {+ FileManager.default.isExecutableFile(atPath: $0)+ && (pythonVersion($0).map { $0 >= minPython } ?? false)+ }+ }++ /// The `python3` / `python3.x` names in a directory, newest version first.+ nonisolated static func pythonNames(in dir: String, matching pattern: String) -> [String] {+ let names = (try? FileManager.default.contentsOfDirectory(atPath: dir)) ?? []+ return names.filter { $0.range(of: pattern, options: .regularExpression) != nil }+ .sorted { $0.compare($1, options: .numeric) == .orderedDescending }+ }++ /// uv's managed Pythons: the shims in `uvShimDir` and every install under `uvPythonRoot`+ /// (`cpython-3.12.13-macos-aarch64-none/bin/python3.12`). A uv user often has neither+ /// python.org's framework nor Homebrew, and a GUI launch's PATH does not contain+ /// `~/.local/bin`, so nothing else on this Mac finds them.+ nonisolated static func uvPythonCandidates() -> [String] {+ var out = pythonNames(in: uvShimDir, matching: #"^python3(\.\d+)?$"#).map { uvShimDir + "/" + $0 }+ let installs = (try? FileManager.default.contentsOfDirectory(atPath: uvPythonRoot)) ?? []+ for d in installs.sorted(by: { $0.compare($1, options: .numeric) == .orderedDescending }) {+ let bin = uvPythonRoot + "/" + d + "/bin"+ out += pythonNames(in: bin, matching: #"^python3(\.\d+)?$"#).map { bin + "/" + $0 }+ }+ return out+ }++ /// Every interpreter a build could run under, best first: python.org's framework, Homebrew,+ /// /usr/local, uv's store, then whatever `which` can see. Probed by hand because a GUI app+ /// does not inherit the shell's PATH — the same reason .NET (in ~/.dotnet) used to show as+ /// missing while a terminal saw it.+ nonisolated static func pythonCandidates() -> [String] {var cands: [String] = []let fw = "/Library/Frameworks/Python.framework/Versions"if let vers = try? FileManager.default.contentsOfDirectory(atPath: fw) {@@ -1966,11 +2023,9 @@ final class BuildModel: ObservableObject {// Homebrew's [email protected] is always python3.x, but the bare python3 link exists only for// the formula that is linked: a 3.12 beside an unlinked default would go unseen.for dir in ["/opt/homebrew/bin", "/usr/local/bin"] {- let names = (try? FileManager.default.contentsOfDirectory(atPath: dir)) ?? []- cands += names.filter { $0.range(of: #"^python3\.\d+$"#, options: .regularExpression) != nil }- .sorted { $0.compare($1, options: .numeric) == .orderedDescending }- .map { dir + "/" + $0 }+ cands += pythonNames(in: dir, matching: #"^python3\.\d+$"#).map { dir + "/" + $0 }}+ cands += uvPythonCandidates()let p = Process()p.executableURL = URL(fileURLWithPath: "/usr/bin/which")p.arguments = ["-a", "python3"]@@ -1982,9 +2037,15 @@ final class BuildModel: ObservableObject {let out = String(data: pipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8) ?? ""cands += out.split(separator: "\n").map(String.init)}+ return cands+ }++ /// Every python3 on this Mac, newest-looking first, each tried for a usable version and the+ /// packages. Returns the one to build with, plus why the others were rejected for the message.+ nonisolated static func findPython() -> (path: String, ok: Bool) {var seen = Set<String>()var fallback: (String, (Int, Int))? = nil // newest with an acceptable version but no packages- for c in cands where !c.isEmpty && seen.insert(c).inserted {+ for c in pythonCandidates() where !c.isEmpty && seen.insert(c).inserted {guard FileManager.default.isExecutableFile(atPath: c), let v = pythonVersion(c) else { continue }guard v >= minPython else { continue }if importsOK(c) { return (c, true) }diff --git a/frontend/Tests/NSPortBuilderTests/LibraryTests.swift b/frontend/Tests/NSPortBuilderTests/LibraryTests.swiftindex ef283823..5c7bb909 100644--- a/frontend/Tests/NSPortBuilderTests/LibraryTests.swift+++ b/frontend/Tests/NSPortBuilderTests/LibraryTests.swift@@ -1036,6 +1036,63 @@ final class LibraryTests: XCTestCase {}}+ /// A uv-managed Python sits outside every location the app probed, and a GUI launch's PATH+ /// hides ~/.local/bin: uv had a working 3.12 with the packages and the panel still said+ /// "No Python 3.12 or newer found".+ func testUvManagedPythonsAreCandidates() throws {+ let oldShim = BuildModel.uvShimDir, oldRoot = BuildModel.uvPythonRoot+ defer { BuildModel.uvShimDir = oldShim; BuildModel.uvPythonRoot = oldRoot }+ let shim = temporary.appendingPathComponent("local/bin")+ let root = temporary.appendingPathComponent("uv/python")+ let store = root.appendingPathComponent("cpython-3.12.13-macos-aarch64-none/bin")+ for dir in [shim, store] {+ try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)+ }+ // uv links python3 / python3.12 shims in ~/.local/bin; the store holds the real binary.+ for dir in [shim, store] {+ for name in ["python3", "python3.12"] {+ try Data("#!/bin/sh\n".utf8).write(to: dir.appendingPathComponent(name))+ }+ }+ BuildModel.uvShimDir = shim.path+ BuildModel.uvPythonRoot = root.path+ let cands = BuildModel.pythonCandidates()+ XCTAssertTrue(cands.contains(shim.appendingPathComponent("python3").path),+ "the uv shim must be probed: a GUI launch's PATH does not contain ~/.local/bin")+ XCTAssertTrue(cands.contains(shim.appendingPathComponent("python3.12").path))+ XCTAssertTrue(cands.contains(store.appendingPathComponent("python3.12").path),+ "uv's store holds the interpreter itself, not only the shim")+ }++ /// The panel hands makeVenv() the venv path it hopes to create when findPython() found no+ /// interpreter. That cannot be a base: `-m venv` on it could not even start, so the Python+ /// row stayed red however often 安装 was pressed.+ func testVenvBaseIsNeverTheVenvItHasToCreate() throws {+ let oldShim = BuildModel.uvShimDir, oldRoot = BuildModel.uvPythonRoot, oldVenv = BuildModel.venvDir+ defer {+ BuildModel.uvShimDir = oldShim+ BuildModel.uvPythonRoot = oldRoot+ BuildModel.venvDir = oldVenv+ }+ let shim = temporary.appendingPathComponent("bin")+ try FileManager.default.createDirectory(at: shim, withIntermediateDirectories: true)+ // A stand-in interpreter: only its version and its exit status are asked for here.+ let interp = shim.appendingPathComponent("python3.12")+ try Data("#!/bin/sh\n[ \"$1\" = -c ] && echo 3.12\nexit 0\n".utf8).write(to: interp)+ try FileManager.default.setAttributes([.posixPermissions: 0o755], ofItemAtPath: interp.path)+ BuildModel.uvShimDir = shim.path+ BuildModel.uvPythonRoot = temporary.appendingPathComponent("no-uv").path+ BuildModel.venvDir = temporary.appendingPathComponent("no-venv").path++ let wanted = BuildModel.venvPython() // findPython()'s last resort, and what the panel passes+ let base = try XCTUnwrap(BuildModel.venvBase(preferred: wanted), "a usable interpreter must be found")+ XCTAssertNotEqual(base, wanted, "the venv cannot be the base it is created from")+ let v = try XCTUnwrap(BuildModel.pythonVersion(base))+ XCTAssertTrue(v.0 > BuildModel.minPython.0 || (v.0 == BuildModel.minPython.0 && v.1 >= BuildModel.minPython.1))+ XCTAssertEqual(BuildModel.venvBase(preferred: interp.path), interp.path,+ "an interpreter that does run at the required version is kept as given")+ }+/// Issue #73: the extraction writes RomFS.img now, not a RomFS folder. The archive step looked/// only for the folder, so every build ended with "archive skipped" after a successful build./// This drives BuildModel.extractedVersion — the function the archive step calls — rather than