Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions pybind11/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
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
try:
from pip import locations
return os.path.dirname(
locations.distutils_scheme('pybind11', *args, **kwargs)['headers'])
except ImportError:
return 'include'
import sys

# Are we running in a virtual environment?
virtualenv = hasattr(sys, 'real_prefix') or \
sys.prefix != getattr(sys, "base_prefix", sys.prefix)

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)