Skip to content

Commit c79692e

Browse files
committed
Fix Windows script wrappers for UTF-8 paths
1 parent 298068d commit c79692e

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

src/poetry/masonry/builders/editable.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636
sys.exit({callable_}())
3737
"""
3838

39-
WINDOWS_CMD_TEMPLATE = """\
40-
@echo off\r\n"{python}" "%~dp0\\{script}" %*\r\n
41-
"""
39+
# The .cmd wrapper is written as UTF-8. Switch cmd.exe to UTF-8 before it
40+
# parses paths so non-ASCII virtualenv locations are handled correctly.
41+
WINDOWS_CMD_TEMPLATE = (
42+
'@echo off\r\nchcp 65001 >nul\r\n"{python}" "%~dp0\\{script}" %*\r\n'
43+
)
4244

4345

4446
class EditableBuilder(Builder):

tests/masonry/builders/test_editable_builder.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,30 @@ def test_builder_installs_proper_files_for_standard_packages(
265265
assert tmp_venv._bin_dir.joinpath("fox").read_text(encoding="utf-8") == fox_script
266266

267267

268+
def test_builder_windows_cmd_wrapper_uses_utf8_code_page_for_non_ascii_paths(
269+
simple_poetry: Poetry, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
270+
) -> None:
271+
class WindowsScriptEnv(MockEnv):
272+
@property
273+
def python(self) -> Path:
274+
return Path(
275+
r"C:\Users\jmoni\OneDrive\Área de Trabalho\example\.venv\Scripts\python.exe"
276+
)
277+
278+
env = WindowsScriptEnv(path=tmp_path / "Área de Trabalho" / ".venv")
279+
python = env.python
280+
281+
monkeypatch.setattr("poetry.masonry.builders.editable.WINDOWS", True)
282+
283+
builder = EditableBuilder(simple_poetry, env, NullIO())
284+
builder._add_scripts()
285+
286+
assert (
287+
env.script_dirs[0].joinpath("foo.cmd").read_bytes()
288+
== (f'@echo off\r\nchcp 65001 >nul\r\n"{python}" "%~dp0\\foo" %*\r\n').encode()
289+
)
290+
291+
268292
def test_builder_falls_back_on_setup_and_pip_for_packages_with_build_scripts(
269293
mocker: MockerFixture, extended_poetry: Poetry, tmp_path: Path
270294
) -> None:

0 commit comments

Comments
 (0)