Skip to content

Commit 6be7a0c

Browse files
committed
Fix removing directories
1 parent f3e61bf commit 6be7a0c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

setup.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ def has_flag(compiler, flagname):
4141
"""Return a boolean indicating whether a flag name is supported on
4242
the specified compiler.
4343
"""
44-
import tempfile
45-
with tempfile.NamedTemporaryFile('w', suffix='.cpp', delete=False) as f:
46-
f.write('int main (int argc, char **argv) { return 0; }')
47-
fname = f.name
48-
try:
49-
compiler.compile([fname], extra_postargs=[flagname])
50-
except setuptools.distutils.errors.CompileError:
51-
return False
44+
import tempfile, os
45+
with tempfile.TemporaryDirectory() as d:
46+
fname = os.path.join(d, 'main.cpp')
47+
with open(fname, 'w') as f:
48+
f.write('int main (int argc, char **argv) { return 0; }')
49+
try:
50+
compiler.compile([fname], extra_postargs=[flagname])
51+
except setuptools.distutils.errors.CompileError:
52+
return False
5253
return True
5354

5455

0 commit comments

Comments
 (0)