Skip to content

Commit

Permalink
GH-127724: don't use sysconfig to calculate the venv local include pa…
Browse files Browse the repository at this point in the history
…th (#127731)
  • Loading branch information
FFY00 authored Dec 12, 2024
1 parent a8ffe66 commit 8ac307f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Lib/venv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ def _venv_path(self, env_dir, name):
vars = {
'base': env_dir,
'platbase': env_dir,
'installed_base': env_dir,
'installed_platbase': env_dir,
}
return sysconfig.get_path(name, scheme='venv', vars=vars)

Expand Down Expand Up @@ -175,9 +173,20 @@ def create_if_needed(d):
context.python_dir = dirname
context.python_exe = exename
binpath = self._venv_path(env_dir, 'scripts')
incpath = self._venv_path(env_dir, 'include')
libpath = self._venv_path(env_dir, 'purelib')

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

context.inc_path = incpath
create_if_needed(incpath)
context.lib_path = libpath
Expand Down

0 comments on commit 8ac307f

Please sign in to comment.