diff options
author | Tyler Reddy <tyler.je.reddy@gmail.com> | 2018-09-10 09:35:45 -0700 |
---|---|---|
committer | Tyler Reddy <tyler.je.reddy@gmail.com> | 2018-09-10 09:36:12 -0700 |
commit | ac7dc482b2292c1987412ea7742f948681982f18 (patch) | |
tree | 5e5e33b6a2d17acaa46170a951edabc6bc93a78e | |
parent | 91454d6611021cc1d0d581f7bc81775ca0184517 (diff) | |
download | numpy-ac7dc482b2292c1987412ea7742f948681982f18.tar.gz |
MAINT: remove exec_command from gnu.py
* replaced usage of exec_command() with
standard library equivalent in distutils
gnu module
-rw-r--r-- | numpy/distutils/exec_command.py | 18 | ||||
-rw-r--r-- | numpy/distutils/fcompiler/gnu.py | 31 |
2 files changed, 40 insertions, 9 deletions
diff --git a/numpy/distutils/exec_command.py b/numpy/distutils/exec_command.py index 8118e2fc3..af7810d75 100644 --- a/numpy/distutils/exec_command.py +++ b/numpy/distutils/exec_command.py @@ -61,6 +61,24 @@ import locale from numpy.distutils.misc_util import is_sequence, make_temp_file from numpy.distutils import log +def filepath_from_subprocess_output(output): + """ + Convert `bytes` in the encoding used by a subprocess into a filesystem-appropriate `str`. + + Inherited from `exec_command`, and possibly incorrect. + """ + output = output.decode(locale.getpreferredencoding(False), + errors='replace') + output = output.replace('\r\n', '\n') + # Another historical oddity + if output[-1:] == '\n': + output = output[:-1] + # stdio uses bytes in python 2, so to avoid issues, we simply + # remove all non-ascii characters + if sys.version_info < (3, 0): + output = output.encode('ascii', errors='replace') + return output + def temp_file_name(): fo, name = make_temp_file() fo.close() diff --git a/numpy/distutils/fcompiler/gnu.py b/numpy/distutils/fcompiler/gnu.py index 0ebbe79dc..488a5a7e6 100644 --- a/numpy/distutils/fcompiler/gnu.py +++ b/numpy/distutils/fcompiler/gnu.py @@ -8,10 +8,11 @@ import platform import tempfile import hashlib import base64 +import subprocess from subprocess import Popen, PIPE, STDOUT from copy import copy +from numpy.distutils.exec_command import filepath_from_subprocess_output from numpy.distutils.fcompiler import FCompiler -from numpy.distutils.exec_command import exec_command from numpy.distutils.compat import get_exception from numpy.distutils.system_info import system_info @@ -160,9 +161,13 @@ class GnuFCompiler(FCompiler): return opt def get_libgcc_dir(self): - status, output = exec_command( - self.compiler_f77 + ['-print-libgcc-file-name'], use_tee=0) - if not status: + try: + output = subprocess.check_output(self.compiler_f77 + + ['-print-libgcc-file-name']) + except (OSError, subprocess.CalledProcessError): + pass + else: + output = filepath_from_subprocess_output(output) return os.path.dirname(output) return None @@ -177,9 +182,13 @@ class GnuFCompiler(FCompiler): libgfortran_dir = None if libgfortran_name: find_lib_arg = ['-print-file-name={0}'.format(libgfortran_name)] - status, output = exec_command( - self.compiler_f77 + find_lib_arg, use_tee=0) - if not status: + try: + output = subprocess.check_output( + self.compiler_f77 + find_lib_arg) + except (OSError, subprocess.CalledProcessError): + pass + else: + output = filepath_from_subprocess_output(output) libgfortran_dir = os.path.dirname(output) return libgfortran_dir @@ -373,8 +382,12 @@ class Gnu95FCompiler(GnuFCompiler): return opt def get_target(self): - status, output = exec_command(self.compiler_f77 + ['-v'], use_tee=0) - if not status: + try: + output = subprocess.check_output(self.compiler_f77 + ['-v']) + except (OSError, subprocess.CalledProcessError): + pass + else: + output = filepath_from_subprocess_output(output) m = TARGET_R.search(output) if m: return m.group(1) |