summaryrefslogtreecommitdiff
path: root/numpy/f2py
diff options
context:
space:
mode:
authorE. Madison Bray <erik.bray@lri.fr>2020-05-11 14:11:59 +0200
committerE. Madison Bray <erik.bray@lri.fr>2020-05-11 14:11:59 +0200
commit9fa7fee0ad8d23bd36ef51b0ec02cf2811f1eec6 (patch)
treeb40593718a8f445b2bba0476d43b035c18e9f834 /numpy/f2py
parente66453568b685dee47d6e6e634b3a47edffcaeed (diff)
downloadnumpy-9fa7fee0ad8d23bd36ef51b0ec02cf2811f1eec6.tar.gz
ENH: add full_output to f2py.compile
fixes #12756 by providing a straightforward way to return the stdout/stderr from compiling the FORTRAN module to the caller
Diffstat (limited to 'numpy/f2py')
-rw-r--r--numpy/f2py/__init__.py36
1 files changed, 22 insertions, 14 deletions
diff --git a/numpy/f2py/__init__.py b/numpy/f2py/__init__.py
index 949bac0ff..007ed5d89 100644
--- a/numpy/f2py/__init__.py
+++ b/numpy/f2py/__init__.py
@@ -21,7 +21,8 @@ def compile(source,
extra_args='',
verbose=True,
source_fn=None,
- extension='.f'
+ extension='.f',
+ full_output=False
):
"""
Build extension module from a Fortran 77 source string with f2py.
@@ -55,10 +56,19 @@ def compile(source,
.. versionadded:: 1.11.0
+ full_output : bool, optional
+ If True, return a `subprocess.CompletedProcess` containing
+ the stdout and stderr of the compile process, instead of just
+ the status code.
+
+ .. versionadded:: 1.20.0
+
+
Returns
-------
- result : int
- 0 on success
+ result : int or `subprocess.CompletedProcess`
+ 0 on success, or a `subprocess.CompletedProcess` if
+ ``full_output=True``
Examples
--------
@@ -95,23 +105,21 @@ def compile(source,
'-c',
'import numpy.f2py as f2py2e;f2py2e.main()'] + args
try:
- output = subprocess.check_output(c)
- except subprocess.CalledProcessError as exc:
- status = exc.returncode
- output = ''
+ cp = subprocess.run(c, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
except OSError:
# preserve historic status code used by exec_command()
- status = 127
- output = ''
- else:
- status = 0
- output = output.decode()
+ cp = subprocess.CompletedProcess(c, 127, stdout='', stderr='')
if verbose:
- print(output)
+ print(cp.stdout.decode())
finally:
if source_fn is None:
os.remove(fname)
- return status
+
+ if full_output:
+ return cp
+ else:
+ return cp.returncode
from numpy._pytesttester import PytestTester
test = PytestTester(__name__)