From 21f3c641fc8ca41d17e9d582a0b2fd62c555fa41 Mon Sep 17 00:00:00 2001 From: Jeff <138259519+jdotc1@users.noreply.github.com> Date: Wed, 21 Oct 2026 14:43:28 -0400 Subject: [PATCH 1/2] fix(frontend): preserve whitespace in backend paths --- src/pyproject_api/_via_fresh_subprocess.py | 2 +- tests/test_frontend.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/pyproject_api/_via_fresh_subprocess.py b/src/pyproject_api/_via_fresh_subprocess.py index e9a2c29..dfa344d 100644 --- a/src/pyproject_api/_via_fresh_subprocess.py +++ b/src/pyproject_api/_via_fresh_subprocess.py @@ -64,7 +64,7 @@ def __init__( @contextmanager def _send_msg(self, cmd: str, result_file: Path, msg: str) -> Generator[SubprocessCmdStatus, None, None]: # ruff:ignore[unused-method-argument] env = os.environ.copy() - backend = os.pathsep.join(str(i) for i in self._backend_paths).strip() + backend = os.pathsep.join(str(i) for i in self._backend_paths) if backend: env["PYTHONPATH"] = backend process = Popen( # ruff:ignore[subprocess-without-shell-equals-true] # fixed argv, no shell diff --git a/tests/test_frontend.py b/tests/test_frontend.py index 8410d90..cf2c34e 100644 --- a/tests/test_frontend.py +++ b/tests/test_frontend.py @@ -55,6 +55,27 @@ def get_requires_for_build_wheel(config_settings=None): assert frontend.get_requires_for_build_wheel().requires == (Requirement("wheel"),) +@pytest.mark.parametrize( + "backend_name", + [ + "backend", + "backend with spaces", + pytest.param( + "backend ", marks=pytest.mark.skipif(sys.platform == "win32", reason="trailing spaces normalized") + ), + ], +) +def test_backend_path_preserves_whitespace(tmp_path: Path, backend_name: str) -> None: + backend = tmp_path / backend_name + backend.mkdir() + (backend / "build_tester.py").write_text( + "def get_requires_for_build_wheel(config_settings=None):\n return ['wheel']\n" + ) + frontend = SubprocessFrontend(tmp_path, (backend,), "build_tester", None, ()) + + assert frontend.get_requires_for_build_wheel().requires == (Requirement("wheel"),) + + @pytest.mark.parametrize( "hook", [ From 7d2681f65c48f90690de1870f85d3859fa808c36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Tue, 27 Oct 2026 12:34:51 -0700 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=85=20test(frontend):=20pin=20the=20t?= =?UTF-8?q?railing-space=20backend=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ordinary and embedded-space cases passed with .strip() too, and so would a leading space: backend paths are absolute, so the joined string never starts with whitespace. Keep the one case that fails without the fix, exclude it from Windows coverage where it is skipped, and add the news fragment the changelog check requires. Mark the new locals Final. --- .../+backend-path-whitespace.bugfix.rst | 1 + tests/test_frontend.py | 17 ++++------------- 2 files changed, 5 insertions(+), 13 deletions(-) create mode 100644 docs/changelog.d/+backend-path-whitespace.bugfix.rst diff --git a/docs/changelog.d/+backend-path-whitespace.bugfix.rst b/docs/changelog.d/+backend-path-whitespace.bugfix.rst new file mode 100644 index 0000000..c4f9d51 --- /dev/null +++ b/docs/changelog.d/+backend-path-whitespace.bugfix.rst @@ -0,0 +1 @@ +Keep a trailing space in the last backend path when putting it on ``PYTHONPATH``. diff --git a/tests/test_frontend.py b/tests/test_frontend.py index cf2c34e..c1f8791 100644 --- a/tests/test_frontend.py +++ b/tests/test_frontend.py @@ -55,23 +55,14 @@ def get_requires_for_build_wheel(config_settings=None): assert frontend.get_requires_for_build_wheel().requires == (Requirement("wheel"),) -@pytest.mark.parametrize( - "backend_name", - [ - "backend", - "backend with spaces", - pytest.param( - "backend ", marks=pytest.mark.skipif(sys.platform == "win32", reason="trailing spaces normalized") - ), - ], -) -def test_backend_path_preserves_whitespace(tmp_path: Path, backend_name: str) -> None: - backend = tmp_path / backend_name +@pytest.mark.skipif(sys.platform == "win32", reason="Windows drops trailing spaces from names") +def test_backend_path_with_trailing_space(tmp_path: Path) -> None: # pragma: win32 no cover + backend: Final = tmp_path / "backend " backend.mkdir() (backend / "build_tester.py").write_text( "def get_requires_for_build_wheel(config_settings=None):\n return ['wheel']\n" ) - frontend = SubprocessFrontend(tmp_path, (backend,), "build_tester", None, ()) + frontend: Final = SubprocessFrontend(tmp_path, (backend,), "build_tester", None, ()) assert frontend.get_requires_for_build_wheel().requires == (Requirement("wheel"),)