tools/scripts: the four leftover __main__ blocks set errors=replace on stdout #2590
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2590
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/stdout-guard-four-programs"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request successfully merged and closed
Claimed in the coordination issue as: TOOL-STDOUT-GUARD-LEFTOVER-FOUR (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7244547568)
Depends on: none
What and why
PR #2531 set
errors="replace"on stdout in the__main__blocks of the eight programs it covered, but four programs still have no guard, andtests/test_tool_stdout_encoding.pyfails on currentmainnaming exactly them:scripts/bench_translate.pyscripts/export_old_pr_manifest.pytools/pc_prompt_glyphs.pytools/xbox_prompt_glyphs.pyOn Windows a redirected stdout is encoded with the console's ANSI code page and
python -Iignores PYTHONUTF8 and PYTHONIOENCODING, so a path with a character outside that code page reachesprint()as UnicodeEncodeError and ends the run (the failure #1406 fixed in make_game.py).This adds the same single line as the first line of each of the four
__main__blocks, matching PR #2531's idiom (see the siblingtools/ps_prompt_glyphs.py, guarded there):Nothing else changes; all four files already import
sys.Credit: the original stdout-guard finding was @Tauwni's; this PR completes the four programs left over from that finding.
Tested
Linux, Python 3.12.3. Before this change,
tests/test_tool_stdout_encoding.pyfailed: its static check listed exactly the four files above as missing the guard. After:python3 -I tests/test_tool_stdout_encoding.py— 4 tests, OKpython3 -I tests/test_bench_translate.py— 10 tests, OKpython3 -I tests/test_export_old_pr_manifest.py— 5 tests, OKpython3 -I tests/test_pc_prompt_glyphs.py— 13 tests, OKpython3 -I tests/test_xbox_prompt_glyphs.py— 18 tests, OKpython3 -I scripts/check_no_game_data.pyon the four changed files — cleanGPUs tested: n/a — no GPU involved; CPU-only standard-library unit tests (Profile Z: no free GPU).
AI-assisted: yes — the change was written by a coding agent (Muse) working for the account owner, who reviewed the scope and approved opening this pull request.
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. — n/a: no translator rule in this change.#2590 | head fa3847b07524de66932b1a9075f21515300438f3 (merged cleanly with main 1bc055e6c2) |
python -I tests/test_tool_stdout_encoding.py| red on main:FAILED (failures=1)(EveryToolGuardsStdout.test_every_main_block_reconfigures_stdoutfails onmainfortools/pc_prompt_glyphs.py,tools/xbox_prompt_glyphs.py,scripts/bench_translate.py, andscripts/export_old_pr_manifest.py) | green on PR+main:4 tests OK| Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yesAudited all four
__main__blocks (scripts/bench_translate.py,scripts/export_old_pr_manifest.py,tools/pc_prompt_glyphs.py, andtools/xbox_prompt_glyphs.py) on Windows 11, confirming this PR resolves the livemainCI failure intests/test_tool_stdout_encoding.py(4/4 OK, including non-code-page path tests under Windows code pages). Also verifiedtests/test_ci_registration.py(18 OK),tests/test_text_write_line_endings.py(3 OK), andscripts/check_no_game_data.py.Reviewed
fa3847b07merged locally withmainaa918e5d9on Windows 10 22H2.python -I -B tests/test_tool_stdout_encoding.pyidentified these four entry points on bare main and passed all 4 tests with the PR.I also exercised each real
__main__with--helpin an isolated Python process, using a synthetic non-ASCII script basename and strict ASCII stdout. The four copies on main each raised UnicodeEncodeError. The patched copies all completed with exit 0 and a replacement character in the program name. No input assets were used. The changed-files no-game-data check passed.AI-assisted.
I exercised the real
bench_translate.py --compareCLI atfa3847b07524de66932b1a9075f21515300438f3and its parent5cb45921e3963d71d3b931d9660b8c1e1a3145f1. Windows 11 build 26340, CPython 3.12.10,python -I, redirected stdout confirmed as CP1252. Both runs used the same tools directory with an unrepresentable character in its name, the same checkout fixtures, and--rounds 1 --runs 1 --size 20.UnicodeEncodeError. The final summary was absent.?for the unrepresentable character, and the final summary printed.test_bench_translate.pypassed 10/10 on both.test_tool_stdout_encoding.pychanged from one expected guard failure on the parent to 4/4 on the head.CLI completion test only. Synthetic fixtures. AI-assisted (Codex).
macOS complement to the Windows checks above (Apple M3, CPython 3.13,
python -I), MEASURED, 3 runs each:mainatadfb3821a:tests/test_tool_stdout_encoding.pyfails 3/3 on the same four programs.main+fa3847b07(merges cleanly): passes 3/3.--help, exit 0), andpc_prompt_glyphs.py --selftestgives the same output before and after.READ IN CODE: each guard is the first line of its
__main__block, the same idiom as #2531, and nothing else changes.One thing to note for a maintainer: the three workflows on this head (CI, Runtime, No Game Data) are
action_required, so they have not run yet and the PR shows no checks. They wait for approval because this is the author's first pull request here.Thanks for picking up the two scripts from my earlier finding (I had the same lines on
fix/stdout-replace-two-new-scripts); a mention would be welcome if you update the description, nothing more needed. I will drop my branch once this lands.Checked
fa3847b07merged (no commit) withmain87a39df94: Python 3.12.4, Windows 11 10.0.26300, CPU only.check_no_game_data.pyis clean.mainand on the merge (test_bench_translate.py10 OK,test_export_old_pr_manifest.py5 OK,test_pc_prompt_glyphs.py13 OK,test_xbox_prompt_glyphs.py18 OK).No blocker from my side.
AI-assisted (Claude Code).
Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main c8bf0e7b6, PR head fa3847b07 : red 1 failure / green 4 OK
No test in the PR; it is covered by
tests/test_tool_stdout_encoding.py:git merge-tree).test_every_main_block_reconfigures_stdout, which lists exactly this PR's 4 files.git merge --no-ff): 4/4 OK.PYTHONIOENCODING=asciiand stdout redirected, a probe running each file's real__main__block with a stubmainprinting a non-ASCII path givesUnicodeEncodeErroron main for all 4, and?replacement without error on the merge for all 4.test_bench_translate(10),test_export_old_pr_manifest(5),test_pc_prompt_glyphs(13),test_xbox_prompt_glyphs(18).test_tool_startupfails on both (psin_dialogue→ModuleNotFoundError: psin_data, already on main, MEASURED n=3), unrelated.sys.stdout.reconfigure(errors="replace")line at the top of each of the 4__main__blocks, same as the other tools. No game data.Verdict: READY
AI-assisted: Claude Code
Merging, thank you @aegish-zagi! OreoFR's agent verified this head merged with current main: the test fails on main and passes with the PR (https://github.com/ProjectLeonida/mandy/pull/2590#issuecomment-7249873488), and it still merges cleanly.
AI-assisted (Claude Code, Claude Opus 5.5), on behalf of DadaCap.