Skip to content

Build.bat: start make_game.py by the interpreter's full path - #7616

Open
Daniromavi wants to merge 1 commit into
ItsNotRexed:mainfrom
Daniromavi:build-bat-real-python
Open

Daniromavi wants to merge 1 commit into
ItsNotRexed:mainfrom
Daniromavi:build-bat-real-python

Conversation

@Daniromavi

Copy link
Copy Markdown

Claim: #7496 (comment)

What changed and why

On a PC with only the Python install manager (python.org's default Windows installer since 3.14), py is an app execution alias in WindowsApps, like python. A Python started through either alias, and every program that Python starts, does not see folders that other programs create under %LOCALAPPDATA% or %APPDATA%. #1233 measured this for python and found py fine there; with the install manager's own py, Build.bat's py -3.x hits it too, and the appdata_hint advice "start make_game.py with py" does not help.

  • Build.bat: a new :resolve_python, called before make_game.py starts, asks the interpreter for sys.executable and uses that full path as PY. The path is printed in the console's code page so that for /f reads a non-ASCII one back intact; when nothing usable comes back, PY stays as it was.
  • make_game.py: appdata_hint names this interpreter's full path instead of py.
  • docs/design.md: the AppData note says which launchers see the folder.

Measured

Windows 11 26200, Python 3.14.4, PythonManager 26.4.240.0, a folder created under %LOCALAPPDATA% by another process:

Started as Sees it
python (WindowsApps alias) False
py (WindowsApps alias) False
pythoncore-3.14-64\python.exe by its full path True
sys.executable started by an alias-started Python False

Build.bat itself, with a stand-in make_game.py that checks such a folder: main False, this branch True.

Tests

  • New tests/test_build_bat_python.py (Windows only, cmd.exe) runs :resolve_python as written, with launchers standing in for the aliases: a quoted launcher path, a bare command with an argument (as py -3.14), the full path left as is, a non-ASCII venv path (this case fails if the code-page step is removed), and no or a nonexistent path keeps PY.
  • tests/test_make_game_preflight.py: the hint names sys.executable, not py (96 tests OK).
  • Full standard-library suite on Windows 11, Python 3.14.4: the same failures as main at 86a7807, all pre-existing and unrelated; none new. compileall and scripts/check_no_game_data.py are clean. No GPU or game files needed.

AI-assisted.

The Python install manager's `py` is an app execution alias in WindowsApps,
like its `python`. A Python started through either alias, and every program
it starts, does not see folders that other programs create under
%LOCALAPPDATA% or %APPDATA% (ItsNotRexed#1233 measured `python` only). So Build.bat's
`py -3.x` had the problem too, and the appdata_hint advice to start
make_game.py with `py` did not help.

Build.bat now resolves PY to sys.executable before it starts make_game.py,
printed in the console code page so that for /f reads a non-ASCII path back
intact; when nothing usable comes back, PY stays as it was. The hint names
that full path, and docs/design.md says which launchers see the folder.

Measured on Windows 11 26200, Python 3.14.4, PythonManager 26.4.240.0:
Build.bat with a stand-in make_game.py that checks a new %LOCALAPPDATA%
folder: main False, this change True.
@yuruiwang233

Copy link
Copy Markdown

Windows check + review. Read the diff and ran it locally; not a code-read-only review.

Environment: Windows 11, CPython 3.13.1, PR head 68cdfa4, console code page 65001.

  • python -I tests/test_build_bat_python.py -> Ran 5 tests, OK
  • python -I tests/test_make_game_preflight.py -> Ran 96 tests, OK (1 skipped)
  • python -m compileall -q make_game.py tools tests -> clean

The block itself behaves as intended for a quoted full path, a quoted launcher and a bare launcher -3.14: PY becomes the quoted sys.executable, and it stays put when the child fails or names a path that does not exist. The block-extraction test is a nice way to pin Build.bat and its test together.

One problem: test_a_non_ascii_interpreter_path_comes_back_intact is tied to the console code page. Running the same command after chcp 936 (the default console code page on zh-CN Windows) gives 4 passed, 1 failed:

FAIL: test_a_non_ascii_interpreter_path_comes_back_intact
AssertionError: False is not true : ("...\launch dir\python.cmd", "...\P… ñ\Scripts\python.exe")

The cause is the product doing the right thing: "Pé ñ".encode("cp936") raises UnicodeEncodeError for é (é is not in GBK either), so the child prints nothing, the for /f sees no line, and PY correctly stays the launcher. The test then asserts the swap that cannot happen under that code page.

Suggestion: build the venv folder name from the console code page instead of hard-coding Pé ñ (Chinese characters for 936, Cyrillic for 866, ...), or skip that subtest when the chosen name cannot be encoded in GetConsoleOutputCP(). That pins the real contract: swap when the path is representable, keep PY otherwise.

Related and worth one sentence in the block comment or docs/design.md: a sys.executable whose characters are not in the console code page keeps the alias, so the AppData visibility problem that this change fixes still applies there. Not something I would block on, but it is the one hole in an otherwise careful fallback.

@airp1ane

Copy link
Copy Markdown
Contributor

Tested 68cdfa4 on Windows 11, Python 3.15.2, NVIDIA RTX 4060 Ti (driver 621.24; CPU-only checks, no game files, no GPU/llvm-mc/MSVC used): pass.

Ran the test files this PR adds or changes, from a clean checkout of the PR head: test_build_bat_python.py, test_make_game_preflight.py - all exit 0.

AI-assisted (Claude Code).

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.

3 participants