Peach: Local-first video metadata scraper and media manager.
fix: 独立 Windows 包使用 UTF-8 启动日志
longmeidaodaac9c1d52b3
diff --git a/scripts/build_app_entry.py b/scripts/build_app_entry.pyindex bed352d29..0428c4d6d 100644--- a/scripts/build_app_entry.py+++ b/scripts/build_app_entry.py@@ -39,6 +39,10 @@ def _open_std_handle(handle_id: int):def _prepare_console() -> None:if os.name != "nt":return+ for stream in (sys.stdout, sys.stderr):+ reconfigure = getattr(stream, "reconfigure", None)+ if reconfigure is not None:+ reconfigure(encoding="utf-8", errors="backslashreplace")if sys.stdout is not None and sys.stderr is not None:returntry:diff --git a/scripts/build_windows.ps1 b/scripts/build_windows.ps1index 326f0d5cf..9101c9565 100644--- a/scripts/build_windows.ps1+++ b/scripts/build_windows.ps1@@ -56,7 +56,7 @@ if ($Standalone) {}& $Python -m PyInstaller --noconfirm --clean @BuildMode --windowed --name Peach `--distpath $BuildDestination --workpath $WorkPath --specpath $BuildPath `- --paths (Join-Path $ProjectRoot 'src') `+ --paths (Join-Path $ProjectRoot 'src') --python-option 'X utf8' `--collect-all curl_cffi --collect-all resvg_py `--hidden-import uvicorn.logging --hidden-import uvicorn.loops.auto `--hidden-import uvicorn.protocols.http.auto --hidden-import uvicorn.protocols.websockets.auto `diff --git a/tests/test_cli.py b/tests/test_cli.pyindex 7b0b45e92..0954b041a 100644--- a/tests/test_cli.py+++ b/tests/test_cli.py@@ -559,6 +559,16 @@ class PackagedEntryTests(unittest.TestCase):self.assertIn("follow", subcommands)self.assertEqual(subcommands, self.entry.cli_commands())+ def test_windows_redirected_console_accepts_chinese_startup_messages(self):+ output = io.BytesIO()+ stream = io.TextIOWrapper(output, encoding="cp1252", newline="\n")+ with mock.patch.object(self.entry.os, "name", "nt"), mock.patch.object(+ self.entry.sys, "stdout", stream+ ), mock.patch.object(self.entry.sys, "stderr", stream):+ self.entry._prepare_console()+ print("服务已启动", flush=True)+ self.assertEqual(output.getvalue(), "服务已启动\n".encode("utf-8"))+def test_tray_still_starts_when_the_first_argument_is_not_a_subcommand(self):self.assertFalse(self.entry.wants_cli(["peach.exe"]))self.assertFalse(self.entry.wants_cli(["peach.exe", "--tray-only"]))