summaryrefslogtreecommitdiff
path: root/numpy/f2py/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/f2py/__init__.py')
-rw-r--r--numpy/f2py/__init__.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/numpy/f2py/__init__.py b/numpy/f2py/__init__.py
index ccdbd4e0b..fcfd1853e 100644
--- a/numpy/f2py/__init__.py
+++ b/numpy/f2py/__init__.py
@@ -28,20 +28,20 @@ def compile(source,
from numpy.distutils.exec_command import exec_command
import tempfile
if source_fn is None:
- fname = os.path.join(tempfile.mktemp()+'.f')
+ f = tempfile.NamedTemporaryFile(suffix='.f')
else:
- fname = source_fn
-
- f = open(fname, 'w')
- f.write(source)
- f.close()
-
- args = ' -c -m %s %s %s'%(modulename, fname, extra_args)
- c = '%s -c "import numpy.f2py as f2py2e;f2py2e.main()" %s' %(sys.executable, args)
- s, o = exec_command(c)
- if source_fn is None:
- try: os.remove(fname)
- except OSError: pass
+ f = open(source_fn, 'w')
+
+ try:
+ f.write(source)
+ f.flush()
+
+ args = ' -c -m %s %s %s'%(modulename, f.name, extra_args)
+ c = '%s -c "import numpy.f2py as f2py2e;f2py2e.main()" %s' % \
+ (sys.executable, args)
+ s, o = exec_command(c)
+ finally:
+ f.close()
return s
from numpy.testing import Tester