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

Open
github-bot wants to merge 1 commit from github-bot/gh-1553 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 04:21 UTC · original
IlyassRS3:fix/character-textures-classification-io → main · +113 −16 · 2 files · 1 commits · open

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)

**@⁠IlyassRS3** on GitHub · 2026-11-25 04:21 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1553) `IlyassRS3:fix/character-textures-classification-io` → `main` · +113 −16 · 2 files · 1 commits · open ## 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:56:22 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 04:21 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 04:21 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1553#pullrequestreview-6051819327) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1553/head:github-bot/gh-1553'
git switch 'github-bot/gh-1553'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1553'
git switch 'github-bot/gh-1553'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1553'
git switch 'github-bot/gh-1553'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1553'
git switch 'main'
git merge --squash 'github-bot/gh-1553'
git switch 'main'
git merge --ff-only 'github-bot/gh-1553'
git switch 'main'
git merge 'github-bot/gh-1553'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.