Skip to content

pc_checker: start Windows PowerShell by its full path for the GPU query - #5676

Open
sovljanskii wants to merge 1 commit into
ItsNotRexed:mainfrom
sovljanskii:pc-checker-powershell-path
Open

sovljanskii wants to merge 1 commit into
ItsNotRexed:mainfrom
sovljanskii:pc-checker-powershell-path

Conversation

@sovljanskii

Copy link
Copy Markdown
Contributor

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) asks Win32_VideoController for every adapter by starting "powershell". CreateProcess searches System32 but not System32\WindowsPowerShell\v1.0, so the bare name works only while that folder is on PATH. When it isn't, _run turns the FileNotFoundError into an empty string. The report then silently leaves out every GPU that nvidia-smi doesn't list: AMD, Intel, and any NVIDIA card nvidia-smi misses. The verdict comes back "unknown" or is based on the wrong GPU.

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. #3930 uses the same rule for make_game.py's runtime stage. pc_checker runs standalone, so it gets its own copy rather than importing make_game. Neither PR depends on the other.

Tests

New WindowsPowerShell tests in tests/test_pc_checker.py:

  • the full path under SystemRoot;
  • the windir fallback;
  • the bare name when the file isn't there;
  • detect_gpus with sys.platform patched to win32 in 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 --cli still detects the M4;
  • the ten tests/test_docs_*.py pass, compileall is clean, and git diff --check is 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 --cli on a Windows PC with an AMD or Intel GPU would be welcome.

AI-assisted.

  • No game data, keys or decryption.

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.
@neoisg8

neoisg8 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Verified locally on Windows 11 (Python 3.14, real Windows environment):

  1. Test Suite:
    • python -I tests/test_pc_checker.py: all 30 tests pass in 0.016s.
  2. Live CLI Check:
    • python -I tools/pc_checker.py --cli: ran live on Windows 11 host (13th Gen Intel Core i7-13650HX, NVIDIA GeForce RTX 4060 Laptop GPU (8 GB VRAM), 24 GB RAM). windows_powershell() successfully resolved C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe and performed the CIM query cleanly.
  3. Negative Control:
    • Running against unpatched main (commit 561b65a) reproduces 3 errors (AttributeError: module 'pc_checker' has no attribute 'windows_powershell') and 1 failure (['powershell'] != [exe]).
  4. Hygiene:
    • git diff --check is clean, line endings and compileall pass with 0. No game data.

LGTM!

AI-assisted.

@Darkz0rz

Copy link
Copy Markdown

Tested 96055c66 against main 561b65a8 on the case it fixes: a Windows 11 (build 26300) PC with an NVIDIA and a non-NVIDIA GPU (RTX 4090 + the Ryzen 7 9800X3D's AMD Radeon iGPU), Python 3.12.10. Pass. On main the AMD GPU silently disappears when PowerShell's folder isn't on PATH, and with this PR it stays.

pc_checker.detect_gpus() names, with the normal PATH and with every WindowsPowerShell entry removed from PATH:

normal PATH no WindowsPowerShell on PATH
main 561b65a8 RTX 4090, AMD Radeon(TM) Graphics RTX 4090 only
this PR RTX 4090, AMD Radeon(TM) Graphics RTX 4090, AMD Radeon(TM) Graphics

The 4090 survives on main only because nvidia-smi reports it. python -I tests/test_pc_checker.py: 30 OK.

AI-assisted: runs were done with Claude Code.

@kapitche

Copy link
Copy Markdown
Contributor

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 larpinguser left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@larpinguser

Copy link
Copy Markdown

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

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.

5 participants