Fix Windows script wrappers for UTF-8 paths#10946
Conversation
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Consider capturing the original console code page and restoring it after invoking Python so that the wrapper doesn’t leave the terminal permanently switched to UTF-8 as a side effect.
- The hard-coded
C:\Users\jmoni\...path in the test looks personal and slightly brittle; using a more generic ortmp_path-derived Windows-style path with non-ASCII components would keep the intent while avoiding user-specific details.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider capturing the original console code page and restoring it after invoking Python so that the wrapper doesn’t leave the terminal permanently switched to UTF-8 as a side effect.
- The hard-coded `C:\Users\jmoni\...` path in the test looks personal and slightly brittle; using a more generic or `tmp_path`-derived Windows-style path with non-ASCII components would keep the intent while avoiding user-specific details.
## Individual Comments
### Comment 1
<location path="src/poetry/masonry/builders/editable.py" line_range="39-41" />
<code_context>
-WINDOWS_CMD_TEMPLATE = """\
-@echo off\r\n"{python}" "%~dp0\\{script}" %*\r\n
-"""
+# The .cmd wrapper is written as UTF-8. Switch cmd.exe to UTF-8 before it
+# parses paths so non-ASCII virtualenv locations are handled correctly.
+WINDOWS_CMD_TEMPLATE = (
+ '@echo off\r\nchcp 65001 >nul\r\n"{python}" "%~dp0\\{script}" %*\r\n'
+)
</code_context>
<issue_to_address>
**question:** Consider whether unconditionally forcing code page 65001 is safe for all environments that use this wrapper.
Changing the active code page will affect all subsequent commands in that `cmd.exe` session (including subprocesses spawned by Python). Given this wrapper runs in diverse contexts (CI, editors, etc.), please verify that always running `chcp 65001` won’t break cases that rely on a non‑UTF‑8 console. If that’s a risk, consider gating this behind an env flag or only enabling it when non‑ASCII paths are detected.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| # The .cmd wrapper is written as UTF-8. Switch cmd.exe to UTF-8 before it | ||
| # parses paths so non-ASCII virtualenv locations are handled correctly. | ||
| WINDOWS_CMD_TEMPLATE = ( |
There was a problem hiding this comment.
question: Consider whether unconditionally forcing code page 65001 is safe for all environments that use this wrapper.
Changing the active code page will affect all subsequent commands in that cmd.exe session (including subprocesses spawned by Python). Given this wrapper runs in diverse contexts (CI, editors, etc.), please verify that always running chcp 65001 won’t break cases that rely on a non‑UTF‑8 console. If that’s a risk, consider gating this behind an env flag or only enabling it when non‑ASCII paths are detected.
|
Related Knowledge 1 document with suggested updates is ready for review. Python Poetry CHANGELOG
|
c79692e to
97e6fcf
Compare
|
Calling |
Pull Request Check List
Fixes #10193
Summary
Editable installs on Windows write
.cmdscript wrappers as UTF-8. When those wrappers are launched from a non-UTF-8 console code page, non-ASCII paths can be mojibake beforecmd.exeinvokes Python.This changes the generated
.cmdwrapper to switchcmd.exeto UTF-8 before the command containing the Python/script paths is parsed, and adds a regression test covering a Windows-style path containingÁrea de Trabalho.