Skip to content

🐛 fix(py_info): stop system_include returning the prefix when headers are missing - #182

Open
darrenhuai wants to merge 3 commits into
tox-dev:mainfrom
darrenhuai:fix/system-include-fallback
Open

darrenhuai wants to merge 3 commits into
tox-dev:mainfrom
darrenhuai:fix/system-include-fallback

Conversation

@darrenhuai

Copy link
Copy Markdown
Contributor

On Python 3.11 and later, PythonInfo.system_include returns the interpreter's prefix when the interpreter has no include directory, as with Ubuntu's python3 installed without python3-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 is main on a copy of uv's CPython 3.14.3 build with its include folder removed:

CPython 3.14.3, include folder removed
sysconfig include: <prefix>\Include  exists=False
system_include:    <prefix>\  exists=True Python.h=False

Once this merges, system_include returns <prefix>\Include there, which does not exist, so that check gives the right answer. The only reader I found is the skip condition in virtualenv's tests/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_install is empty and sysconfig has no headers key, so install_path("headers") is "" and the join gives the prefix plus a separator. The branch came over from virtualenv in #28 marked pragma: 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 on main.

… 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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant