Skip to content
Merged
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
1 change: 1 addition & 0 deletions docs/changelog.d/+backend-output-encoding.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Stop the backend from crashing when it prints a path its standard output encoding cannot represent.
2 changes: 2 additions & 0 deletions src/pyproject_api/_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,6 @@ def read_line(fd=0):


if __name__ == "__main__":
# printed paths may hold characters the stdout encoding cannot represent
sys.stdout.reconfigure(errors="backslashreplace") # type: ignore[unresolved-attribute] # stub says TextIO
sys.exit(run(sys.argv[1:]))
15 changes: 13 additions & 2 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import subprocess # ruff:ignore[suspicious-subprocess-import]
import sys
from textwrap import dedent
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, Final

import pytest

from pyproject_api import _backend
from pyproject_api import SubprocessFrontend, _backend
from pyproject_api._backend import BackendProxy, read_line, run

if TYPE_CHECKING:
Expand Down Expand Up @@ -222,3 +222,14 @@ def test_read_line_eof_at_the_beginning() -> None:
read_line(fd=r)
finally:
os.close(r)


def test_backend_output_with_unencodable_path(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("PYTHONIOENCODING", "ascii") # like a Windows ANSI code page that lacks a path character
root: Final[Path] = tmp_path / "pröject"
root.mkdir()
(root / "build_tester.py").write_text("def build_sdist(sdist_directory, config_settings=None): return 'out.tar.gz'")

result: Final = SubprocessFrontend(root, (root,), "build_tester", None, ()).build_sdist(root / "dist")

assert (result.sdist, "pr\\xf6ject" in result.out) == (root / "dist" / "out.tar.gz", True)
Loading