Repository navigation
🐛 fix(py_info): stop system_include returning the prefix when headers are missing - #182
Open
darrenhuai wants to merge 3 commits into
Open
darrenhuai wants to merge 3 commits into
darrenhuai wants to merge 3 commits into
Conversation
… are missing
An interpreter installed without its C headers, such as Ubuntu's python3 without python3-dev, has no include directory.
On Python 3.11 and later system_include then returned the interpreter's prefix, which always exists, so a caller that
checks the path sees an include directory with no headers in it.
The broken packaging fallback joins the parent of the distutils headers path onto the prefix. Without distutils, as on
3.11 and later and on Debian's 3.10, there is no headers path, install_path("headers") is empty and the join gives the
prefix itself. The fallback now only runs when there is a headers path to use, so the missing sysconfig include path
comes back instead. Tests now cover the branch, so it loses its no cover pragma.
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.
On Python 3.11 and later,
PythonInfo.system_includereturns the interpreter's prefix when the interpreter has no include directory, as with Ubuntu'spython3installed withoutpython3-dev. 🐛 The prefix always exists, so a caller that checks the path before building a C extension is told the headers are there when they are not. Here ismainon a copy of uv's CPython 3.14.3 build with itsincludefolder removed:Once this merges,
system_includereturns<prefix>\Includethere, which does not exist, so that check gives the right answer. The only reader I found is the skip condition in virtualenv'stests/unit/create/via_global_ref/test_build_c_ext.py, so on such an interpreter that test currently runs instead of being skipped.The broken packaging fallback joins the parent of
install_path("headers")onto the prefix, which strips the distribution name off the distutils headers path. On 3.11 and later, and on Debian's 3.10,distutils_installis empty and sysconfig has noheaderskey, soinstall_path("headers")is""and the join gives the prefix plus a separator. The branch came over from virtualenv in #28 markedpragma: no cover, and its one test only checked that the result is a string. The fallback now runs only when the headers path has a parent to use, and otherwise the sysconfig include path comes back as is. The rewritten test covers each branch, so the pragma is gone, and its no-headers case fails onmain.