Repository navigation
Conversation
`backend-path` entries have to stay inside the source tree (PEP 517), but `build` only checked that the entry was a directory. An entry that leaves the source tree (`..`, an absolute path) was handed to `pyproject-hooks`, which raised a bare `ValueError`. The `except BuildException` pattern shown in the API guide does not catch it, and the CLI prints a traceback before its error line. An entry that is a symlink to a directory outside the source tree was accepted, and `build` then imported the backend from outside the tree. `_validate_backend_path` now checks every entry before the hook caller is created. The containment check resolves symlinks on both sides and compares the results with `pathlib.Path.is_relative_to`, so it does not need the cross-drive special case that `os.path.commonpath` needs on Windows. The directory check runs first, so an entry that cannot be resolved at all is still reported the way it was before. Fixes pypa#1267. Refs pypa#1264. Signed-off-by: v01dst <v01dst@users.noreply.github.com>
Signed-off-by: v01dst <v01dst@users.noreply.github.com>
v01dst
requested review from
gaborbernat,
henryiii and
layday
as code owners
November 19, 2026 00:04
This was referenced Nov 19, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why I made this PR
backend-pathentries have to stay inside the source tree (PEP 517), butbuildonly checked that the entry was a directory. Two things slipped through:.., an absolute path) was handed topyproject-hooks, which raised a bareValueError. Theexcept BuildExceptionpattern shown in the API guide does not catch it, and the CLI prints a traceback before its error line.buildthen imported the backend from outside the tree. That is backend-path accepts symlinks outside the source tree #1267.This narrows the scope of the original report to the
backend-pathcase, following @henryiii's note on #1264. The other malformed inputs listed there are left as they are.Description
_validate_backend_pathchecks every entry before the hook caller is created:..ValueError: paths must be inside source treeBuildSystemTableValidationErrorValueError: paths must be relativeBuildSystemTableValidationErrorBuildSystemTableValidationErrorBuildSystemTableValidationErrorBuildSystemTableValidationErroris aBuildException, so the documented error handling catches it and the CLI prints one error line instead of a traceback.The containment check resolves symlinks on both sides and compares the results with
pathlib.Path.is_relative_to, so it does not need the cross-drive special case thatos.path.commonpathneeds on Windows. The directory check runs first, so an entry that cannot be resolved at all (a path with a null byte, a symlink loop) is still reported the way it was before.Changelog
docs/changelog/1299.bugfix.rst.Checklist
docs/development/contributing.rst)AI assistance (supporting detail, reviewed by the author)
The reproduction and the test cases were written with an AI coding assistant (OpenCode, MiniMax-M3.1-Flash). The author checked the behaviour of every path against the code on
mainbefore and after the change: abackend-pathentry of..raisedValueError: paths must be inside source treefrompyproject-hooksbefore the change and raisesBuildSystemTableValidationErrorafter it, and abackend-pathentry that is a symlink to a directory outside the source tree was accepted before the change and is rejected after it. The test suite was run locally with Python 3.12 on Windows (362 passed, 3 skipped).