Skip to content

Commit f3e61bf

Browse files
committed
Fix for temp file on windows
On windows the temp file cannot be opened a second time while it is still opened by python. Close the file in python before asking the compiler to read it. See https://docs.python.org/3.7/library/tempfile.html#tempfile.NamedTemporaryFile
1 parent 7aeb9cc commit f3e61bf

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

setup.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ def has_flag(compiler, flagname):
4242
the specified compiler.
4343
"""
4444
import tempfile
45-
with tempfile.NamedTemporaryFile('w', suffix='.cpp') as f:
45+
with tempfile.NamedTemporaryFile('w', suffix='.cpp', delete=False) as f:
4646
f.write('int main (int argc, char **argv) { return 0; }')
47-
try:
48-
compiler.compile([f.name], extra_postargs=[flagname])
49-
except setuptools.distutils.errors.CompileError:
50-
return False
47+
fname = f.name
48+
try:
49+
compiler.compile([fname], extra_postargs=[flagname])
50+
except setuptools.distutils.errors.CompileError:
51+
return False
5152
return True
5253

5354

0 commit comments

Comments
 (0)