11from setuptools import setup , Extension
22from setuptools .command .build_ext import build_ext
3- from pip import locations
4- import os
53import sys
64import setuptools
75
6+
7+ class get_pybind_include (object ):
8+ """Helper class to determine the pybind11 include path
9+
10+ The purpose of this class is to postpone importing pybind11
11+ until it is actually installed, so that the ``get_include()``
12+ method can be invoked. """
13+
14+ def __init__ (self , user = False ):
15+ self .user = user
16+
17+ def __str__ (self ):
18+ import pybind11
19+ return pybind11 .get_include (self .user )
20+
21+
822ext_modules = [
923 Extension (
1024 'pbtest' ,
1125 ['py/main.cpp' ],
1226 include_dirs = [
1327 # Path to pybind11 headers
14- os .path .dirname (locations .distutils_scheme ('pybind11' )['headers' ])
28+ get_pybind_include (),
29+ get_pybind_include (user = True )
1530 ],
16- language = 'c++' ,
31+ language = 'c++'
1732 ),
1833]
1934
35+
2036# As of Python 3.6, CCompiler has a `has_flag` method.
2137# cf http://bugs.python.org/issue26689
2238def has_flag (compiler , flagname ):
@@ -32,6 +48,7 @@ def has_flag(compiler, flagname):
3248 return False
3349 return True
3450
51+
3552def cpp_flag (compiler ):
3653 """Return the -std=c++[11/14] compiler flag.
3754
@@ -42,7 +59,8 @@ def cpp_flag(compiler):
4259 elif has_flag (compiler , '-std=c++11' ):
4360 return '-std=c++11'
4461 else :
45- raise RuntimeError ('Unsupported compiler -- at least C++11 support is needed!' )
62+ raise RuntimeError ('Unsupported compiler -- at least C++11 support '
63+ 'is needed!' )
4664
4765
4866class BuildExt (build_ext ):
@@ -75,7 +93,7 @@ def build_extensions(self):
7593 description = 'A test project using pybind11' ,
7694 long_description = '' ,
7795 ext_modules = ext_modules ,
78- install_requires = ['pybind11' ],
96+ install_requires = ['pybind11>=1.7 ' ],
7997 cmdclass = {'build_ext' : BuildExt },
8098 zip_safe = False ,
8199)
0 commit comments