diff options
Diffstat (limited to 'numpy/distutils')
-rw-r--r-- | numpy/distutils/command/build_ext.py | 14 | ||||
-rw-r--r-- | numpy/distutils/command/config.py | 34 | ||||
-rw-r--r-- | numpy/distutils/command/config_compiler.py | 9 | ||||
-rw-r--r-- | numpy/distutils/core.py | 4 | ||||
-rw-r--r-- | numpy/distutils/exec_command.py | 18 | ||||
-rw-r--r-- | numpy/distutils/fcompiler/gnu.py | 32 | ||||
-rw-r--r-- | numpy/distutils/fcompiler/ibm.py | 13 | ||||
-rw-r--r-- | numpy/distutils/fcompiler/pg.py | 3 | ||||
-rw-r--r-- | numpy/distutils/lib2def.py | 1 | ||||
-rw-r--r-- | numpy/distutils/mingw32ccompiler.py | 1 | ||||
-rw-r--r-- | numpy/distutils/misc_util.py | 8 | ||||
-rw-r--r-- | numpy/distutils/npy_pkg_config.py | 5 | ||||
-rw-r--r-- | numpy/distutils/system_info.py | 12 |
13 files changed, 107 insertions, 47 deletions
diff --git a/numpy/distutils/command/build_ext.py b/numpy/distutils/command/build_ext.py index f6bd81b6c..18d36480a 100644 --- a/numpy/distutils/command/build_ext.py +++ b/numpy/distutils/command/build_ext.py @@ -4,8 +4,7 @@ from __future__ import division, absolute_import, print_function import os -import sys -import shutil +import subprocess from glob import glob from distutils.dep_util import newer_group @@ -15,7 +14,7 @@ from distutils.errors import DistutilsFileError, DistutilsSetupError,\ from distutils.file_util import copy_file from numpy.distutils import log -from numpy.distutils.exec_command import exec_command +from numpy.distutils.exec_command import filepath_from_subprocess_output from numpy.distutils.system_info import combine_paths, system_info from numpy.distutils.misc_util import filter_sources, has_f_sources, \ has_cxx_sources, get_ext_source_files, \ @@ -558,9 +557,12 @@ class build_ext (old_build_ext): # correct path when compiling in Cygwin but with normal Win # Python if dir.startswith('/usr/lib'): - s, o = exec_command(['cygpath', '-w', dir], use_tee=False) - if not s: - dir = o + try: + dir = subprocess.check_output(['cygpath', '-w', dir]) + except (OSError, subprocess.CalledProcessError): + pass + else: + dir = filepath_from_subprocess_output(dir) f_lib_dirs.append(dir) c_library_dirs.extend(f_lib_dirs) diff --git a/numpy/distutils/command/config.py b/numpy/distutils/command/config.py index 47bc496cf..6b904d6ef 100644 --- a/numpy/distutils/command/config.py +++ b/numpy/distutils/command/config.py @@ -7,6 +7,7 @@ from __future__ import division, absolute_import, print_function import os, signal import warnings import sys +import subprocess from distutils.command.config import config as old_config from distutils.command.config import LANG_EXT @@ -14,7 +15,7 @@ from distutils import log from distutils.file_util import copy_file from distutils.ccompiler import CompileError, LinkError import distutils -from numpy.distutils.exec_command import exec_command +from numpy.distutils.exec_command import filepath_from_subprocess_output from numpy.distutils.mingw32ccompiler import generate_manifest from numpy.distutils.command.autodist import (check_gcc_function_attribute, check_gcc_variable_attribute, @@ -121,9 +122,13 @@ Original exception was: %s, and the Compiler class was %s # correct path when compiling in Cygwin but with # normal Win Python if d.startswith('/usr/lib'): - s, o = exec_command(['cygpath', '-w', d], - use_tee=False) - if not s: d = o + try: + d = subprocess.check_output(['cygpath', + '-w', d]) + except (OSError, subprocess.CalledProcessError): + pass + else: + d = filepath_from_subprocess_output(d) library_dirs.append(d) for libname in self.fcompiler.libraries or []: if libname not in libraries: @@ -436,7 +441,6 @@ int main (void) "involving running executable on the target machine.\n" \ "+++++++++++++++++++++++++++++++++++++++++++++++++\n", DeprecationWarning, stacklevel=2) - from distutils.ccompiler import CompileError, LinkError self._check_compiler() exitcode, output = 255, '' try: @@ -450,8 +454,24 @@ int main (void) grabber.restore() raise exe = os.path.join('.', exe) - exitstatus, output = exec_command(exe, execute_in='.', - use_tee=use_tee) + try: + # specify cwd arg for consistency with + # historic usage pattern of exec_command() + # also, note that exe appears to be a string, + # which exec_command() handled, but we now + # use a list for check_output() -- this assumes + # that exe is always a single command + output = subprocess.check_output([exe], cwd='.') + except subprocess.CalledProcessError as exc: + exitstatus = exc.returncode + output = '' + except OSError: + # preserve the EnvironmentError exit status + # used historically in exec_command() + exitstatus = 127 + output = '' + else: + output = filepath_from_subprocess_output(output) if hasattr(os, 'WEXITSTATUS'): exitcode = os.WEXITSTATUS(exitstatus) if os.WIFSIGNALED(exitstatus): diff --git a/numpy/distutils/command/config_compiler.py b/numpy/distutils/command/config_compiler.py index 5e638fecc..bf170063e 100644 --- a/numpy/distutils/command/config_compiler.py +++ b/numpy/distutils/command/config_compiler.py @@ -5,9 +5,12 @@ from numpy.distutils import log #XXX: Linker flags -def show_fortran_compilers(_cache=[]): - # Using cache to prevent infinite recursion - if _cache: return +def show_fortran_compilers(_cache=None): + # Using cache to prevent infinite recursion. + if _cache: + return + elif _cache is None: + _cache = [] _cache.append(1) from numpy.distutils.fcompiler import show_fcompilers import distutils.core diff --git a/numpy/distutils/core.py b/numpy/distutils/core.py index d9e125368..70cc37caa 100644 --- a/numpy/distutils/core.py +++ b/numpy/distutils/core.py @@ -71,12 +71,14 @@ def _dict_append(d, **kws): else: raise TypeError(repr(type(dv))) -def _command_line_ok(_cache=[]): +def _command_line_ok(_cache=None): """ Return True if command line does not contain any help or display requests. """ if _cache: return _cache[0] + elif _cache is None: + _cache = [] ok = True display_opts = ['--'+n for n in Distribution.display_option_names] for o in Distribution.display_options: 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..f151809c7 100644 --- a/numpy/distutils/fcompiler/gnu.py +++ b/numpy/distutils/fcompiler/gnu.py @@ -8,10 +8,10 @@ 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 +160,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 +181,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 +381,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) diff --git a/numpy/distutils/fcompiler/ibm.py b/numpy/distutils/fcompiler/ibm.py index d0c2202d4..c4cb2fca7 100644 --- a/numpy/distutils/fcompiler/ibm.py +++ b/numpy/distutils/fcompiler/ibm.py @@ -3,9 +3,10 @@ from __future__ import division, absolute_import, print_function import os import re import sys +import subprocess from numpy.distutils.fcompiler import FCompiler -from numpy.distutils.exec_command import exec_command, find_executable +from numpy.distutils.exec_command import find_executable from numpy.distutils.misc_util import make_temp_file from distutils import log @@ -35,9 +36,13 @@ class IBMFCompiler(FCompiler): lslpp = find_executable('lslpp') xlf = find_executable('xlf') if os.path.exists(xlf) and os.path.exists(lslpp): - s, o = exec_command(lslpp + ' -Lc xlfcmp') - m = re.search(r'xlfcmp:(?P<version>\d+([.]\d+)+)', o) - if m: version = m.group('version') + try: + o = subprocess.check_output([lslpp, '-Lc', 'xlfcmp']) + except (OSError, subprocess.CalledProcessError): + pass + else: + m = re.search(r'xlfcmp:(?P<version>\d+([.]\d+)+)', o) + if m: version = m.group('version') xlf_dir = '/etc/opt/ibmcmp/xlf' if version is None and os.path.isdir(xlf_dir): diff --git a/numpy/distutils/fcompiler/pg.py b/numpy/distutils/fcompiler/pg.py index e6c816baa..99071800a 100644 --- a/numpy/distutils/fcompiler/pg.py +++ b/numpy/distutils/fcompiler/pg.py @@ -2,7 +2,6 @@ from __future__ import division, absolute_import, print_function import sys -import os from numpy.distutils.fcompiler import FCompiler, dummy_fortran_file from sys import platform @@ -62,8 +61,6 @@ class PGroupFCompiler(FCompiler): if sys.version_info >= (3, 5): - import subprocess - import shlex import functools class PGroupFlangCompiler(FCompiler): diff --git a/numpy/distutils/lib2def.py b/numpy/distutils/lib2def.py index 0a5364566..2d013a1e3 100644 --- a/numpy/distutils/lib2def.py +++ b/numpy/distutils/lib2def.py @@ -2,7 +2,6 @@ from __future__ import division, absolute_import, print_function import re import sys -import os import subprocess __doc__ = """This module generates a DEF file from the symbols in diff --git a/numpy/distutils/mingw32ccompiler.py b/numpy/distutils/mingw32ccompiler.py index e7fa7bc0d..e6bbe1996 100644 --- a/numpy/distutils/mingw32ccompiler.py +++ b/numpy/distutils/mingw32ccompiler.py @@ -71,7 +71,6 @@ class Mingw32CCompiler(distutils.cygwinccompiler.CygwinCCompiler): # we need to support 3.2 which doesn't match the standard # get_versions methods regex if self.gcc_version is None: - import re p = subprocess.Popen(['gcc', '-dumpversion'], shell=True, stdout=subprocess.PIPE) out_string = p.stdout.read() diff --git a/numpy/distutils/misc_util.py b/numpy/distutils/misc_util.py index 8305aeae5..073e841e8 100644 --- a/numpy/distutils/misc_util.py +++ b/numpy/distutils/misc_util.py @@ -84,7 +84,9 @@ def get_num_build_jobs(): Get number of parallel build jobs set by the --parallel command line argument of setup.py If the command did not receive a setting the environment variable - NPY_NUM_BUILD_JOBS checked and if that is unset it returns 1. + NPY_NUM_BUILD_JOBS is checked. If that is unset, return the number of + processors on the system, with a maximum of 8 (to prevent + overloading the system if there a lot of CPUs). Returns ------- @@ -97,6 +99,7 @@ def get_num_build_jobs(): cpu_count = len(os.sched_getaffinity(0)) except AttributeError: cpu_count = multiprocessing.cpu_count() + cpu_count = min(cpu_count, 8) envjobs = int(os.environ.get("NPY_NUM_BUILD_JOBS", cpu_count)) dist = get_distribution() # may be None during configuration @@ -1564,7 +1567,6 @@ class Configuration(object): """Common implementation for add_library and add_installed_library. Do not use directly""" build_info = copy.copy(build_info) - name = name #+ '__OF__' + self.name build_info['sources'] = sources # Sometimes, depends is not set up to an empty list by default, and if @@ -2009,7 +2011,6 @@ class Configuration(object): f.write('version = %r\n' % (version)) f.close() - import atexit def rm_file(f=target,p=self.info): if delete: try: os.remove(f); p('removed '+f) @@ -2051,7 +2052,6 @@ class Configuration(object): f.write('version = %r\n' % (version)) f.close() - import atexit def rm_file(f=target,p=self.info): if delete: try: os.remove(f); p('removed '+f) diff --git a/numpy/distutils/npy_pkg_config.py b/numpy/distutils/npy_pkg_config.py index 6fe517659..ea16e772d 100644 --- a/numpy/distutils/npy_pkg_config.py +++ b/numpy/distutils/npy_pkg_config.py @@ -5,9 +5,9 @@ import re import os if sys.version_info[0] < 3: - from ConfigParser import RawConfigParser, NoOptionError + from ConfigParser import RawConfigParser else: - from configparser import RawConfigParser, NoOptionError + from configparser import RawConfigParser __all__ = ['FormatError', 'PkgNotFound', 'LibraryInfo', 'VariableSet', 'read_config', 'parse_flags'] @@ -414,7 +414,6 @@ if __name__ == '__main__': print("%s\t%s - %s" % (info.name, info.name, info.description)) pkg_name = args[1] - import os d = os.environ.get('NPY_PKG_CONFIG_PATH') if d: info = read_config(pkg_name, ['numpy/core/lib/npy-pkg-config', '.', d]) diff --git a/numpy/distutils/system_info.py b/numpy/distutils/system_info.py index a5693bdd5..79adcc334 100644 --- a/numpy/distutils/system_info.py +++ b/numpy/distutils/system_info.py @@ -126,7 +126,6 @@ import os import re import copy import warnings -import atexit from glob import glob from functools import reduce if sys.version_info[0] < 3: @@ -147,7 +146,8 @@ from distutils import log from distutils.util import get_platform from numpy.distutils.exec_command import ( - find_executable, exec_command, get_pythonexe) + find_executable, filepath_from_subprocess_output, + get_pythonexe) from numpy.distutils.misc_util import (is_sequence, is_string, get_shared_lib_extension) from numpy.distutils.command.config import config as cmd_config @@ -2243,8 +2243,12 @@ class _pkg_config_info(system_info): def get_config_output(self, config_exe, option): cmd = config_exe + ' ' + self.append_config_exe + ' ' + option - s, o = exec_command(cmd, use_tee=0) - if not s: + try: + o = subprocess.check_output(cmd) + except (OSError, subprocess.CalledProcessError): + pass + else: + o = filepath_from_subprocess_output(o) return o def calc_info(self): |