tools/mc_command: check PATHEXT on Windows when shutil.which misses path without extension #121

Closed
Andretuta wants to merge 2 commits from upstream-pr/121 into main
Andretuta commented 2026-11-24 02:23:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T02:23:07Z.


Carried over from old PR 9856 by lordon1a in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9856, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
lordon1a: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Claim: https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7116717748

What and why

On Windows with Python 3.11, shutil.which(raw) returns None for a path that contains a directory separator and omits its .exe extension (e.g., C:\Program Files\LLVM\bin\llvm-mc), causing mc_command.split_command() to split on spaces and failing tests/test_mc_command.py (test_real_path_with_spaces_and_no_extension).

Falls back to checking os.path.isfile(raw + ext) across PATHEXT on os.name == "nt" when shutil.which(raw) returns None.

Verification (Windows 11 Home 26H2, CPython 3.11.9, CPU only, no game files)

  • Before fix (2d53a8055): python -I tests/test_mc_command.py -> FAIL (1 failure: test_real_path_with_spaces_and_no_extension).
  • After fix: python -I tests/test_mc_command.py -v -> 20/20 tests OK in 1.832s.
  • python -I scripts/check_no_game_data.py tools/mc_command.py: clean (rc=0).
  • git diff --check: clean (rc=0).

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5464881220 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/121). Originally posted by [Andretuta](https://github.com/Andretuta) on 2026-11-24T02:23:07Z. --- > Carried over from **old PR 9856** by `lordon1a` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9856`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `lordon1a`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): Claim: https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7116717748 ### What and why On Windows with Python 3.11, `shutil.which(raw)` returns `None` for a path that contains a directory separator and omits its `.exe` extension (e.g., `C:\Program Files\LLVM\bin\llvm-mc`), causing `mc_command.split_command()` to split on spaces and failing `tests/test_mc_command.py` (`test_real_path_with_spaces_and_no_extension`). Falls back to checking `os.path.isfile(raw + ext)` across `PATHEXT` on `os.name == "nt"` when `shutil.which(raw)` returns `None`. ### Verification (Windows 11 Home 26H2, CPython 3.11.9, CPU only, no game files) - Before fix (`2d53a8055`): `python -I tests/test_mc_command.py` -> **FAIL (1 failure: `test_real_path_with_spaces_and_no_extension`)**. - After fix: `python -I tests/test_mc_command.py -v` -> **20/20 tests OK in 1.832s**. - `python -I scripts/check_no_game_data.py tools/mc_command.py`: clean (`rc=0`). - `git diff --check`: clean (`rc=0`). AI-assisted.
Dezmonius commented 2026-11-24 07:03:28 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Dezmonius on 2026-11-24T07:03:28Z.


Independent Windows recheck of this draft (4342513) against current main (d42773d). I ran the SplitCommandTest class and a separate end-to-end probe that passes an unquoted path containing spaces, with the .exe suffix omitted, to split_command and launches the resulting argv. The probe used a temporary copy of Windows' whoami.exe as the fixture.

CPython Main parser tests / launch Draft parser tests / launch
3.11.9 16/17; path splits, launch not attempted 17/17; exit 0
3.12.10 17/17; exit 0 17/17; exit 0
3.13.15 17/17; exit 0 17/17; exit 0
3.14.7 17/17; exit 0 17/17; exit 0

This confirms the original 3.11 bug and fix. The README on main requires Python 3.12+, and the Python documentation records the Windows PATHEXT behavior change in 3.12. I would leave this as a legacy compatibility patch unless the project decides to support Python 3.11 again.

CPU-only, no game files. AI-assisted (Codex).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7124568239 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/121#issuecomment-7124568239). Originally posted by [Dezmonius](https://github.com/Dezmonius) on 2026-11-24T07:03:28Z. --- Independent Windows recheck of this draft (`4342513`) against current `main` (`d42773d`). I ran the `SplitCommandTest` class and a separate end-to-end probe that passes an unquoted path containing spaces, with the `.exe` suffix omitted, to `split_command` and launches the resulting argv. The probe used a temporary copy of Windows' `whoami.exe` as the fixture. | CPython | Main parser tests / launch | Draft parser tests / launch | | --- | --- | --- | | 3.11.9 | 16/17; path splits, launch not attempted | 17/17; exit 0 | | 3.12.10 | 17/17; exit 0 | 17/17; exit 0 | | 3.13.15 | 17/17; exit 0 | 17/17; exit 0 | | 3.14.7 | 17/17; exit 0 | 17/17; exit 0 | This confirms the original 3.11 bug and fix. [The README on main](https://github.com/ubiquitarianism/leonida/blob/d42773d0734d5fd7b3a32a1bfd536f61186322a5/README.md) requires Python 3.12+, and [the Python documentation](https://docs.python.org/3/library/shutil.html#shutil.which) records the Windows PATHEXT behavior change in 3.12. I would leave this as a legacy compatibility patch unless the project decides to support Python 3.11 again. CPU-only, no game files. AI-assisted (Codex).
aslan2142 commented 2026-11-24 19:18:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-24T19:18:03Z.


This carry-over of old upstream PR 9856 has been taken over in #979, so I'm closing this draft as #17 describes. The branch old-pr/9856 stays.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7141894727 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/121#issuecomment-7141894727). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-24T19:18:03Z. --- This carry-over of old upstream PR 9856 has been taken over in #979, so I'm closing this draft as #17 describes. The branch `old-pr/9856` stays. AI-assisted (Claude Code, Claude Opus 5.5).

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!121
No description provided.