1
1
from setuptools import setup , Extension
2
2
from setuptools .command .build_ext import build_ext
3
- from pip import locations
4
- import os
5
3
import sys
6
4
import setuptools
7
5
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
+
8
22
ext_modules = [
9
23
Extension (
10
24
'pbtest' ,
11
25
['py/main.cpp' ],
12
26
include_dirs = [
13
27
# Path to pybind11 headers
14
- os .path .dirname (locations .distutils_scheme ('pybind11' )['headers' ])
28
+ get_pybind_include (),
29
+ get_pybind_include (user = True )
15
30
],
16
- language = 'c++' ,
31
+ language = 'c++'
17
32
),
18
33
]
19
34
35
+
20
36
# As of Python 3.6, CCompiler has a `has_flag` method.
21
37
# cf http://bugs.python.org/issue26689
22
38
def has_flag (compiler , flagname ):
@@ -32,6 +48,7 @@ def has_flag(compiler, flagname):
32
48
return False
33
49
return True
34
50
51
+
35
52
def cpp_flag (compiler ):
36
53
"""Return the -std=c++[11/14] compiler flag.
37
54
@@ -42,7 +59,8 @@ def cpp_flag(compiler):
42
59
elif has_flag (compiler , '-std=c++11' ):
43
60
return '-std=c++11'
44
61
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!' )
46
64
47
65
48
66
class BuildExt (build_ext ):
@@ -75,7 +93,7 @@ def build_extensions(self):
75
93
description = 'A test project using pybind11' ,
76
94
long_description = '' ,
77
95
ext_modules = ext_modules ,
78
- install_requires = ['pybind11' ],
96
+ install_requires = ['pybind11>=1.7 ' ],
79
97
cmdclass = {'build_ext' : BuildExt },
80
98
zip_safe = False ,
81
99
)
0 commit comments