summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2015-12-17 15:27:07 -0700
committerCharles Harris <charlesr.harris@gmail.com>2015-12-17 15:27:07 -0700
commitdcc9b48e549efce6bdb966ea4204306e87abb73c (patch)
treea281d2debee9c5a01d9763cf871d70a62637af09 /numpy
parenteaad7e8f3d9ebd0c85106e12b88f36f286941e1a (diff)
parentd8967ceefe7afca7a260df3f744699d1512f6fd6 (diff)
downloadnumpy-dcc9b48e549efce6bdb966ea4204306e87abb73c.tar.gz
Merge pull request #6852 from charris/fixup-gh-6696
Fixup #6696, updates to f2py.compile
Diffstat (limited to 'numpy')
-rw-r--r--numpy/f2py/__init__.py36
1 files changed, 27 insertions, 9 deletions
diff --git a/numpy/f2py/__init__.py b/numpy/f2py/__init__.py
index 17a575927..ef92114ed 100644
--- a/numpy/f2py/__init__.py
+++ b/numpy/f2py/__init__.py
@@ -19,16 +19,32 @@ main = f2py2e.main
def compile(source,
modulename='untitled',
extra_args='',
- verbose=1,
- source_fn=None
+ verbose=True,
+ source_fn=None,
+ extension='.f'
):
''' Build extension module from processing source with f2py.
- Read the source of this function for more information.
+
+ Parameters
+ ----------
+ source : str
+ Fortran source of module / subroutine to compile
+ modulename : str, optional
+ the name of compiled python module
+ extra_args: str, optional
+ additional parameters passed to f2py
+ verbose: bool, optional
+ print f2py output to screen
+ extension: {'.f', '.f90'}, optional
+ filename extension influences the fortran compiler behavior
+
+ .. versionadded:: 1.11.0
+
'''
from numpy.distutils.exec_command import exec_command
import tempfile
if source_fn is None:
- f = tempfile.NamedTemporaryFile(suffix='.f')
+ f = tempfile.NamedTemporaryFile(suffix=extension)
else:
f = open(source_fn, 'w')
@@ -36,13 +52,15 @@ def compile(source,
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)
+ args = ' -c -m {} {} {}'.format(modulename, f.name, extra_args)
+ c = '{} -c "import numpy.f2py as f2py2e;f2py2e.main()" {}'
+ c = c.format(sys.executable, args)
+ status, output = exec_command(c)
+ if verbose:
+ print(output)
finally:
f.close()
- return s
+ return status
from numpy.testing import Tester
test = Tester().test