Repository navigation
pc_checker: start Windows PowerShell by its full path for the GPU query - #5676
sovljanskii wants to merge 1 commit into
Conversation
detect_gpus asks Win32_VideoController for every adapter through "powershell". CreateProcess searches System32 but not System32\WindowsPowerShell\v1.0, so the bare name works only while that folder is on PATH. Where it isn't, _run turns the FileNotFoundError into an empty string and the report silently leaves out every GPU that nvidia-smi doesn't list (AMD, Intel, and any NVIDIA card nvidia-smi misses). windows_powershell() resolves %SystemRoot% (then %windir%, then C:\Windows) to System32\WindowsPowerShell\v1.0\powershell.exe, and keeps the bare name where the file isn't at its usual place. This is the same rule ItsNotRexed#3930 uses for make_game.py's runtime stage. pc_checker runs on its own, so it has its own copy instead of importing make_game. The new WindowsPowerShell tests cover: - the full path under SystemRoot; - the windir fallback; - the bare-name fallback; - detect_gpus with sys.platform patched to win32 in the module, which checks that the CIM query starts the full path and that its adapter is reported. Without the change, those tests give 3 errors and 1 failure. test_pc_checker gives 30 OK on Python 3.15.2, 3.14.10 and 3.12.16 on macOS (Apple M4), and pc_checker --cli still reports the M4.
|
Verified locally on Windows 11 (Python 3.14, real Windows environment):
LGTM! AI-assisted. |
|
Tested
The 4090 survives on AI-assisted: runs were done with Claude Code. |
|
Tested 96055c6 merged with main 561b65a on Linux (WSL2) Python 3.12.16 (-I) and Windows 11 Python 3.13.1: pass tests/test_pc_checker.py: Linux 30 run, 30 passed, 0 failed; Windows 30 run, 30 passed, 0 failed. Negative control: with tools/pc_checker.py from main, the same file gives 1 failure + 3 errors on Linux (the 4 new WindowsPowerShell tests). Native check on the case it fixes (RTX 4080 SUPER + Intel UHD 770 PC): windows_powershell() returns C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe, and detect_gpus() with PATH reduced to C:\Windows\System32 (no PowerShell folder) returns 2 GPUs plus 2 virtual monitors (Intel UHD 770 included) with the PR; main's detect_gpus() with the same PATH returns only the NVIDIA GPU, so the Intel one is dropped silently as the PR describes. Diff read: only tools/pc_checker.py and its test change, the only powershell call in the file is the one replaced. |
larpinguser
left a comment
There was a problem hiding this comment.
Summary
Adds windows_powershell() to pc_checker.py: it resolves PowerShell 5.1 at %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe (falling back to windir, then C:\Windows), or the bare name if that file is elsewhere. detect_gpus() uses it for its WMI query, so GPUs beyond nvidia-smi's report are no longer silently dropped when that folder is off PATH. Four tests cover resolution paths and GPU detection.
Why merge
Fixes silent under-reporting of GPUs on Windows machines with a nonstandard PATH, with full test coverage.
Verdict: Approve
SummaryAdds Why mergeFixes silent under-reporting of GPUs on Windows machines with a nonstandard PATH, with full test coverage. Verdict: Approve |
Claimed in the coordination issue: claim in #5361. There is no item ID yet. The problem was noted in the #3965 re-review.
What and why
On Windows,
detect_gpus(tools/pc_checker.py) asksWin32_VideoControllerfor every adapter by starting"powershell".CreateProcesssearchesSystem32but notSystem32\WindowsPowerShell\v1.0, so the bare name works only while that folder is on PATH. When it isn't,_runturns theFileNotFoundErrorinto an empty string. The report then silently leaves out every GPU thatnvidia-smidoesn't list: AMD, Intel, and any NVIDIA cardnvidia-smimisses. The verdict comes back "unknown" or is based on the wrong GPU.windows_powershell()resolves%SystemRoot%(then%windir%, thenC:\Windows) toSystem32\WindowsPowerShell\v1.0\powershell.exe, and keeps the bare name where the file isn't at its usual place. #3930 uses the same rule formake_game.py's runtime stage.pc_checkerruns standalone, so it gets its own copy rather than importingmake_game. Neither PR depends on the other.Tests
New
WindowsPowerShelltests intests/test_pc_checker.py:SystemRoot;windirfallback;detect_gpuswithsys.platformpatched towin32in the module only. It checks that the CIM query starts the full path and that the adapter it returns is reported.Without the change, these give 3 errors and 1 failure.
Tested on macOS 27.2, Apple M4 (CPU only; no GPU involved):
python -I tests/test_pc_checker.py: 30 OK on Python 3.15.2, 3.14.10 and 3.12.16;python -I tools/pc_checker.py --clistill detects the M4;tests/test_docs_*.pypass,compileallis clean, andgit diff --checkis clean.Not run on Windows. The Windows path is exercised only through the patched test, so a run of
python -I tools/pc_checker.py --clion a Windows PC with an AMD or Intel GPU would be welcome.AI-assisted.