diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2020-11-23 07:47:33 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-23 07:47:33 -0700 |
commit | f09166e85cea7c1639fbb1054171699394ecb62d (patch) | |
tree | fa2d7c229b628224d2353b67bdea31ac59678bb5 /numpy/f2py | |
parent | a0f9f503f2dbc9492e7cc20b52623993ced6214a (diff) | |
parent | fd89e950701206122c358bba1bf816a8bcbea844 (diff) | |
download | numpy-f09166e85cea7c1639fbb1054171699394ecb62d.tar.gz |
Merge pull request #16205 from embray/issue/12756
ENH: Add ``full_output`` argument to ``f2py.compile``.
Diffstat (limited to 'numpy/f2py')
-rw-r--r-- | numpy/f2py/__init__.py | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/numpy/f2py/__init__.py b/numpy/f2py/__init__.py index 328045c07..07ab6cd7d 100644 --- a/numpy/f2py/__init__.py +++ b/numpy/f2py/__init__.py @@ -20,7 +20,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. @@ -54,10 +55,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 -------- @@ -94,23 +104,22 @@ 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 = '' + cp = subprocess.CompletedProcess(c, 127, stdout=b'', stderr=b'') else: - status = 0 - output = output.decode() - if verbose: - print(output) + if verbose: + print(cp.stdout.decode()) finally: if source_fn is None: os.remove(fname) - return status + + if full_output: + return cp + else: + return cp.returncode if sys.version_info[:2] >= (3, 7): |