Skip to content

Commit

Permalink
Avoid opening the file twice
Browse files Browse the repository at this point in the history
  • Loading branch information
isuruf authored and wjakob committed Apr 26, 2020
1 parent 187e874 commit 4a08067
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ def has_flag(compiler, flagname):
"""
import tempfile
import os
with tempfile.NamedTemporaryFile('w', suffix='.cpp') as f:
with tempfile.NamedTemporaryFile('w', suffix='.cpp', delete=False) as f:
f.write('int main (int argc, char **argv) { return 0; }')
fname = f.name
try:
compiler.compile([fname], extra_postargs=[flagname])
except setuptools.distutils.errors.CompileError:
return False
finally:
try:
compiler.compile([fname], extra_postargs=[flagname])
except setuptools.distutils.errors.CompileError:
return False
finally:
try:
os.remove(fname)
except OSError:
pass
os.remove(fname)
except OSError:
pass
return True


Expand Down

0 comments on commit 4a08067

Please sign in to comment.