Skip to content

Commit 8ac307f

Browse files
authored
GH-127724: don't use sysconfig to calculate the venv local include path (#127731)
1 parent a8ffe66 commit 8ac307f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Lib/venv/__init__.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ def _venv_path(self, env_dir, name):
103103
vars = {
104104
'base': env_dir,
105105
'platbase': env_dir,
106-
'installed_base': env_dir,
107-
'installed_platbase': env_dir,
108106
}
109107
return sysconfig.get_path(name, scheme='venv', vars=vars)
110108

@@ -175,9 +173,20 @@ def create_if_needed(d):
175173
context.python_dir = dirname
176174
context.python_exe = exename
177175
binpath = self._venv_path(env_dir, 'scripts')
178-
incpath = self._venv_path(env_dir, 'include')
179176
libpath = self._venv_path(env_dir, 'purelib')
180177

178+
# PEP 405 says venvs should create a local include directory.
179+
# See https://peps.python.org/pep-0405/#include-files
180+
# XXX: This directory is not exposed in sysconfig or anywhere else, and
181+
# doesn't seem to be utilized by modern packaging tools. We keep it
182+
# for backwards-compatibility, and to follow the PEP, but I would
183+
# recommend against using it, as most tooling does not pass it to
184+
# compilers. Instead, until we standardize a site-specific include
185+
# directory, I would recommend installing headers as package data,
186+
# and providing some sort of API to get the include directories.
187+
# Example: https://numpy.org/doc/2.1/reference/generated/numpy.get_include.html
188+
incpath = os.path.join(env_dir, 'Include' if os.name == 'nt' else 'include')
189+
181190
context.inc_path = incpath
182191
create_if_needed(incpath)
183192
context.lib_path = libpath

0 commit comments

Comments
 (0)