Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

macOS: a failed Python install no longer crashes, and brew's python3.x is found

Yoan Ancelly56d0c452bae2
diff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swift
index 48fa702e..a8512dbc 100644
--- a/frontend/Sources/NSPortBuilder/ContentView.swift
+++ b/frontend/Sources/NSPortBuilder/ContentView.swift
@@ -1683,6 +1683,14 @@ final class BuildModel: ObservableObject {
}
}
cands += ["/opt/homebrew/bin/python3", "/usr/local/bin/python3", "/usr/bin/python3"]
+ // 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 }
+ }
let p = Process()
p.executableURL = URL(fileURLWithPath: "/usr/bin/which")
p.arguments = ["-a", "python3"]
@@ -1822,10 +1830,14 @@ final class BuildModel: ObservableObject {
let pyVer = pythonVersion(py).map { "\($0.0).\($0.1)" } ?? "?"
// A too-old interpreter is a different problem from a missing package: say which one it is,
// because the fix differs (install a newer Python vs pip install into this one).
+ // A version we cannot read means no interpreter ran at all (py is then the venv
+ // that does not exist yet), which is not the same as one that is too old.
+ let minVer = "\(minPython.0).\(minPython.1)"
let pyDetail = pyOK ? py
- : (pythonVersion(py).map { $0 >= minPython } ?? false)
+ : pythonVersion(py).map { $0 >= minPython
? "dep.python.missing:\(py) (\(pyVer))"
- : "dep.python.old:\(pyVer):\(minPython.0).\(minPython.1)"
+ : "dep.python.old:\(pyVer):\(minVer)" }
+ ?? "dep.python.notFound:\(minVer):\(minVer)"
out.append(Dep(id: "python", name: "dep.python", hint: "dep.python.hint",
present: pyOK, detail: pyDetail,
installCmd: [py, "-m", "pip", "install", "--user", "lz4", "capstone", "fonttools", "backports.zstd"]))
@@ -1872,7 +1884,7 @@ final class BuildModel: ObservableObject {
}
DispatchQueue.main.async {
if let j = self.deps.firstIndex(where: { $0.id == dep.id }) { self.deps[j].installing = false }
- if !ok { self.doneNote = String(format: self.t("dep.install.fail"), 1) }
+ if !ok { self.doneNote = String(format: self.t("dep.install.fail"), self.t(dep.name)) }
self.checkDeps()
}
}
@@ -1909,14 +1921,15 @@ final class BuildModel: ObservableObject {
}
/// A dependency row's second column: a path when there is one, else the translated hint.
- /// `detail` carries either a real path, an L10n key, or "key:argument".
+ /// `detail` carries either a real path, an L10n key, or "key:argument[:argument…]".
func depDetail(_ d: Dep) -> String {
let raw = d.detail
if raw.isEmpty { return t(d.hint) }
if raw.hasPrefix("/") || raw.hasPrefix("~") { return raw }
if let colon = raw.firstIndex(of: ":") {
let key = String(raw[..<colon]), arg = String(raw[raw.index(after: colon)...])
- if L10n.table[key] != nil { return String(format: t(key), shortPath(arg)) }
+ let args = arg.components(separatedBy: ":").map { shortPath($0) as CVarArg }
+ if L10n.table[key] != nil { return String(format: t(key), arguments: args) }
}
if L10n.table[raw] != nil { return t(raw) }
return raw
diff --git a/frontend/Sources/NSPortBuilder/Localization.swift b/frontend/Sources/NSPortBuilder/Localization.swift
index f4323d17..03ebf7f7 100644
--- a/frontend/Sources/NSPortBuilder/Localization.swift
+++ b/frontend/Sources/NSPortBuilder/Localization.swift
@@ -371,8 +371,10 @@ enum L10n {
"dep.python.missing": ("%@ 缺包", "%@ is missing packages"),
"dep.install.begin": ("开始安装 %@…", "Installing %@…"),
"dep.install.fail": ("安装失败:%@(详情见日志)", "Install failed: %@ (see the log)"),
- "dep.python.old": ("Python %@ 太旧(需要 3.9 或更新);这个解释器没有构建需要的包",
- "Python %@ is too old (need 3.9 or newer); it lacks the packages the build needs"),
+ "dep.python.old": ("Python %@ 太旧(需要 %@ 或更新);这个解释器没有构建需要的包",
+ "Python %@ is too old (need %@ or newer); it lacks the packages the build needs"),
+ "dep.python.notFound": ("没找到 Python %@ 或更新版本;先装一个(brew install python@%@),再点「重新检测」",
+ "No Python %@ or newer found; install one (brew install python@%@), then press Check again"),
"dep.python.none": ("没找到可用的 Python(%@ 不行)——点右侧「安装」,App 会下载 3.12 并静默装到自己的目录",
"No usable Python found (%@ will not run) — press Install and the app fetches 3.12 into its own folder"),
"msg.workdirHint": ("提示:「输出目录」同时是构建缓存的位置(输出目录/<ID>_build)。已有构建资源时,把它选回上次的同一位置即可复用(解包、shader 不重跑);换新位置会从头再来。",