Skip to content

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

Keep Qt pre-push tests working on Python 3.9

thehobbit85bb5c0ed83806
diff --git a/frontend-qt/README.md b/frontend-qt/README.md
index d3a7a40f..65f8c731 100644
--- a/frontend-qt/README.md
+++ b/frontend-qt/README.md
@@ -12,7 +12,7 @@ written once and runs everywhere Python and Qt do.
| | SwiftUI (`frontend/`) | Qt (this) |
|---|---|---|
| Platforms | macOS 13+ | Windows 10+, macOS 11+ |
-| Language | Swift | Python 3.9+ |
+| Language | Swift | Python 3.9+ for the launcher and its tests |
| Strings | `l10n/*.json`, read by `LocalizationFiles.swift` | the same files, read by `nspb_qt/l10n.py` |
| Build logic | runs the Python scripts | runs the same scripts |
@@ -131,7 +131,7 @@ Run this first if you prefer the command line. It lists what is missing and wher
python -m nspb_qt.win.doctor
```
-1. **Python 3.10+**, then `pip install PySide6 lz4 capstone fonttools zbic pillow`
+1. **Python 3.12+** for the game build scripts, then `pip install PySide6 lz4 capstone fonttools zbic pillow`
(and `backports.zstd` before Python 3.14).
2. **.NET SDK 10** — the app downloads it (the zip, not the installer: no administrator rights,
about 287 MB), or get it from <https://dotnet.microsoft.com/download/dotnet/10.0> (SDK, x64).
diff --git a/frontend-qt/nspb_qt/win/shim.py b/frontend-qt/nspb_qt/win/shim.py
index ddb83412..68876f85 100644
--- a/frontend-qt/nspb_qt/win/shim.py
+++ b/frontend-qt/nspb_qt/win/shim.py
@@ -679,6 +679,12 @@ if os.name == 'nt' and not os.environ.get('NSPB_SHIM_OFF'):
'''
+def _write_if_changed(path: Path, text: str) -> None:
+ data = text.encode('utf-8')
+ if not path.is_file() or path.read_bytes() != data:
+ path.write_bytes(data)
+
+
def install(shim_dir: Path, python_exe: str | None = None) -> None:
"""Write `sitecustomize.py` and the `.cmd` stand-ins into `shim_dir`.
@@ -695,9 +701,7 @@ def install(shim_dir: Path, python_exe: str | None = None) -> None:
body = _SITECUSTOMIZE_SRC.replace(
" _PKG = os.environ.get('NSPB_WIN_DIR') or _HERE\n",
' _PKG = os.environ.get(\'NSPB_WIN_DIR\') or ' + repr(pkg) + '\n')
- sc = shim_dir / SITECUSTOMIZE
- if not sc.is_file() or sc.read_text(encoding='utf-8') != body:
- sc.write_text(body, encoding='utf-8', newline='\n')
+ _write_if_changed(shim_dir / SITECUSTOMIZE, body)
py = python_exe or sys.executable
here = Path(pkg)
for name, target in (('xcrun', here / 'xcrun_shim.py'),
@@ -705,14 +709,10 @@ def install(shim_dir: Path, python_exe: str | None = None) -> None:
('xcodegen', here / 'xcodegen_shim.py')):
body_cmd = (f'@echo off\r\n'
f'"{py}" "{target}" %*\r\n')
- p = shim_dir / f'{name}.cmd'
- if not p.is_file() or p.read_text(encoding='utf-8', errors='replace') != body_cmd:
- p.write_text(body_cmd, encoding='utf-8', newline='')
+ _write_if_changed(shim_dir / f'{name}.cmd', body_cmd)
# a `python3.cmd` so the pipeline's `python3` spelling works in a shell too
- p = shim_dir / 'python3.cmd'
body_py = f'@echo off\r\n"{py}" %*\r\n'
- if not p.is_file() or p.read_text(encoding='utf-8', errors='replace') != body_py:
- p.write_text(body_py, encoding='utf-8', newline='')
+ _write_if_changed(shim_dir / 'python3.cmd', body_py)
def shim_dir() -> Path:
diff --git a/frontend-qt/tests/test_win.py b/frontend-qt/tests/test_win.py
index bae19c24..4939568d 100644
--- a/frontend-qt/tests/test_win.py
+++ b/frontend-qt/tests/test_win.py
@@ -607,12 +607,17 @@ class ShimTest(unittest.TestCase):
d = Path(td)
shim.install(d, python_exe=sys.executable)
first = {p.name: p.read_bytes() for p in d.iterdir()}
+ for p in d.iterdir():
+ os.utime(p, (1_000_000_000, 1_000_000_000))
+ mtimes = {p.name: p.stat().st_mtime_ns for p in d.iterdir()}
shim.install(d, python_exe=sys.executable)
second = {p.name: p.read_bytes() for p in d.iterdir()}
self.assertEqual(first, second)
- self.assertIn('sitecustomize.py', first)
+ self.assertEqual(mtimes, {p.name: p.stat().st_mtime_ns for p in d.iterdir()})
+ self.assertNotIn(b'\r', first['sitecustomize.py'])
for name in ('xcrun.cmd', 'xcodebuild.cmd', 'xcodegen.cmd', 'python3.cmd'):
- self.assertIn(name, first, f'{name} stand-in not written')
+ lines = first[name].splitlines(keepends=True)
+ self.assertTrue(lines and all(line.endswith(b'\r\n') for line in lines), name)
def test_sitecustomize_is_valid_python(self) -> None:
import ast
@@ -2008,7 +2013,7 @@ class VenvWheelsTest(unittest.TestCase):
ns: dict = {}
exec(compile(ast.fix_missing_locations(ast.Module(body=[fn], type_ignores=[])),
'<model>', 'exec'), ns)
- return ns['_pip_args']
+ return ns['_pip_args'].__func__
def test_offline_args_when_wheels_are_bundled(self) -> None:
args = self._pip_args_fn()(['lz4', 'nsz'], Path('C:/app/wheels'))
@@ -2036,7 +2041,7 @@ class VenvWheelsTest(unittest.TestCase):
ns: dict = {'sys': sys, 'Path': Path}
exec(compile(ast.fix_missing_locations(ast.Module(body=[fn], type_ignores=[])),
'<model>', 'exec'), ns)
- bundled_wheels = ns['bundled_wheels']
+ bundled_wheels = ns['bundled_wheels'].__func__
with tempfile.TemporaryDirectory() as td:
app_dir = Path(td) / 'NS Port Builder'
internal = app_dir / '_internal'
@@ -2169,7 +2174,7 @@ class InstallFailureHintTest(unittest.TestCase):
ns: dict = {}
exec(compile(ast.fix_missing_locations(ast.Module(body=[fn], type_ignores=[])),
'<model>', 'exec'), ns)
- classify = ns['_classify_install_failure']
+ classify = ns['_classify_install_failure'].__func__
self.assertEqual(classify('DownloadError: connection reset by peer'), 'dep.fix.network')
self.assertEqual(classify('URLError: operation timed out'), 'dep.fix.network')
self.assertEqual( classify('OSError: [Errno 28] No space left on device'), 'dep.fix.diskspace')