Skip to content

leonida_tui's log names its newline; import_call_sites and world_drawable_lookup/verify guard stdout (lint tests red on main) - #7046

Closed
Mob1K7105 wants to merge 1 commit into
ItsNotRexed:mainfrom
Mob1K7105:lint-newline-stdout-guards
Closed

Mob1K7105 wants to merge 1 commit into
ItsNotRexed:mainfrom
Mob1K7105:lint-newline-stdout-guards

Conversation

@Mob1K7105

Copy link
Copy Markdown

Claimed in the coordination issue: #6750 (comment)

What and why

Two repository-wide lint tests are red on main (cb168f46) because of files merged today:

  • tests/test_text_write_line_endings.py flags tools/leonida_tui.py:753: the run log Speed up make_game by overlapping stages and showing progress. #1797 added is opened in text mode without newline=, so it is CRLF on Windows. It now opens with newline="\n" (CONTRIBUTING.md's rule for a file a tool writes).
  • tests/test_tool_stdout_encoding.py flags tools/import_call_sites.py, tools/world_drawable_lookup.py and tools/world_drawable_verify.py, whose __main__ blocks lack the sys.stdout.reconfigure(errors="replace") guard. Each gets the same guard and comment as the other tools (e.g. tools/bvh_index.py).

Left to the PRs that already fix them: tools/f64_omod_probe.py:268 (#6597) and tools/bvh_slot_check.py (#6508). With those two, both tests pass.

Tested

  • tests/test_text_write_line_endings.py and tests/test_tool_stdout_encoding.py: only the two items above remain (they listed 2 and 4 on main).
  • tests/test_leonida_tui.py, test_import_call_sites.py, test_world_drawable_lookup.py, test_world_drawable_verify.py: pass. compileall and git diff --check clean.
  • Linux, Python 3.14.10. No GPU or game files involved.

AI-assisted: yes (Claude Code).

  • No game data, keys or decryption.

🤖 Generated with Claude Code

tests/test_text_write_line_endings.py flagged the log file ItsNotRexed#1797 added to
tools/leonida_tui.py (opened without newline=, so CRLF on Windows), and
tests/test_tool_stdout_encoding.py flagged import_call_sites.py,
world_drawable_lookup.py and world_drawable_verify.py, added today
without the stdout reconfigure guard the other tools carry.
f64_omod_probe.py (ItsNotRexed#6597) and bvh_slot_check.py (ItsNotRexed#6508) already have PRs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tikD1337

Copy link
Copy Markdown
Contributor

No blocking correctness issues found in the four-file diff. The changes correctly apply the repository’s text-output conventions, and the 35 targeted tests pass on Windows with CPython 3.13. The repository-wide lint suites still have two pre-existing failures outside this diff, detailed below.

tools/leonida_tui.py now opens the stage log with newline="\n", matching the rule in CONTRIBUTING.md. StageConsole.write_line() already strips trailing CR/LF characters and appends one "\n"; the explicit newline setting prevents Windows text-mode output from translating that terminator to CRLF. UTF-8 encoding, append mode, locking, flushing, and the in-memory log buffer retain their existing behavior. An additional raw-byte check confirmed that writing lines ending in CRLF and LF produces exactly b"alpha\nbeta\n" on disk. Existing log contents are preserved when reopening in append mode.

tools/import_call_sites.py, tools/world_drawable_lookup.py, and tools/world_drawable_verify.py now set sys.stdout.reconfigure(errors="replace") before invoking their CLI entry points. This addresses UnicodeEncodeError when redirected stdout uses a Windows code page that cannot represent an output character. Changing only the error handler preserves the selected encoding; a separate CP1252 check confirmed that an unrepresentable character becomes ?.

The guards are appropriately confined to __main__, so importing these modules does not reconfigure the caller’s stdout. Catching AttributeError, ValueError, and OSError makes setup tolerant of streams without reconfigure(), closed streams, and I/O failures during reconfiguration. These exceptions surround only configuration; exceptions from the tools’ actual work retain their existing behavior. Import scanning, drawable candidate selection, verification classifications, argument parsing, and exit handling are unchanged.

The replacement policy is intentionally lossy for human-readable stdout: an unrepresentable character may appear as ?. The three JSON output paths use json.dumps() with its default ensure_ascii=True, so Unicode values remain represented through ASCII escapes rather than being replaced during encoding. The guard remains best-effort for custom stdout implementations; it does not guarantee that subsequent writes to an unusable stream succeed.

Verification required no game files. The supplied Windows 11 / CPython 3.13 verification reports these checks passing:

Check Result
git diff --check PASS
python -m compileall -q make_game.py tools tests PASS
check_no_game_data.py PASS
python -I make_game.py --help PASS
tests/test_leonida_tui.py 24 tests passed
tests/test_import_call_sites.py 8 tests passed
tests/test_world_drawable_lookup.py 1 test passed
tests/test_world_drawable_verify.py 2 tests passed

Independent reruns with CPython 3.13.14 also passed the four targeted suites, compilation, help invocation, and game-data check. The targeted suites cover TUI logging and console behavior, synthetic PE import analysis, drawable candidate filtering, and verification joins and bounds checks. The raw-byte newline and CP1252 replacement checks described above also passed.

The additional repository-wide checks remain red:

  • tests/test_text_write_line_endings.py: tools/f64_omod_probe.py:268 opens a text writer without newline=.
  • tests/test_tool_stdout_encoding.py: tools/bvh_slot_check.py lacks the required stdout guard.

Both offending sites exist unchanged in the parent commit. Neither failure identifies a remaining violation in these four changed files. The targeted tests also do not establish subprocess-level coverage of every new entry-point guard; the encoding behavior check and repository-wide static guard check provide complementary evidence. A full green lint result should not be claimed for this revision.

The diff complies with the project’s restrictions: it adds no game data or game-derived fixtures, introduces no keys, decryption or protection workarounds, and adds no online-service access. It follows the fix-don’t-disable rule by correcting output behavior while preserving validation and lint enforcement. No shader-translator rule or runtime contract changes, GPU/driver testing, or MSVC/Ninja build are needed for this Python-only change.

AI-assisted.

@Mob1K7105

Copy link
Copy Markdown
Author

Closing as a duplicate of #7032 (the three stdout guards) and #7033 (leonida_tui's log newline), both opened first; my claim went to the already-closed coordination thread #6750, so I missed them. Sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants