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/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..c1f8791 100644 --- a/tests/test_frontend.py +++ b/tests/test_frontend.py @@ -55,6 +55,18 @@ def get_requires_for_build_wheel(config_settings=None): assert frontend.get_requires_for_build_wheel().requires == (Requirement("wheel"),) +@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: Final = SubprocessFrontend(tmp_path, (backend,), "build_tester", None, ()) + + assert frontend.get_requires_for_build_wheel().requires == (Requirement("wheel"),) + + @pytest.mark.parametrize( "hook", [