Detect pybind11 header path without depending on pip internals (fixes #1174) (#1190)

This commit is contained in:
Wenzel Jakob 2018-04-16 10:27:21 +02:00 committed by GitHub
parent fd9bc8f54d
commit 060936fed2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,11 +1,28 @@
from ._version import version_info, __version__ # noqa: F401 imported but unused from ._version import version_info, __version__ # noqa: F401 imported but unused
def get_include(*args, **kwargs): def get_include(user=False):
from distutils.dist import Distribution
import os import os
try: import sys
from pip import locations
return os.path.dirname( # Are we running in a virtual environment?
locations.distutils_scheme('pybind11', *args, **kwargs)['headers']) virtualenv = hasattr(sys, 'real_prefix') or \
except ImportError: sys.prefix != getattr(sys, "base_prefix", sys.prefix)
return 'include'
if virtualenv:
return os.path.join(sys.prefix, 'include', 'site',
'python' + sys.version[:3])
else:
dist = Distribution({'name': 'pybind11'})
dist.parse_config_files()
dist_cobj = dist.get_command_obj('install', create=True)
# Search for packages in user's home directory?
if user:
dist_cobj.user = user
dist_cobj.prefix = ""
dist_cobj.finalize_options()
return os.path.dirname(dist_cobj.install_headers)