Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure UTF-8 encoding when communicating with a subprocess #8563

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/poetry/utils/env/base_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ def run_python_script(self, content: str, **kwargs: Any) -> str:
"-I",
"-W",
"ignore",
"-X",
"utf8",
"-",
input_=content,
stderr=subprocess.PIPE,
Expand All @@ -352,6 +354,7 @@ def _run(self, cmd: list[str], **kwargs: Any) -> str:
check=True,
env=env,
text=True,
encoding="utf-8",
**kwargs,
).stdout
elif call:
Expand Down
10 changes: 10 additions & 0 deletions tests/utils/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,16 @@ def test_run_python_script_only_stdout(tmp_path: Path, tmp_venv: VirtualEnv) ->
assert "some warning" not in output


def test_run_python_script_non_ascii_input(
tmp_path: Path, tmp_venv: VirtualEnv
) -> None:
output = tmp_venv.run_python_script(
"import sys; print('👎', file=sys.stderr); print('👍')"
)
assert "👍" in output
assert "👎" not in output


def test_create_venv_tries_to_find_a_compatible_python_executable_using_generic_ones_first( # noqa: E501
manager: EnvManager,
poetry: Poetry,
Expand Down