Skip to content

Commit

Permalink
Fix get_include for nonstandard installations
Browse files Browse the repository at this point in the history
This fixes pybind#1425.
  • Loading branch information
knedlsepp committed Jun 8, 2018
1 parent 55dc131 commit a28f048
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
32 changes: 8 additions & 24 deletions pybind11/__init__.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
from ._version import version_info, __version__ # noqa: F401 imported but unused


def get_include(user=False):
from distutils.dist import Distribution
import os
def get_include():
from os import pardir
from os.path import abspath, dirname, join
from sysconfig import get_config_var
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)
prefix = abspath(join(dirname(__file__), pardir, pardir, pardir, pardir))
relative_include = get_config_var('INCLUDEPY').replace(
get_config_var('prefix'), '')
return join(prefix, relative_include)
3 changes: 1 addition & 2 deletions pybind11/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
def print_includes():
dirs = [sysconfig.get_path('include'),
sysconfig.get_path('platinclude'),
get_include(),
get_include(True)]
get_include()]

# Make unique but preserve order
unique_dirs = []
Expand Down

0 comments on commit a28f048

Please sign in to comment.