8000 Merge pull request #7 from SylvainCorlay/has_flag_better_implementation · martin-honnen/python_example@818b984 · GitHub < 8000 link rel="manifest" href="/manifest.json" crossOrigin="use-credentials">
[go: up one dir, main page]

Skip to content

Commit 818b984

Browse files
committed
Merge pull request pybind#7 from SylvainCorlay/has_flag_better_implementation
Better implementation of has_flag method
2 parents 17808d7 + 6f5e450 commit 818b984

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

setup.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@
1717
),
1818
]
1919

20+
# As of Python 3.6, CCompiler has a `has_flag` method.
21+
# cf http://bugs.python.org/issue26689
2022
def has_flag(compiler, flagname):
2123
"""Return a boolean indicating whether a flag name is supported on
2224
the specified compiler.
2325
"""
2426
import tempfile
25-
fd, fname = tempfile.mkstemp('.cpp', 'main', text=True)
26-
with os.fdopen(fd, 'w') as f:
27+
with tempfile.NamedTemporaryFile('w', suffix='.cpp') as f:
2728
f.write('int main (int argc, char **argv) { return 0; }')
28-
try:
29-
compiler.compile([fname], extra_postargs=[flagname])
30-
except setuptools.distutils.errors.CompileError:
31-
return False
29+
try:
30+
compiler.compile([f.name], extra_postargs=[flagname])
31+
except setuptools.distutils.errors.CompileError:
32+
return False
3233
return True
3334

3435
def cpp_flag(compiler):

0 commit comments

Comments
 (0)
0