[PR #1553] character_textures: fix None/zero/dict-param classification, unknown_slots count, and atomic I/O (CHARACTER-TEXTURES-CLASSIFICATION-AND-IO) #1578

Open
opened 2026-11-26 20:21:44 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1553
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/character-textures-classification-io


📝 Commits (1)

  • 896fe7a character_textures: fix None/zero/dict-param classification, unknown_slots count, and atomic I/O

📊 Changes

2 files changed (+113 additions, -16 deletions)

View changed files

📝 tests/test_character_textures.py (+63 -0)
📝 tools/character_textures.py (+50 -16)

📄 Description

What

Fix four classification/summary bugs and harden --json/--csv I/O in tools/character_textures.py:

  1. Missing texture name serialized as literal "None" (_texture_name):
    • When a binding had no name/texture/key/id64 field (or a None entry), _first(...) returned None and _texture_name(None) ran str(None) -> "None" instead of "-". Return "-" when value is None.
  2. Falsy material name 0 discarded (classify_material):
    • _first() explicitly preserves 0 and False as values, not gaps, but _first(material, MATERIAL_NAME_KEYS) or f"material[{index}]" discarded 0 and renamed it to "material[0]". Check is not None before falling back.
  3. Dict-form Textures clobbered explicit lowercase param/slot/hash (texture_bindings):
    • binding.setdefault("Param", slot) inserted "Param" (which precedes "param"/"slot"/"hash" in PARAM_KEYS) even when the entry dict already carried a lowercase slot key, overwriting the entry's own slot with the outer dict key. Only set "Param" when _first(binding, PARAM_KEYS) is None.
  4. summary["unknown_slots"] missed bindings without a valid Param (build_report):
    • Counting only b["role"].startswith("unknown 0x") skipped bindings with missing/malformed Param (role == "unknown"). Count both "unknown" and "unknown 0x...".
  5. CLI empty/whitespace --json/--csv validation & atomic writes (write_json, write_csv, main):
    • Reject empty or whitespace-only --json/--csv paths via parser.error(...) instead of silently ignoring "" or creating a whitespace-named file (" ").
    • Write JSON (allow_nan=False, trailing "\n") and CSV (newline="") atomically through sibling temp files with file_mode.published_mode and replace_retry.replace, preserving existing files on failure.
    • Accept optional argv=None in main(argv=None).

Claimed in the coordination issue as

CHARACTER-TEXTURES-CLASSIFICATION-AND-IO — verified 0 open PRs and 0 prior claims; unable to post a comment on #14 because GitHub disabled commenting once #14 reached its 2,500-comment cap (and no successor "Coordinating who works on what" issue is open yet).

Testing

  • python3 -I -W error tests/test_character_textures.py -v: 18/18 OK (including 3 new regression tests).

  • python3 -I tests/test_text_write_line_endings.py: 3/3 OK.

  • python3 -I scripts/check_no_game_data.py tools/character_textures.py tests/test_character_textures.py: clean.

  • python3 -m compileall -q tools/character_textures.py tests/test_character_textures.py: clean.

  • Mutation check against unpatched main:tools/character_textures.py: all 3 new tests fail on main (FAILED (failures=6, errors=1)).

  • AI-assisted: yes

  • GPUs tested: none (CPU-only JSON/CSV texture classification tests on macOS; no GPU or game files needed)


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1553 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/character-textures-classification-io` --- ### 📝 Commits (1) - [`896fe7a`](https://github.com/ubiquitarianism/leonida/commit/896fe7ad39b37fd56f1e0612055090ad177402b2) character_textures: fix None/zero/dict-param classification, unknown_slots count, and atomic I/O ### 📊 Changes **2 files changed** (+113 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_character_textures.py` (+63 -0) 📝 `tools/character_textures.py` (+50 -16) </details> ### 📄 Description ## What Fix four classification/summary bugs and harden `--json`/`--csv` I/O in `tools/character_textures.py`: 1. **Missing texture name serialized as literal `"None"` (`_texture_name`)**: - When a binding had no name/texture/key/id64 field (or a `None` entry), `_first(...)` returned `None` and `_texture_name(None)` ran `str(None)` -> `"None"` instead of `"-"`. Return `"-"` when `value is None`. 2. **Falsy material name `0` discarded (`classify_material`)**: - `_first()` explicitly preserves `0` and `False` as values, not gaps, but `_first(material, MATERIAL_NAME_KEYS) or f"material[{index}]"` discarded `0` and renamed it to `"material[0]"`. Check `is not None` before falling back. 3. **Dict-form `Textures` clobbered explicit lowercase `param`/`slot`/`hash` (`texture_bindings`)**: - `binding.setdefault("Param", slot)` inserted `"Param"` (which precedes `"param"`/`"slot"`/`"hash"` in `PARAM_KEYS`) even when the entry dict already carried a lowercase slot key, overwriting the entry's own slot with the outer dict key. Only set `"Param"` when `_first(binding, PARAM_KEYS) is None`. 4. **`summary["unknown_slots"]` missed bindings without a valid `Param` (`build_report`)**: - Counting only `b["role"].startswith("unknown 0x")` skipped bindings with missing/malformed `Param` (`role == "unknown"`). Count both `"unknown"` and `"unknown 0x..."`. 5. **CLI empty/whitespace `--json`/`--csv` validation & atomic writes (`write_json`, `write_csv`, `main`)**: - Reject empty or whitespace-only `--json`/`--csv` paths via `parser.error(...)` instead of silently ignoring `""` or creating a whitespace-named file (`" "`). - Write JSON (`allow_nan=False`, trailing `"\n"`) and CSV (`newline=""`) atomically through sibling temp files with `file_mode.published_mode` and `replace_retry.replace`, preserving existing files on failure. - Accept optional `argv=None` in `main(argv=None)`. ## Claimed in the coordination issue as `CHARACTER-TEXTURES-CLASSIFICATION-AND-IO` — verified 0 open PRs and 0 prior claims; unable to post a comment on `#14` because GitHub disabled commenting once `#14` reached its 2,500-comment cap (and no successor `"Coordinating who works on what"` issue is open yet). ## Testing - `python3 -I -W error tests/test_character_textures.py -v`: **18/18 OK** (including 3 new regression tests). - `python3 -I tests/test_text_write_line_endings.py`: **3/3 OK**. - `python3 -I scripts/check_no_game_data.py tools/character_textures.py tests/test_character_textures.py`: clean. - `python3 -m compileall -q tools/character_textures.py tests/test_character_textures.py`: clean. - Mutation check against unpatched `main:tools/character_textures.py`: all 3 new tests fail on `main` (`FAILED (failures=6, errors=1)`). - AI-assisted: yes - GPUs tested: none (CPU-only JSON/CSV texture classification tests on macOS; no GPU or game files needed) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1578
No description provided.