diff options
Diffstat (limited to 'numpy/distutils')
68 files changed, 648 insertions, 579 deletions
diff --git a/numpy/distutils/__init__.py b/numpy/distutils/__init__.py index 8dbb63b28..79974d1c2 100644 --- a/numpy/distutils/__init__.py +++ b/numpy/distutils/__init__.py @@ -19,8 +19,6 @@ LAPACK, and for setting include paths and similar build options, please see """ -from __future__ import division, absolute_import, print_function - # Must import local ccompiler ASAP in order to get # customized CCompiler.spawn effective. from . import ccompiler diff --git a/numpy/distutils/ccompiler.py b/numpy/distutils/ccompiler.py index 643879023..9ea083774 100644 --- a/numpy/distutils/ccompiler.py +++ b/numpy/distutils/ccompiler.py @@ -1,22 +1,23 @@ -from __future__ import division, absolute_import, print_function - import os import re import sys -import types import shlex import time import subprocess from copy import copy from distutils import ccompiler -from distutils.ccompiler import * -from distutils.errors import DistutilsExecError, DistutilsModuleError, \ - DistutilsPlatformError, CompileError +from distutils.ccompiler import ( + compiler_class, gen_lib_options, get_default_compiler, new_compiler, + CCompiler +) +from distutils.errors import ( + DistutilsExecError, DistutilsModuleError, DistutilsPlatformError, + CompileError, UnknownFileError +) from distutils.sysconfig import customize_compiler from distutils.version import LooseVersion from numpy.distutils import log -from numpy.distutils.compat import get_exception from numpy.distutils.exec_command import ( filepath_from_subprocess_output, forward_bytes_to_stdout ) @@ -85,11 +86,8 @@ def _needs_build(obj, cc_args, extra_postargs, pp_opts): def replace_method(klass, method_name, func): - if sys.version_info[0] < 3: - m = types.MethodType(func, None, klass) - else: - # Py3k does not have unbound method anymore, MethodType does not work - m = lambda self, *args, **kw: func(self, *args, **kw) + # Py3k does not have unbound method anymore, MethodType does not work + m = lambda self, *args, **kw: func(self, *args, **kw) setattr(klass, method_name, m) @@ -277,12 +275,8 @@ def CCompiler_compile(self, sources, output_dir=None, macros=None, if not sources: return [] - # FIXME:RELATIVE_IMPORT - if sys.version_info[0] < 3: - from .fcompiler import FCompiler, is_f_file, has_f90_header - else: - from numpy.distutils.fcompiler import (FCompiler, is_f_file, - has_f90_header) + from numpy.distutils.fcompiler import (FCompiler, is_f_file, + has_f90_header) if isinstance(self, FCompiler): display = [] for fc in ['f77', 'f90', 'fix']: @@ -751,15 +745,15 @@ def new_compiler (plat=None, module_name = "numpy.distutils." + module_name try: __import__ (module_name) - except ImportError: - msg = str(get_exception()) + except ImportError as e: + msg = str(e) log.info('%s in numpy.distutils; trying from distutils', str(msg)) module_name = module_name[6:] try: __import__(module_name) - except ImportError: - msg = str(get_exception()) + except ImportError as e: + msg = str(e) raise DistutilsModuleError("can't compile C/C++ code: unable to load module '%s'" % \ module_name) try: diff --git a/numpy/distutils/command/__init__.py b/numpy/distutils/command/__init__.py index 76a260072..3ba501de0 100644 --- a/numpy/distutils/command/__init__.py +++ b/numpy/distutils/command/__init__.py @@ -4,8 +4,6 @@ Package containing implementation of all the standard Distutils commands. """ -from __future__ import division, absolute_import, print_function - def test_na_writable_attributes_deletion(): a = np.NA(2) attr = ['payload', 'dtype'] diff --git a/numpy/distutils/command/autodist.py b/numpy/distutils/command/autodist.py index 9c98b84d8..1475a5e24 100644 --- a/numpy/distutils/command/autodist.py +++ b/numpy/distutils/command/autodist.py @@ -1,8 +1,6 @@ """This module implements additional tests ala autoconf which can be useful. """ -from __future__ import division, absolute_import, print_function - import textwrap # We put them here since they could be easily reused outside numpy.distutils diff --git a/numpy/distutils/command/bdist_rpm.py b/numpy/distutils/command/bdist_rpm.py index 3e52a503b..682e7a8eb 100644 --- a/numpy/distutils/command/bdist_rpm.py +++ b/numpy/distutils/command/bdist_rpm.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import os import sys if 'setuptools' in sys.modules: diff --git a/numpy/distutils/command/build.py b/numpy/distutils/command/build.py index 5a9da1217..a156a7c6e 100644 --- a/numpy/distutils/command/build.py +++ b/numpy/distutils/command/build.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import os import sys from distutils.command.build import build as old_build diff --git a/numpy/distutils/command/build_clib.py b/numpy/distutils/command/build_clib.py index 13edf0717..d679b2d03 100644 --- a/numpy/distutils/command/build_clib.py +++ b/numpy/distutils/command/build_clib.py @@ -1,7 +1,5 @@ """ Modified version of build_clib that handles fortran source files. """ -from __future__ import division, absolute_import, print_function - import os from glob import glob import shutil @@ -11,9 +9,10 @@ from distutils.errors import DistutilsSetupError, DistutilsError, \ from numpy.distutils import log from distutils.dep_util import newer_group -from numpy.distutils.misc_util import filter_sources, has_f_sources,\ - has_cxx_sources, all_strings, get_lib_source_files, is_sequence, \ - get_numpy_include_dirs +from numpy.distutils.misc_util import ( + filter_sources, get_lib_source_files, get_numpy_include_dirs, + has_cxx_sources, has_f_sources, is_sequence +) # Fix Python distutils bug sf #1718574: _l = old_build_clib.user_options diff --git a/numpy/distutils/command/build_ext.py b/numpy/distutils/command/build_ext.py index cd9b1c6f1..0e07ba9cf 100644 --- a/numpy/distutils/command/build_ext.py +++ b/numpy/distutils/command/build_ext.py @@ -1,8 +1,6 @@ """ Modified version of build_ext that handles fortran source files. """ -from __future__ import division, absolute_import, print_function - import os import subprocess from glob import glob @@ -15,11 +13,11 @@ from distutils.file_util import copy_file from numpy.distutils import log 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, \ - get_numpy_include_dirs, is_sequence, get_build_architecture, \ - msvc_version +from numpy.distutils.system_info import combine_paths +from numpy.distutils.misc_util import ( + filter_sources, get_ext_source_files, get_numpy_include_dirs, + has_cxx_sources, has_f_sources, is_sequence +) from numpy.distutils.command.config_compiler import show_fortran_compilers diff --git a/numpy/distutils/command/build_py.py b/numpy/distutils/command/build_py.py index 54dcde435..d30dc5bf4 100644 --- a/numpy/distutils/command/build_py.py +++ b/numpy/distutils/command/build_py.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - from distutils.command.build_py import build_py as old_build_py from numpy.distutils.misc_util import is_string diff --git a/numpy/distutils/command/build_scripts.py b/numpy/distutils/command/build_scripts.py index c8b25fc71..d5cadb274 100644 --- a/numpy/distutils/command/build_scripts.py +++ b/numpy/distutils/command/build_scripts.py @@ -1,8 +1,6 @@ """ Modified version of build_scripts that handles building scripts from functions. """ -from __future__ import division, absolute_import, print_function - from distutils.command.build_scripts import build_scripts as old_build_scripts from numpy.distutils import log from numpy.distutils.misc_util import is_string diff --git a/numpy/distutils/command/build_src.py b/numpy/distutils/command/build_src.py index 3e0522c5f..303d6197c 100644 --- a/numpy/distutils/command/build_src.py +++ b/numpy/distutils/command/build_src.py @@ -1,7 +1,5 @@ """ Build swig and f2py sources. """ -from __future__ import division, absolute_import, print_function - import os import re import sys diff --git a/numpy/distutils/command/config.py b/numpy/distutils/command/config.py index b9f2fa76e..e54a54449 100644 --- a/numpy/distutils/command/config.py +++ b/numpy/distutils/command/config.py @@ -2,13 +2,12 @@ # try_compile call. try_run works but is untested for most of Fortran # compilers (they must define linker_exe first). # Pearu Peterson -from __future__ import division, absolute_import, print_function - -import os, signal -import warnings -import sys +import os +import signal import subprocess +import sys import textwrap +import warnings from distutils.command.config import config as old_config from distutils.command.config import LANG_EXT @@ -24,7 +23,6 @@ from numpy.distutils.command.autodist import (check_gcc_function_attribute, check_inline, check_restrict, check_compiler_gcc4) -from numpy.distutils.compat import get_exception LANG_EXT['f77'] = '.f' LANG_EXT['f90'] = '.f90' @@ -52,8 +50,7 @@ class config(old_config): if not self.compiler.initialized: try: self.compiler.initialize() - except IOError: - e = get_exception() + except IOError as e: msg = textwrap.dedent("""\ Could not initialize compiler instance: do you have Visual Studio installed? If you are trying to build with MinGW, please use "python setup.py @@ -96,8 +93,8 @@ class config(old_config): self.compiler = self.fcompiler try: ret = mth(*((self,)+args)) - except (DistutilsExecError, CompileError): - str(get_exception()) + except (DistutilsExecError, CompileError) as e: + str(e) self.compiler = save_compiler raise CompileError self.compiler = save_compiler @@ -495,7 +492,7 @@ class config(old_config): self._clean() return exitcode, output -class GrabStdout(object): +class GrabStdout: def __init__(self): self.sys_stdout = sys.stdout diff --git a/numpy/distutils/command/config_compiler.py b/numpy/distutils/command/config_compiler.py index bf170063e..44265bfcc 100644 --- a/numpy/distutils/command/config_compiler.py +++ b/numpy/distutils/command/config_compiler.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - from distutils.core import Command from numpy.distutils import log diff --git a/numpy/distutils/command/develop.py b/numpy/distutils/command/develop.py index 1410ab2a0..af24baf2e 100644 --- a/numpy/distutils/command/develop.py +++ b/numpy/distutils/command/develop.py @@ -3,8 +3,6 @@ generated files (from build_src or build_scripts) are properly converted to real files with filenames. """ -from __future__ import division, absolute_import, print_function - from setuptools.command.develop import develop as old_develop class develop(old_develop): diff --git a/numpy/distutils/command/egg_info.py b/numpy/distutils/command/egg_info.py index 18673ece7..14c62b4d1 100644 --- a/numpy/distutils/command/egg_info.py +++ b/numpy/distutils/command/egg_info.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import sys from setuptools.command.egg_info import egg_info as _egg_info diff --git a/numpy/distutils/command/install.py b/numpy/distutils/command/install.py index c74ae9446..2eff2d145 100644 --- a/numpy/distutils/command/install.py +++ b/numpy/distutils/command/install.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import sys if 'setuptools' in sys.modules: import setuptools.command.install as old_install_mod diff --git a/numpy/distutils/command/install_clib.py b/numpy/distutils/command/install_clib.py index 6a73f7e33..aa2e5594c 100644 --- a/numpy/distutils/command/install_clib.py +++ b/numpy/distutils/command/install_clib.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import os from distutils.core import Command from distutils.ccompiler import new_compiler diff --git a/numpy/distutils/command/install_data.py b/numpy/distutils/command/install_data.py index 996cf7e40..0a2e68ae1 100644 --- a/numpy/distutils/command/install_data.py +++ b/numpy/distutils/command/install_data.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import sys have_setuptools = ('setuptools' in sys.modules) diff --git a/numpy/distutils/command/install_headers.py b/numpy/distutils/command/install_headers.py index f3f58aa28..bb4ad563b 100644 --- a/numpy/distutils/command/install_headers.py +++ b/numpy/distutils/command/install_headers.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import os from distutils.command.install_headers import install_headers as old_install_headers diff --git a/numpy/distutils/command/sdist.py b/numpy/distutils/command/sdist.py index bfaab1c8f..e34193883 100644 --- a/numpy/distutils/command/sdist.py +++ b/numpy/distutils/command/sdist.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import sys if 'setuptools' in sys.modules: from setuptools.command.sdist import sdist as old_sdist diff --git a/numpy/distutils/compat.py b/numpy/distutils/compat.py deleted file mode 100644 index 9a81cd392..000000000 --- a/numpy/distutils/compat.py +++ /dev/null @@ -1,10 +0,0 @@ -"""Small modules to cope with python 2 vs 3 incompatibilities inside -numpy.distutils - -""" -from __future__ import division, absolute_import, print_function - -import sys - -def get_exception(): - return sys.exc_info()[1] diff --git a/numpy/distutils/conv_template.py b/numpy/distutils/conv_template.py index 3bcb7b884..d08015fdf 100644 --- a/numpy/distutils/conv_template.py +++ b/numpy/distutils/conv_template.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """ takes templated file .xxx.src and produces .xxx file where .xxx is .i or .c or .h, using the following template rules @@ -78,8 +78,6 @@ Example: 3, 3, jim """ -from __future__ import division, absolute_import, print_function - __all__ = ['process_str', 'process_file'] @@ -87,8 +85,6 @@ import os import sys import re -from numpy.distutils.compat import get_exception - # names for replacement that are already global. global_names = {} @@ -240,8 +236,7 @@ def parse_string(astr, env, level, line) : code.append(replace_re.sub(replace, pref)) try : envlist = parse_loop_header(head) - except ValueError: - e = get_exception() + except ValueError as e: msg = "line %d: %s" % (newline, e) raise ValueError(msg) for newenv in envlist : @@ -289,8 +284,7 @@ def process_file(source): sourcefile = os.path.normcase(source).replace("\\", "\\\\") try: code = process_str(''.join(lines)) - except ValueError: - e = get_exception() + except ValueError as e: raise ValueError('In "%s" loop at %s' % (sourcefile, e)) return '#line 1 "%s"\n%s' % (sourcefile, code) @@ -327,8 +321,7 @@ def main(): allstr = fid.read() try: writestr = process_str(allstr) - except ValueError: - e = get_exception() + except ValueError as e: raise ValueError("In %s loop at %s" % (file, e)) outfile.write(writestr) diff --git a/numpy/distutils/core.py b/numpy/distutils/core.py index 70cc37caa..d5551f349 100644 --- a/numpy/distutils/core.py +++ b/numpy/distutils/core.py @@ -1,7 +1,5 @@ -from __future__ import division, absolute_import, print_function - import sys -from distutils.core import * +from distutils.core import Distribution if 'setuptools' in sys.modules: have_setuptools = True @@ -27,7 +25,7 @@ from numpy.distutils.command import config, config_compiler, \ build, build_py, build_ext, build_clib, build_src, build_scripts, \ sdist, install_data, install_headers, install, bdist_rpm, \ install_clib -from numpy.distutils.misc_util import get_data_files, is_sequence, is_string +from numpy.distutils.misc_util import is_sequence, is_string numpy_cmdclass = {'build': build.build, 'build_src': build_src.build_src, diff --git a/numpy/distutils/cpuinfo.py b/numpy/distutils/cpuinfo.py index bc9728335..51ce3c129 100644 --- a/numpy/distutils/cpuinfo.py +++ b/numpy/distutils/cpuinfo.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """ cpuinfo @@ -12,28 +12,22 @@ NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. Pearu Peterson """ -from __future__ import division, absolute_import, print_function - __all__ = ['cpu'] -import sys, re, types import os - -if sys.version_info[0] >= 3: - from subprocess import getstatusoutput -else: - from commands import getstatusoutput - -import warnings import platform +import re +import sys +import types +import warnings + +from subprocess import getstatusoutput -from numpy.distutils.compat import get_exception def getoutput(cmd, successful_status=(0,), stacklevel=1): try: status, output = getstatusoutput(cmd) - except EnvironmentError: - e = get_exception() + except EnvironmentError as e: warnings.warn(str(e), UserWarning, stacklevel=stacklevel) return False, "" if os.WIFEXITED(status) and os.WEXITSTATUS(status) in successful_status: @@ -67,7 +61,7 @@ def key_value_from_command(cmd, sep, successful_status=(0,), d[l[0]] = l[1] return d -class CPUInfoBase(object): +class CPUInfoBase: """Holds CPU information and provides methods for requiring the availability of various CPU features. """ @@ -115,8 +109,7 @@ class LinuxCPUInfo(CPUInfoBase): info[0]['uname_m'] = output.strip() try: fo = open('/proc/cpuinfo') - except EnvironmentError: - e = get_exception() + except EnvironmentError as e: warnings.warn(str(e), UserWarning, stacklevel=2) else: for line in fo: @@ -490,10 +483,7 @@ class Win32CPUInfo(CPUInfoBase): info = [] try: #XXX: Bad style to use so long `try:...except:...`. Fix it! - if sys.version_info[0] >= 3: - import winreg - else: - import _winreg as winreg + import winreg prgx = re.compile(r"family\s+(?P<FML>\d+)\s+model\s+(?P<MDL>\d+)" r"\s+stepping\s+(?P<STP>\d+)", re.IGNORECASE) @@ -523,8 +513,8 @@ class Win32CPUInfo(CPUInfoBase): info[-1]["Family"]=int(srch.group("FML")) info[-1]["Model"]=int(srch.group("MDL")) info[-1]["Stepping"]=int(srch.group("STP")) - except Exception: - print(sys.exc_info()[1], '(ignoring)') + except Exception as e: + print(e, '(ignoring)') self.__class__.info = info def _not_impl(self): pass diff --git a/numpy/distutils/exec_command.py b/numpy/distutils/exec_command.py index 712f22666..fb10d2470 100644 --- a/numpy/distutils/exec_command.py +++ b/numpy/distutils/exec_command.py @@ -49,8 +49,6 @@ Known bugs: because the messages are lost at some point. """ -from __future__ import division, absolute_import, print_function - __all__ = ['exec_command', 'find_executable'] import os @@ -76,10 +74,6 @@ def filepath_from_subprocess_output(output): # 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 @@ -91,10 +85,7 @@ def forward_bytes_to_stdout(val): The assumption is that the subprocess call already returned bytes in a suitable encoding. """ - if sys.version_info.major < 3: - # python 2 has binary output anyway - sys.stdout.write(val) - elif hasattr(sys.stdout, 'buffer'): + if hasattr(sys.stdout, 'buffer'): # use the underlying binary output if there is one sys.stdout.buffer.write(val) elif hasattr(sys.stdout, 'encoding'): @@ -307,11 +298,6 @@ def _exec_command(command, use_shell=None, use_tee = None, **env): if text[-1:] == '\n': text = text[:-1] - # stdio uses bytes in python 2, so to avoid issues, we simply - # remove all non-ascii characters - if sys.version_info < (3, 0): - text = text.encode('ascii', errors='replace') - if use_tee and text: print(text) return proc.returncode, text diff --git a/numpy/distutils/extension.py b/numpy/distutils/extension.py index 872bd5362..67114ef2e 100644 --- a/numpy/distutils/extension.py +++ b/numpy/distutils/extension.py @@ -6,15 +6,9 @@ modules in setup scripts. Overridden to support f2py. """ -from __future__ import division, absolute_import, print_function - -import sys import re from distutils.extension import Extension as old_Extension -if sys.version_info[0] >= 3: - basestring = str - cxx_ext_re = re.compile(r'.*[.](cpp|cxx|cc)\Z', re.I).match fortran_pyf_ext_re = re.compile(r'.*[.](f90|f95|f77|for|ftn|f|pyf)\Z', re.I).match @@ -76,7 +70,7 @@ class Extension(old_Extension): self.swig_opts = swig_opts or [] # swig_opts is assumed to be a list. Here we handle the case where it # is specified as a string instead. - if isinstance(self.swig_opts, basestring): + if isinstance(self.swig_opts, str): import warnings msg = "swig_opts is specified as a string instead of a list" warnings.warn(msg, SyntaxWarning, stacklevel=2) diff --git a/numpy/distutils/fcompiler/__init__.py b/numpy/distutils/fcompiler/__init__.py index 3723470f3..1c3069363 100644 --- a/numpy/distutils/fcompiler/__init__.py +++ b/numpy/distutils/fcompiler/__init__.py @@ -13,15 +13,12 @@ should be a list. But note that FCompiler.executables is actually a dictionary of commands. """ -from __future__ import division, absolute_import, print_function - __all__ = ['FCompiler', 'new_fcompiler', 'show_fcompilers', 'dummy_fortran_file'] import os import sys import re -import types from numpy.compat import open_latin1 @@ -36,7 +33,6 @@ from numpy.distutils import log from numpy.distutils.misc_util import is_string, all_strings, is_sequence, \ make_temp_file, get_shared_lib_extension from numpy.distutils.exec_command import find_executable -from numpy.distutils.compat import get_exception from numpy.distutils import _shell_utils from .environment import EnvironmentConfig @@ -614,8 +610,8 @@ class FCompiler(CCompiler): src) try: self.spawn(command, display=display) - except DistutilsExecError: - msg = str(get_exception()) + except DistutilsExecError as e: + msg = str(e) raise CompileError(msg) def module_options(self, module_dirs, module_build_dir): @@ -682,8 +678,8 @@ class FCompiler(CCompiler): command = linker + ld_args try: self.spawn(command) - except DistutilsExecError: - msg = str(get_exception()) + except DistutilsExecError as e: + msg = str(e) raise LinkError(msg) else: log.debug("skipping %s (up-to-date)", output_filename) @@ -931,8 +927,7 @@ def show_fcompilers(dist=None): c = new_fcompiler(compiler=compiler, verbose=dist.verbose) c.customize(dist) v = c.get_version() - except (DistutilsModuleError, CompilerNotFound): - e = get_exception() + except (DistutilsModuleError, CompilerNotFound) as e: log.debug("show_fcompilers: %s not found" % (compiler,)) log.debug(repr(e)) diff --git a/numpy/distutils/fcompiler/absoft.py b/numpy/distutils/fcompiler/absoft.py index d14fee0e1..efe3a4cb5 100644 --- a/numpy/distutils/fcompiler/absoft.py +++ b/numpy/distutils/fcompiler/absoft.py @@ -5,8 +5,6 @@ # Notes: # - when using -g77 then use -DUNDERSCORE_G77 to compile f2py # generated extension modules (works for f2py v2.45.241_1936 and up) -from __future__ import division, absolute_import, print_function - import os from numpy.distutils.cpuinfo import cpu diff --git a/numpy/distutils/fcompiler/compaq.py b/numpy/distutils/fcompiler/compaq.py index 671b3a55f..6ce590c7c 100644 --- a/numpy/distutils/fcompiler/compaq.py +++ b/numpy/distutils/fcompiler/compaq.py @@ -1,12 +1,9 @@ #http://www.compaq.com/fortran/docs/ -from __future__ import division, absolute_import, print_function - import os import sys from numpy.distutils.fcompiler import FCompiler -from numpy.distutils.compat import get_exception from distutils.errors import DistutilsPlatformError compilers = ['CompaqFCompiler'] @@ -82,19 +79,16 @@ class CompaqVisualFCompiler(FCompiler): ar_exe = m.lib except DistutilsPlatformError: pass - except AttributeError: - msg = get_exception() + except AttributeError as e: if '_MSVCCompiler__root' in str(msg): print('Ignoring "%s" (I think it is msvccompiler.py bug)' % (msg)) else: raise - except IOError: - e = get_exception() + except IOError as e: if not "vcvarsall.bat" in str(e): print("Unexpected IOError in", __file__) raise e - except ValueError: - e = get_exception() + except ValueError as e: if not "'path'" in str(e): print("Unexpected ValueError in", __file__) raise e diff --git a/numpy/distutils/fcompiler/environment.py b/numpy/distutils/fcompiler/environment.py index bb362d483..21a5be003 100644 --- a/numpy/distutils/fcompiler/environment.py +++ b/numpy/distutils/fcompiler/environment.py @@ -1,12 +1,9 @@ -from __future__ import division, absolute_import, print_function - import os -import warnings from distutils.dist import Distribution __metaclass__ = type -class EnvironmentConfig(object): +class EnvironmentConfig: def __init__(self, distutils_section='ALL', **kw): self._distutils_section = distutils_section self._conf_keys = kw diff --git a/numpy/distutils/fcompiler/g95.py b/numpy/distutils/fcompiler/g95.py index e7c659b33..e109a972a 100644 --- a/numpy/distutils/fcompiler/g95.py +++ b/numpy/distutils/fcompiler/g95.py @@ -1,6 +1,4 @@ # http://g95.sourceforge.net/ -from __future__ import division, absolute_import, print_function - from numpy.distutils.fcompiler import FCompiler compilers = ['G95FCompiler'] diff --git a/numpy/distutils/fcompiler/gnu.py b/numpy/distutils/fcompiler/gnu.py index 965c67041..796dff351 100644 --- a/numpy/distutils/fcompiler/gnu.py +++ b/numpy/distutils/fcompiler/gnu.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import re import os import sys @@ -12,8 +10,6 @@ import subprocess from subprocess import Popen, PIPE, STDOUT from numpy.distutils.exec_command import filepath_from_subprocess_output from numpy.distutils.fcompiler import FCompiler -from numpy.distutils.compat import get_exception -from numpy.distutils.system_info import system_info compilers = ['GnuFCompiler', 'Gnu95FCompiler'] @@ -126,26 +122,17 @@ class GnuFCompiler(FCompiler): # error checking. if not target: # If MACOSX_DEPLOYMENT_TARGET is not set in the environment, - # we try to get it first from the Python Makefile and then we - # fall back to setting it to 10.3 to maximize the set of - # versions we can work with. This is a reasonable default + # we try to get it first from sysconfig and then + # fall back to setting it to 10.9 This is a reasonable default # even when using the official Python dist and those derived # from it. - import distutils.sysconfig as sc - g = {} - try: - get_makefile_filename = sc.get_makefile_filename - except AttributeError: - pass # i.e. PyPy - else: - filename = get_makefile_filename() - sc.parse_makefile(filename, g) - target = g.get('MACOSX_DEPLOYMENT_TARGET', '10.3') - os.environ['MACOSX_DEPLOYMENT_TARGET'] = target - if target == '10.3': - s = 'Env. variable MACOSX_DEPLOYMENT_TARGET set to 10.3' + import sysconfig + target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') + if not target: + target = '10.9' + s = f'Env. variable MACOSX_DEPLOYMENT_TARGET set to {target}' warnings.warn(s, stacklevel=2) - + os.environ['MACOSX_DEPLOYMENT_TARGET'] = target opt.extend(['-undefined', 'dynamic_lookup', '-bundle']) else: opt.append("-shared") @@ -415,8 +402,7 @@ class Gnu95FCompiler(GnuFCompiler): break h.update(block) text = base64.b32encode(h.digest()) - if sys.version_info[0] >= 3: - text = text.decode('ascii') + text = text.decode('ascii') return text.rstrip('=') def _link_wrapper_lib(self, objects, output_dir, extra_dll_dir, @@ -560,5 +546,5 @@ if __name__ == '__main__': print(customized_fcompiler('gnu').get_version()) try: print(customized_fcompiler('g95').get_version()) - except Exception: - print(get_exception()) + except Exception as e: + print(e) diff --git a/numpy/distutils/fcompiler/hpux.py b/numpy/distutils/fcompiler/hpux.py index 51bad548a..09e6483bf 100644 --- a/numpy/distutils/fcompiler/hpux.py +++ b/numpy/distutils/fcompiler/hpux.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - from numpy.distutils.fcompiler import FCompiler compilers = ['HPUXFCompiler'] diff --git a/numpy/distutils/fcompiler/ibm.py b/numpy/distutils/fcompiler/ibm.py index 70d2132e1..4a83682e5 100644 --- a/numpy/distutils/fcompiler/ibm.py +++ b/numpy/distutils/fcompiler/ibm.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import os import re import sys diff --git a/numpy/distutils/fcompiler/intel.py b/numpy/distutils/fcompiler/intel.py index 51f681274..d84f38c76 100644 --- a/numpy/distutils/fcompiler/intel.py +++ b/numpy/distutils/fcompiler/intel.py @@ -1,6 +1,4 @@ # http://developer.intel.com/software/products/compilers/flin/ -from __future__ import division, absolute_import, print_function - import sys from numpy.distutils.ccompiler import simple_version_match diff --git a/numpy/distutils/fcompiler/lahey.py b/numpy/distutils/fcompiler/lahey.py index 1beb662f4..e92583826 100644 --- a/numpy/distutils/fcompiler/lahey.py +++ b/numpy/distutils/fcompiler/lahey.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import os from numpy.distutils.fcompiler import FCompiler diff --git a/numpy/distutils/fcompiler/mips.py b/numpy/distutils/fcompiler/mips.py index da337b24a..a09738045 100644 --- a/numpy/distutils/fcompiler/mips.py +++ b/numpy/distutils/fcompiler/mips.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - from numpy.distutils.cpuinfo import cpu from numpy.distutils.fcompiler import FCompiler diff --git a/numpy/distutils/fcompiler/nag.py b/numpy/distutils/fcompiler/nag.py index cb71d548c..908e724e6 100644 --- a/numpy/distutils/fcompiler/nag.py +++ b/numpy/distutils/fcompiler/nag.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import sys import re from numpy.distutils.fcompiler import FCompiler diff --git a/numpy/distutils/fcompiler/none.py b/numpy/distutils/fcompiler/none.py index bdeea1560..ef411fffc 100644 --- a/numpy/distutils/fcompiler/none.py +++ b/numpy/distutils/fcompiler/none.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - from numpy.distutils.fcompiler import FCompiler from numpy.distutils import customized_fcompiler diff --git a/numpy/distutils/fcompiler/pathf95.py b/numpy/distutils/fcompiler/pathf95.py index 5de86f63a..0768cb12e 100644 --- a/numpy/distutils/fcompiler/pathf95.py +++ b/numpy/distutils/fcompiler/pathf95.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - from numpy.distutils.fcompiler import FCompiler compilers = ['PathScaleFCompiler'] diff --git a/numpy/distutils/fcompiler/pg.py b/numpy/distutils/fcompiler/pg.py index 9c51947fd..eb628cb63 100644 --- a/numpy/distutils/fcompiler/pg.py +++ b/numpy/distutils/fcompiler/pg.py @@ -1,9 +1,7 @@ # http://www.pgroup.com -from __future__ import division, absolute_import, print_function - import sys -from numpy.distutils.fcompiler import FCompiler, dummy_fortran_file +from numpy.distutils.fcompiler import FCompiler from sys import platform from os.path import join, dirname, normpath @@ -64,72 +62,60 @@ class PGroupFCompiler(FCompiler): return '-R%s' % dir -if sys.version_info >= (3, 5): - import functools - - class PGroupFlangCompiler(FCompiler): - compiler_type = 'flang' - description = 'Portland Group Fortran LLVM Compiler' - version_pattern = r'\s*(flang|clang) version (?P<version>[\d.-]+).*' - - ar_exe = 'lib.exe' - possible_executables = ['flang'] - - executables = { - 'version_cmd': ["<F77>", "--version"], - 'compiler_f77': ["flang"], - 'compiler_fix': ["flang"], - 'compiler_f90': ["flang"], - 'linker_so': [None], - 'archiver': [ar_exe, "/verbose", "/OUT:"], - 'ranlib': None - } +import functools - library_switch = '/OUT:' # No space after /OUT:! - module_dir_switch = '-module ' # Don't remove ending space! +class PGroupFlangCompiler(FCompiler): + compiler_type = 'flang' + description = 'Portland Group Fortran LLVM Compiler' + version_pattern = r'\s*(flang|clang) version (?P<version>[\d.-]+).*' - def get_libraries(self): - opt = FCompiler.get_libraries(self) - opt.extend(['flang', 'flangrti', 'ompstub']) - return opt + ar_exe = 'lib.exe' + possible_executables = ['flang'] - @functools.lru_cache(maxsize=128) - def get_library_dirs(self): - """List of compiler library directories.""" - opt = FCompiler.get_library_dirs(self) - flang_dir = dirname(self.executables['compiler_f77'][0]) - opt.append(normpath(join(flang_dir, '..', 'lib'))) + executables = { + 'version_cmd': ["<F77>", "--version"], + 'compiler_f77': ["flang"], + 'compiler_fix': ["flang"], + 'compiler_f90': ["flang"], + 'linker_so': [None], + 'archiver': [ar_exe, "/verbose", "/OUT:"], + 'ranlib': None + } - return opt + library_switch = '/OUT:' # No space after /OUT:! + module_dir_switch = '-module ' # Don't remove ending space! - def get_flags(self): - return [] + def get_libraries(self): + opt = FCompiler.get_libraries(self) + opt.extend(['flang', 'flangrti', 'ompstub']) + return opt - def get_flags_free(self): - return [] + @functools.lru_cache(maxsize=128) + def get_library_dirs(self): + """List of compiler library directories.""" + opt = FCompiler.get_library_dirs(self) + flang_dir = dirname(self.executables['compiler_f77'][0]) + opt.append(normpath(join(flang_dir, '..', 'lib'))) - def get_flags_debug(self): - return ['-g'] + return opt - def get_flags_opt(self): - return ['-O3'] + def get_flags(self): + return [] - def get_flags_arch(self): - return [] + def get_flags_free(self): + return [] - def runtime_library_dir_option(self, dir): - raise NotImplementedError + def get_flags_debug(self): + return ['-g'] -else: - from numpy.distutils.fcompiler import CompilerNotFound + def get_flags_opt(self): + return ['-O3'] - # No point in supporting on older Pythons because not ABI compatible - class PGroupFlangCompiler(FCompiler): - compiler_type = 'flang' - description = 'Portland Group Fortran LLVM Compiler' + def get_flags_arch(self): + return [] - def get_version(self): - raise CompilerNotFound('Flang unsupported on Python < 3.5') + def runtime_library_dir_option(self, dir): + raise NotImplementedError if __name__ == '__main__': diff --git a/numpy/distutils/fcompiler/sun.py b/numpy/distutils/fcompiler/sun.py index 561ea854f..d039f0b25 100644 --- a/numpy/distutils/fcompiler/sun.py +++ b/numpy/distutils/fcompiler/sun.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - from numpy.distutils.ccompiler import simple_version_match from numpy.distutils.fcompiler import FCompiler diff --git a/numpy/distutils/fcompiler/vast.py b/numpy/distutils/fcompiler/vast.py index adc1591bd..92a1647ba 100644 --- a/numpy/distutils/fcompiler/vast.py +++ b/numpy/distutils/fcompiler/vast.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import os from numpy.distutils.fcompiler.gnu import GnuFCompiler diff --git a/numpy/distutils/from_template.py b/numpy/distutils/from_template.py index c5c1163c6..070b7d8b8 100644 --- a/numpy/distutils/from_template.py +++ b/numpy/distutils/from_template.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """ process_file(filename) @@ -45,8 +45,6 @@ process_file(filename) <ctypereal=float,double,\\0,\\1> """ -from __future__ import division, absolute_import, print_function - __all__ = ['process_str', 'process_file'] import os diff --git a/numpy/distutils/intelccompiler.py b/numpy/distutils/intelccompiler.py index 3386775ee..0388ad577 100644 --- a/numpy/distutils/intelccompiler.py +++ b/numpy/distutils/intelccompiler.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import platform from distutils.unixccompiler import UnixCCompiler diff --git a/numpy/distutils/lib2def.py b/numpy/distutils/lib2def.py index 2d013a1e3..820ed71f5 100644 --- a/numpy/distutils/lib2def.py +++ b/numpy/distutils/lib2def.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import re import sys import subprocess @@ -24,7 +22,7 @@ __version__ = '0.1a' py_ver = "%d%d" % tuple(sys.version_info[:2]) -DEFAULT_NM = 'nm -Cs' +DEFAULT_NM = ['nm', '-Cs'] DEF_HEADER = """LIBRARY python%s.dll ;CODE PRELOAD MOVEABLE DISCARDABLE @@ -61,13 +59,16 @@ libfile, deffile = parse_cmd()""" deffile = None return libfile, deffile -def getnm(nm_cmd = ['nm', '-Cs', 'python%s.lib' % py_ver]): +def getnm(nm_cmd=['nm', '-Cs', 'python%s.lib' % py_ver], shell=True): """Returns the output of nm_cmd via a pipe. -nm_output = getnam(nm_cmd = 'nm -Cs py_lib')""" - f = subprocess.Popen(nm_cmd, shell=True, stdout=subprocess.PIPE, universal_newlines=True) - nm_output = f.stdout.read() - f.stdout.close() +nm_output = getnm(nm_cmd = 'nm -Cs py_lib')""" + p = subprocess.Popen(nm_cmd, shell=shell, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, universal_newlines=True) + nm_output, nm_err = p.communicate() + if p.returncode != 0: + raise RuntimeError('failed to run "%s": "%s"' % ( + ' '.join(nm_cmd), nm_err)) return nm_output def parse_nm(nm_output): @@ -109,7 +110,7 @@ if __name__ == '__main__': deffile = sys.stdout else: deffile = open(deffile, 'w') - nm_cmd = [str(DEFAULT_NM), str(libfile)] - nm_output = getnm(nm_cmd) + nm_cmd = DEFAULT_NM + [str(libfile)] + nm_output = getnm(nm_cmd, shell=False) dlist, flist = parse_nm(nm_output) output_def(dlist, flist, DEF_HEADER, deffile) diff --git a/numpy/distutils/line_endings.py b/numpy/distutils/line_endings.py index fe8fd1b0f..686e5ebd9 100644 --- a/numpy/distutils/line_endings.py +++ b/numpy/distutils/line_endings.py @@ -1,9 +1,10 @@ """ Functions for converting from DOS to UNIX line endings """ -from __future__ import division, absolute_import, print_function +import os +import re +import sys -import sys, re, os def dos2unix(file): "Replace CRLF with LF in argument files. Print names of changed files." diff --git a/numpy/distutils/log.py b/numpy/distutils/log.py index ff7de86b1..a8113b9c6 100644 --- a/numpy/distutils/log.py +++ b/numpy/distutils/log.py @@ -1,17 +1,11 @@ -# Colored log, requires Python 2.3 or up. -from __future__ import division, absolute_import, print_function - +# Colored log import sys -from distutils.log import * +from distutils.log import * # noqa: F403 from distutils.log import Log as old_Log from distutils.log import _global_log -if sys.version_info[0] < 3: - from .misc_util import (red_text, default_text, cyan_text, green_text, - is_sequence, is_string) -else: - from numpy.distutils.misc_util import (red_text, default_text, cyan_text, - green_text, is_sequence, is_string) +from numpy.distutils.misc_util import (red_text, default_text, cyan_text, + green_text, is_sequence, is_string) def _fix_args(args,flag=1): diff --git a/numpy/distutils/mingw32ccompiler.py b/numpy/distutils/mingw32ccompiler.py index 075858cfe..7cb6fadcc 100644 --- a/numpy/distutils/mingw32ccompiler.py +++ b/numpy/distutils/mingw32ccompiler.py @@ -7,8 +7,6 @@ Support code for building Python extensions on Windows. # 3. Force windows to use g77 """ -from __future__ import division, absolute_import, print_function - import os import sys import subprocess @@ -16,12 +14,8 @@ import re import textwrap # Overwrite certain distutils.ccompiler functions: -import numpy.distutils.ccompiler - -if sys.version_info[0] < 3: - from . import log -else: - from numpy.distutils import log +import numpy.distutils.ccompiler # noqa: F401 +from numpy.distutils import log # NT stuff # 1. Make sure libpython<version>.a exists for gcc. If not, build it. # 2. Force windows to use gcc (we're struggling with MSVC and g77 support) @@ -32,8 +26,7 @@ import distutils.cygwinccompiler from distutils.version import StrictVersion from distutils.unixccompiler import UnixCCompiler from distutils.msvccompiler import get_build_version as get_build_msvc_version -from distutils.errors import (DistutilsExecError, CompileError, - UnknownFileError) +from distutils.errors import UnknownFileError from numpy.distutils.misc_util import (msvc_runtime_library, msvc_runtime_version, msvc_runtime_major, @@ -71,10 +64,10 @@ 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: - p = subprocess.Popen(['gcc', '-dumpversion'], shell=True, - stdout=subprocess.PIPE) - out_string = p.stdout.read() - p.stdout.close() + try: + out_string = subprocess.check_output(['gcc', '-dumpversion']) + except (OSError, CalledProcessError): + out_string = "" # ignore failures to match old behavior result = re.search(r'(\d+\.\d+)', out_string) if result: self.gcc_version = StrictVersion(result.group(1)) @@ -285,8 +278,8 @@ def find_python_dll(): raise ValueError("%s not found in %s" % (dllname, lib_dirs)) def dump_table(dll): - st = subprocess.Popen(["objdump.exe", "-p", dll], stdout=subprocess.PIPE) - return st.stdout.readlines() + st = subprocess.check_output(["objdump.exe", "-p", dll]) + return st.split(b'\n') def generate_def(dll, dfile): """Given a dll file location, get all its exported symbols and dump them @@ -311,15 +304,14 @@ def generate_def(dll, dfile): if len(syms) == 0: log.warn('No symbols found in %s' % dll) - d = open(dfile, 'w') - d.write('LIBRARY %s\n' % os.path.basename(dll)) - d.write(';CODE PRELOAD MOVEABLE DISCARDABLE\n') - d.write(';DATA PRELOAD SINGLE\n') - d.write('\nEXPORTS\n') - for s in syms: - #d.write('@%d %s\n' % (s[0], s[1])) - d.write('%s\n' % s[1]) - d.close() + with open(dfile, 'w') as d: + d.write('LIBRARY %s\n' % os.path.basename(dll)) + d.write(';CODE PRELOAD MOVEABLE DISCARDABLE\n') + d.write(';DATA PRELOAD SINGLE\n') + d.write('\nEXPORTS\n') + for s in syms: + #d.write('@%d %s\n' % (s[0], s[1])) + d.write('%s\n' % s[1]) def find_dll(dll_name): @@ -472,7 +464,7 @@ def _build_import_library_amd64(): # generate import library from this symbol list cmd = ['dlltool', '-d', def_file, '-l', out_file] - subprocess.Popen(cmd) + subprocess.check_call(cmd) def _build_import_library_x86(): """ Build the import libraries for Mingw32-gcc on Windows @@ -506,16 +498,19 @@ def _build_import_library_x86(): def_name = "python%d%d.def" % tuple(sys.version_info[:2]) def_file = os.path.join(sys.prefix, 'libs', def_name) - nm_cmd = '%s %s' % (lib2def.DEFAULT_NM, lib_file) - nm_output = lib2def.getnm(nm_cmd) + nm_output = lib2def.getnm( + lib2def.DEFAULT_NM + [lib_file], shell=False) dlist, flist = lib2def.parse_nm(nm_output) - lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, open(def_file, 'w')) + with open(def_file, 'w') as fid: + lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, fid) dll_name = find_python_dll () - args = (dll_name, def_file, out_file) - cmd = 'dlltool --dllname "%s" --def "%s" --output-lib "%s"' % args - status = os.system(cmd) - # for now, fail silently + + cmd = ["dlltool", + "--dllname", dll_name, + "--def", def_file, + "--output-lib", out_file] + status = subprocess.check_output(cmd) if status: log.warn('Failed to build import library for gcc. Linking will fail.') return @@ -548,6 +543,8 @@ if sys.platform == 'win32': # Value from msvcrt.CRT_ASSEMBLY_VERSION under Python 3.3.0 # on Windows XP: _MSVCRVER_TO_FULLVER['100'] = "10.0.30319.460" + # Python 3.7 uses 1415, but get_build_version returns 140 ?? + _MSVCRVER_TO_FULLVER['140'] = "14.15.26726.0" if hasattr(msvcrt, "CRT_ASSEMBLY_VERSION"): major, minor, rest = msvcrt.CRT_ASSEMBLY_VERSION.split(".", 2) _MSVCRVER_TO_FULLVER[major + minor] = msvcrt.CRT_ASSEMBLY_VERSION diff --git a/numpy/distutils/misc_util.py b/numpy/distutils/misc_util.py index 7ba8ad862..9f9e9f1ac 100644 --- a/numpy/distutils/misc_util.py +++ b/numpy/distutils/misc_util.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import os import re import sys @@ -34,8 +32,6 @@ def clean_up_temporary_directory(): atexit.register(clean_up_temporary_directory) -from numpy.distutils.compat import get_exception -from numpy.compat import basestring from numpy.compat import npy_load_module __all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict', @@ -51,7 +47,7 @@ __all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict', 'quote_args', 'get_build_architecture', 'get_info', 'get_pkg_info', 'get_num_build_jobs'] -class InstallableLib(object): +class InstallableLib: """ Container to hold information on an installable library. @@ -168,7 +164,6 @@ def get_path_from_frame(frame, parent_path=None): # we're probably running setup.py as execfile("setup.py") # (likely we're building an egg) d = os.path.abspath('.') - # hmm, should we use sys.argv[0] like in __builtin__ case? if parent_path is not None: d = rel_path(d, parent_path) @@ -453,7 +448,7 @@ def _get_f90_modules(source): return modules def is_string(s): - return isinstance(s, basestring) + return isinstance(s, str) def all_strings(lst): """Return True if all items in lst are string objects. """ @@ -728,7 +723,7 @@ def get_frame(level=0): ###################### -class Configuration(object): +class Configuration: _list_keys = ['packages', 'ext_modules', 'data_files', 'include_dirs', 'libraries', 'headers', 'scripts', 'py_modules', @@ -926,18 +921,8 @@ class Configuration(object): else: pn = dot_join(*([parent_name] + subpackage_name.split('.')[:-1])) args = (pn,) - def fix_args_py2(args): - if setup_module.configuration.__code__.co_argcount > 1: - args = args + (self.top_path,) - return args - def fix_args_py3(args): - if setup_module.configuration.__code__.co_argcount > 1: - args = args + (self.top_path,) - return args - if sys.version_info[0] < 3: - args = fix_args_py2(args) - else: - args = fix_args_py3(args) + if setup_module.configuration.__code__.co_argcount > 1: + args = args + (self.top_path,) config = setup_module.configuration(*args) if config.name!=dot_join(parent_name, subpackage_name): self.warn('Subpackage %r configuration returned as %r' % \ @@ -1868,8 +1853,7 @@ class Configuration(object): """Return path's SVN revision number. """ try: - output = subprocess.check_output( - ['svnversion'], shell=True, cwd=path) + output = subprocess.check_output(['svnversion'], cwd=path) except (subprocess.CalledProcessError, OSError): pass else: @@ -1899,7 +1883,7 @@ class Configuration(object): """ try: output = subprocess.check_output( - ['hg identify --num'], shell=True, cwd=path) + ['hg', 'identify', '--num'], cwd=path) except (subprocess.CalledProcessError, OSError): pass else: @@ -1972,9 +1956,8 @@ class Configuration(object): try: version_module = npy_load_module('_'.join(n.split('.')), fn, info) - except ImportError: - msg = get_exception() - self.warn(str(msg)) + except ImportError as e: + self.warn(str(e)) version_module = None if version_module is None: continue @@ -2246,10 +2229,7 @@ def get_info(pkgname, dirs=None): return info def is_bootstrapping(): - if sys.version_info[0] >= 3: - import builtins - else: - import __builtin__ as builtins + import builtins try: builtins.__NUMPY_SETUP__ @@ -2329,8 +2309,11 @@ def generate_config_py(target): extra_dll_dir = os.path.join(os.path.dirname(__file__), '.libs') if sys.platform == 'win32' and os.path.isdir(extra_dll_dir): - os.environ.setdefault('PATH', '') - os.environ['PATH'] += os.pathsep + extra_dll_dir + if sys.version_info >= (3, 8): + os.add_dll_directory(extra_dll_dir) + else: + os.environ.setdefault('PATH', '') + os.environ['PATH'] += os.pathsep + extra_dll_dir """)) @@ -2342,6 +2325,43 @@ def generate_config_py(target): return g.get(name, g.get(name + "_info", {})) def show(): + """ + Show libraries in the system on which NumPy was built. + + Print information about various resources (libraries, library + directories, include directories, etc.) in the system on which + NumPy was built. + + See Also + -------- + get_include : Returns the directory containing NumPy C + header files. + + Notes + ----- + Classes specifying the information to be printed are defined + in the `numpy.distutils.system_info` module. + + Information may include: + + * ``language``: language used to write the libraries (mostly + C or f77) + * ``libraries``: names of libraries found in the system + * ``library_dirs``: directories containing the libraries + * ``include_dirs``: directories containing library header files + * ``src_dirs``: directories containing library source files + * ``define_macros``: preprocessor macros used by + ``distutils.setup`` + + Examples + -------- + >>> np.show_config() + blas_opt_info: + language = c + define_macros = [('HAVE_CBLAS', None)] + libraries = ['openblas', 'openblas'] + library_dirs = ['/usr/local/lib'] + """ for name,info_dict in globals().items(): if name[0] == "_" or type(info_dict) is not type({}): continue print(name + ":") diff --git a/numpy/distutils/msvc9compiler.py b/numpy/distutils/msvc9compiler.py index e9cc334a5..68239495d 100644 --- a/numpy/distutils/msvc9compiler.py +++ b/numpy/distutils/msvc9compiler.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import os from distutils.msvc9compiler import MSVCCompiler as _MSVCCompiler diff --git a/numpy/distutils/msvccompiler.py b/numpy/distutils/msvccompiler.py index 0cb4bf979..681a254b8 100644 --- a/numpy/distutils/msvccompiler.py +++ b/numpy/distutils/msvccompiler.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import os from distutils.msvccompiler import MSVCCompiler as _MSVCCompiler diff --git a/numpy/distutils/npy_pkg_config.py b/numpy/distutils/npy_pkg_config.py index 48584b4c4..951ce5fb8 100644 --- a/numpy/distutils/npy_pkg_config.py +++ b/numpy/distutils/npy_pkg_config.py @@ -1,13 +1,8 @@ -from __future__ import division, absolute_import, print_function - import sys import re import os -if sys.version_info[0] < 3: - from ConfigParser import RawConfigParser -else: - from configparser import RawConfigParser +from configparser import RawConfigParser __all__ = ['FormatError', 'PkgNotFound', 'LibraryInfo', 'VariableSet', 'read_config', 'parse_flags'] @@ -78,7 +73,7 @@ def parse_flags(line): def _escape_backslash(val): return val.replace('\\', '\\\\') -class LibraryInfo(object): +class LibraryInfo: """ Object containing build information about a library. @@ -150,7 +145,7 @@ class LibraryInfo(object): return "\n".join(m) -class VariableSet(object): +class VariableSet: """ Container object for the variables defined in a config file. @@ -380,7 +375,6 @@ def read_config(pkgname, dirs=None): # pkg-config simple emulator - useful for debugging, and maybe later to query # the system if __name__ == '__main__': - import sys from optparse import OptionParser import glob diff --git a/numpy/distutils/numpy_distribution.py b/numpy/distutils/numpy_distribution.py index 6ae19d16b..ea8182659 100644 --- a/numpy/distutils/numpy_distribution.py +++ b/numpy/distutils/numpy_distribution.py @@ -1,6 +1,4 @@ # XXX: Handle setuptools ? -from __future__ import division, absolute_import, print_function - from distutils.core import Distribution # This class is used because we add new files (sconscripts, and so on) with the diff --git a/numpy/distutils/pathccompiler.py b/numpy/distutils/pathccompiler.py index fc9872db3..48051810e 100644 --- a/numpy/distutils/pathccompiler.py +++ b/numpy/distutils/pathccompiler.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - from distutils.unixccompiler import UnixCCompiler class PathScaleCCompiler(UnixCCompiler): diff --git a/numpy/distutils/setup.py b/numpy/distutils/setup.py index 82a53bd08..69d35f5c2 100644 --- a/numpy/distutils/setup.py +++ b/numpy/distutils/setup.py @@ -1,6 +1,4 @@ -#!/usr/bin/env python -from __future__ import division, print_function - +#!/usr/bin/env python3 def configuration(parent_package='',top_path=None): from numpy.distutils.misc_util import Configuration config = Configuration('distutils', parent_package, top_path) diff --git a/numpy/distutils/system_info.py b/numpy/distutils/system_info.py index 5fd1003ab..3a6a7b29d 100644 --- a/numpy/distutils/system_info.py +++ b/numpy/distutils/system_info.py @@ -1,51 +1,8 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """ This file defines a set of system_info classes for getting information about various resources (libraries, library directories, -include directories, etc.) in the system. Currently, the following -classes are available: - - atlas_info - atlas_threads_info - atlas_blas_info - atlas_blas_threads_info - lapack_atlas_info - lapack_atlas_threads_info - atlas_3_10_info - atlas_3_10_threads_info - atlas_3_10_blas_info, - atlas_3_10_blas_threads_info, - lapack_atlas_3_10_info - lapack_atlas_3_10_threads_info - flame_info - blas_info - lapack_info - openblas_info - blis_info - blas_opt_info # usage recommended - lapack_opt_info # usage recommended - fftw_info,dfftw_info,sfftw_info - fftw_threads_info,dfftw_threads_info,sfftw_threads_info - djbfft_info - x11_info - lapack_src_info - blas_src_info - numpy_info - numarray_info - numpy_info - boost_python_info - agg2_info - wx_info - gdk_pixbuf_xlib_2_info - gdk_pixbuf_2_info - gdk_x11_2_info - gtkp_x11_2_info - gtkp_2_info - xft_info - freetype2_info - umfpack_info - -Usage: +include directories, etc.) in the system. Usage: info_dict = get_info(<name>) where <name> is a string 'atlas','x11','fftw','lapack','blas', 'lapack_src', 'blas_src', etc. For a complete list of allowed names, @@ -73,19 +30,94 @@ The file 'site.cfg' is looked for in The first one found is used to get system configuration options The format is that used by ConfigParser (i.e., Windows .INI style). The -section ALL has options that are the default for each section. The -available sections are fftw, atlas, and x11. Appropriate defaults are -used if nothing is specified. +section ALL is not intended for general use. + +Appropriate defaults are used if nothing is specified. The order of finding the locations of resources is the following: 1. environment variable 2. section in site.cfg - 3. ALL section in site.cfg + 3. DEFAULT section in site.cfg + 4. System default search paths (see ``default_*`` variables below). Only the first complete match is returned. +Currently, the following classes are available, along with their section names: + + Numeric_info:Numeric + _numpy_info:Numeric + _pkg_config_info:None + accelerate_info:accelerate + agg2_info:agg2 + amd_info:amd + atlas_3_10_blas_info:atlas + atlas_3_10_blas_threads_info:atlas + atlas_3_10_info:atlas + atlas_3_10_threads_info:atlas + atlas_blas_info:atlas + atlas_blas_threads_info:atlas + atlas_info:atlas + atlas_threads_info:atlas + blas64__opt_info:ALL # usage recommended (general ILP64 BLAS, 64_ symbol suffix) + blas_ilp64_opt_info:ALL # usage recommended (general ILP64 BLAS) + blas_ilp64_plain_opt_info:ALL # usage recommended (general ILP64 BLAS, no symbol suffix) + blas_info:blas + blas_mkl_info:mkl + blas_opt_info:ALL # usage recommended + blas_src_info:blas_src + blis_info:blis + boost_python_info:boost_python + dfftw_info:fftw + dfftw_threads_info:fftw + djbfft_info:djbfft + f2py_info:ALL + fft_opt_info:ALL + fftw2_info:fftw + fftw3_info:fftw3 + fftw_info:fftw + fftw_threads_info:fftw + flame_info:flame + freetype2_info:freetype2 + gdk_2_info:gdk_2 + gdk_info:gdk + gdk_pixbuf_2_info:gdk_pixbuf_2 + gdk_pixbuf_xlib_2_info:gdk_pixbuf_xlib_2 + gdk_x11_2_info:gdk_x11_2 + gtkp_2_info:gtkp_2 + gtkp_x11_2_info:gtkp_x11_2 + lapack64__opt_info:ALL # usage recommended (general ILP64 LAPACK, 64_ symbol suffix) + lapack_atlas_3_10_info:atlas + lapack_atlas_3_10_threads_info:atlas + lapack_atlas_info:atlas + lapack_atlas_threads_info:atlas + lapack_ilp64_opt_info:ALL # usage recommended (general ILP64 LAPACK) + lapack_ilp64_plain_opt_info:ALL # usage recommended (general ILP64 LAPACK, no symbol suffix) + lapack_info:lapack + lapack_mkl_info:mkl + lapack_opt_info:ALL # usage recommended + lapack_src_info:lapack_src + mkl_info:mkl + numarray_info:numarray + numerix_info:numerix + numpy_info:numpy + openblas64__info:openblas64_ + openblas64__lapack_info:openblas64_ + openblas_clapack_info:openblas + openblas_ilp64_info:openblas_ilp64 + openblas_ilp64_lapack_info:openblas_ilp64 + openblas_info:openblas + openblas_lapack_info:openblas + sfftw_info:fftw + sfftw_threads_info:fftw + system_info:ALL + umfpack_info:umfpack + wx_info:wx + x11_info:x11 + xft_info:xft + Example: ---------- -[ALL] +[DEFAULT] +# default section library_dirs = /usr/lib:/usr/local/lib:/opt/lib include_dirs = /usr/include:/usr/local/include:/opt/include src_dirs = /usr/local/src:/opt/src @@ -120,8 +152,6 @@ this distribution for specifics. NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. """ -from __future__ import division, absolute_import, print_function - import sys import os import re @@ -132,12 +162,8 @@ import textwrap from glob import glob from functools import reduce -if sys.version_info[0] < 3: - from ConfigParser import NoOptionError - from ConfigParser import RawConfigParser as ConfigParser -else: - from configparser import NoOptionError - from configparser import RawConfigParser as ConfigParser +from configparser import NoOptionError +from configparser import RawConfigParser as ConfigParser # It seems that some people are importing ConfigParser from here so is # good to keep its class name. Use of RawConfigParser is needed in # order to be able to load path names with percent in them, like @@ -151,12 +177,11 @@ from distutils.util import get_platform from numpy.distutils.exec_command import ( 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 -from numpy.distutils.compat import get_exception -from numpy.distutils import customized_ccompiler +from numpy.distutils import customized_ccompiler as _customized_ccompiler from numpy.distutils import _shell_utils import distutils.ccompiler import tempfile @@ -169,6 +194,15 @@ _bits = {'32bit': 32, '64bit': 64} platform_bits = _bits[platform.architecture()[0]] +global_compiler = None + +def customized_ccompiler(): + global global_compiler + if not global_compiler: + global_compiler = _customized_ccompiler() + return global_compiler + + def _c_string_literal(s): """ Convert a python string into a literal suitable for inclusion into C code @@ -250,32 +284,29 @@ if sys.platform == 'win32': default_include_dirs.extend( os.path.join(library_root, d) for d in _include_dirs) - if sys.version_info >= (3, 3): - # VCpkg is the de-facto package manager on windows for C/C++ - # libraries. If it is on the PATH, then we append its paths here. - # We also don't re-implement shutil.which for Python 2.7 because - # vcpkg doesn't support MSVC 2008. - vcpkg = shutil.which('vcpkg') - if vcpkg: - vcpkg_dir = os.path.dirname(vcpkg) - if platform.architecture() == '32bit': - specifier = 'x86' - else: - specifier = 'x64' - - vcpkg_installed = os.path.join(vcpkg_dir, 'installed') - for vcpkg_root in [ - os.path.join(vcpkg_installed, specifier + '-windows'), - os.path.join(vcpkg_installed, specifier + '-windows-static'), - ]: - add_system_root(vcpkg_root) - - # Conda is another popular package manager that provides libraries - conda = shutil.which('conda') - if conda: - conda_dir = os.path.dirname(conda) - add_system_root(os.path.join(conda_dir, '..', 'Library')) - add_system_root(os.path.join(conda_dir, 'Library')) + # VCpkg is the de-facto package manager on windows for C/C++ + # libraries. If it is on the PATH, then we append its paths here. + vcpkg = shutil.which('vcpkg') + if vcpkg: + vcpkg_dir = os.path.dirname(vcpkg) + if platform.architecture() == '32bit': + specifier = 'x86' + else: + specifier = 'x64' + + vcpkg_installed = os.path.join(vcpkg_dir, 'installed') + for vcpkg_root in [ + os.path.join(vcpkg_installed, specifier + '-windows'), + os.path.join(vcpkg_installed, specifier + '-windows-static'), + ]: + add_system_root(vcpkg_root) + + # Conda is another popular package manager that provides libraries + conda = shutil.which('conda') + if conda: + conda_dir = os.path.dirname(conda) + add_system_root(os.path.join(conda_dir, '..', 'Library')) + add_system_root(os.path.join(conda_dir, 'Library')) else: default_lib_dirs = libpaths(['/usr/local/lib', '/opt/lib', '/usr/lib', @@ -397,6 +428,10 @@ def get_info(name, notfound_action=0): 'lapack_mkl': lapack_mkl_info, # use lapack_opt instead 'blas_mkl': blas_mkl_info, # use blas_opt instead 'accelerate': accelerate_info, # use blas_opt instead + 'openblas64_': openblas64__info, + 'openblas64__lapack': openblas64__lapack_info, + 'openblas_ilp64': openblas_ilp64_info, + 'openblas_ilp64_lapack': openblas_ilp64_lapack_info, 'x11': x11_info, 'fft_opt': fft_opt_info, 'fftw': fftw_info, @@ -419,7 +454,13 @@ def get_info(name, notfound_action=0): 'numarray': numarray_info, 'numerix': numerix_info, 'lapack_opt': lapack_opt_info, + 'lapack_ilp64_opt': lapack_ilp64_opt_info, + 'lapack_ilp64_plain_opt': lapack_ilp64_plain_opt_info, + 'lapack64__opt': lapack64__opt_info, 'blas_opt': blas_opt_info, + 'blas_ilp64_opt': blas_ilp64_opt_info, + 'blas_ilp64_plain_opt': blas_ilp64_plain_opt_info, + 'blas64__opt': blas64__opt_info, 'boost_python': boost_python_info, 'agg2': agg2_info, 'wx': wx_info, @@ -485,6 +526,13 @@ class LapackSrcNotFoundError(LapackNotFoundError): the LAPACK_SRC environment variable.""" +class LapackILP64NotFoundError(NotFoundError): + """ + 64-bit Lapack libraries not found. + Known libraries in numpy/distutils/site.cfg file are: + openblas64_, openblas_ilp64 + """ + class BlasOptNotFoundError(NotFoundError): """ Optimized (vendor) Blas libraries are not found. @@ -499,6 +547,12 @@ class BlasNotFoundError(NotFoundError): numpy/distutils/site.cfg file (section [blas]) or by setting the BLAS environment variable.""" +class BlasILP64NotFoundError(NotFoundError): + """ + 64-bit Blas libraries not found. + Known libraries in numpy/distutils/site.cfg file are: + openblas64_, openblas_ilp64 + """ class BlasSrcNotFoundError(BlasNotFoundError): """ @@ -542,14 +596,18 @@ class UmfpackNotFoundError(NotFoundError): the UMFPACK environment variable.""" -class system_info(object): +class system_info: """ get_info() is the only public method. Don't use others. """ - section = 'ALL' dir_env_var = None - search_static_first = 0 # XXX: disabled by default, may disappear in - # future unless it is proved to be useful. + # XXX: search_static_first is disabled by default, may disappear in + # future unless it is proved to be useful. + search_static_first = 0 + # The base-class section name is a random word "ALL" and is not really + # intended for general use. It cannot be None nor can it be DEFAULT as + # these break the ConfigParser. See gh-15338 + section = 'ALL' saved_results = {} notfounderror = NotFoundError @@ -677,7 +735,7 @@ class system_info(object): return info def get_info(self, notfound_action=0): - """ Return a dictonary with items that are compatible + """ Return a dictionary with items that are compatible with numpy.distutils.setup keyword arguments. """ flag = 0 @@ -1580,7 +1638,7 @@ def get_atlas_version(**config): log.info('Status: %d', s) log.info('Output: %s', o) - if atlas_version == '3.2.1_pre3.3.6': + elif atlas_version == '3.2.1_pre3.3.6': dict_append(info, define_macros=[('NO_ATLAS_INFO', -2)]) else: dict_append(info, define_macros=[( @@ -1591,10 +1649,10 @@ def get_atlas_version(**config): class lapack_opt_info(system_info): - notfounderror = LapackNotFoundError - # Default order of LAPACK checks + # List of all known BLAS libraries, in the default order lapack_order = ['mkl', 'openblas', 'flame', 'atlas', 'accelerate', 'lapack'] + order_env_var_name = 'NPY_LAPACK_ORDER' def _calc_info_mkl(self): info = get_info('lapack_mkl') @@ -1686,8 +1744,11 @@ class lapack_opt_info(system_info): return True return False + def _calc_info(self, name): + return getattr(self, '_calc_info_{}'.format(name))() + def calc_info(self): - user_order = os.environ.get('NPY_LAPACK_ORDER', None) + user_order = os.environ.get(self.order_env_var_name, None) if user_order is None: lapack_order = self.lapack_order else: @@ -1707,7 +1768,7 @@ class lapack_opt_info(system_info): "values: {}".format(non_existing)) for lapack in lapack_order: - if getattr(self, '_calc_info_{}'.format(lapack))(): + if self._calc_info(lapack): return if 'lapack' not in lapack_order: @@ -1717,11 +1778,53 @@ class lapack_opt_info(system_info): warnings.warn(LapackSrcNotFoundError.__doc__ or '', stacklevel=2) -class blas_opt_info(system_info): +class _ilp64_opt_info_mixin: + symbol_suffix = None + symbol_prefix = None + + def _check_info(self, info): + macros = dict(info.get('define_macros', [])) + prefix = macros.get('BLAS_SYMBOL_PREFIX', '') + suffix = macros.get('BLAS_SYMBOL_SUFFIX', '') + + if self.symbol_prefix not in (None, prefix): + return False + + if self.symbol_suffix not in (None, suffix): + return False + return bool(info) + + +class lapack_ilp64_opt_info(lapack_opt_info, _ilp64_opt_info_mixin): + notfounderror = LapackILP64NotFoundError + lapack_order = ['openblas64_', 'openblas_ilp64'] + order_env_var_name = 'NPY_LAPACK_ILP64_ORDER' + + def _calc_info(self, name): + info = get_info(name + '_lapack') + if self._check_info(info): + self.set_info(**info) + return True + return False + + +class lapack_ilp64_plain_opt_info(lapack_ilp64_opt_info): + # Same as lapack_ilp64_opt_info, but fix symbol names + symbol_prefix = '' + symbol_suffix = '' + + +class lapack64__opt_info(lapack_ilp64_opt_info): + symbol_prefix = '' + symbol_suffix = '64_' + + +class blas_opt_info(system_info): notfounderror = BlasNotFoundError - # Default order of BLAS checks + # List of all known BLAS libraries, in the default order blas_order = ['mkl', 'blis', 'openblas', 'atlas', 'accelerate', 'blas'] + order_env_var_name = 'NPY_BLAS_ORDER' def _calc_info_mkl(self): info = get_info('blas_mkl') @@ -1786,8 +1889,11 @@ class blas_opt_info(system_info): self.set_info(**info) return True + def _calc_info(self, name): + return getattr(self, '_calc_info_{}'.format(name))() + def calc_info(self): - user_order = os.environ.get('NPY_BLAS_ORDER', None) + user_order = os.environ.get(self.order_env_var_name, None) if user_order is None: blas_order = self.blas_order else: @@ -1805,7 +1911,7 @@ class blas_opt_info(system_info): raise ValueError("blas_opt_info user defined BLAS order has unacceptable values: {}".format(non_existing)) for blas in blas_order: - if getattr(self, '_calc_info_{}'.format(blas))(): + if self._calc_info(blas): return if 'blas' not in blas_order: @@ -1815,6 +1921,29 @@ class blas_opt_info(system_info): warnings.warn(BlasSrcNotFoundError.__doc__ or '', stacklevel=2) +class blas_ilp64_opt_info(blas_opt_info, _ilp64_opt_info_mixin): + notfounderror = BlasILP64NotFoundError + blas_order = ['openblas64_', 'openblas_ilp64'] + order_env_var_name = 'NPY_BLAS_ILP64_ORDER' + + def _calc_info(self, name): + info = get_info(name) + if self._check_info(info): + self.set_info(**info) + return True + return False + + +class blas_ilp64_plain_opt_info(blas_ilp64_opt_info): + symbol_prefix = '' + symbol_suffix = '' + + +class blas64__opt_info(blas_ilp64_opt_info): + symbol_prefix = '' + symbol_suffix = '64_' + + class blas_info(system_info): section = 'blas' dir_env_var = 'BLAS' @@ -1914,12 +2043,24 @@ class openblas_info(blas_info): section = 'openblas' dir_env_var = 'OPENBLAS' _lib_names = ['openblas'] + _require_symbols = [] notfounderror = BlasNotFoundError - def check_embedded_lapack(self, info): - return True + @property + def symbol_prefix(self): + try: + return self.cp.get(self.section, 'symbol_prefix') + except NoOptionError: + return '' - def calc_info(self): + @property + def symbol_suffix(self): + try: + return self.cp.get(self.section, 'symbol_suffix') + except NoOptionError: + return '' + + def _calc_info(self): c = customized_ccompiler() lib_dirs = self.get_lib_dirs() @@ -1937,23 +2078,33 @@ class openblas_info(blas_info): # Try gfortran-compatible library files info = self.check_msvc_gfortran_libs(lib_dirs, openblas_libs) # Skip lapack check, we'd need build_ext to do it - assume_lapack = True + skip_symbol_check = True elif info: - assume_lapack = False + skip_symbol_check = False info['language'] = 'c' if info is None: - return + return None # Add extra info for OpenBLAS extra_info = self.calc_extra_info() dict_append(info, **extra_info) - if not (assume_lapack or self.check_embedded_lapack(info)): - return + if not (skip_symbol_check or self.check_symbols(info)): + return None info['define_macros'] = [('HAVE_CBLAS', None)] - self.set_info(**info) + if self.symbol_prefix: + info['define_macros'] += [('BLAS_SYMBOL_PREFIX', self.symbol_prefix)] + if self.symbol_suffix: + info['define_macros'] += [('BLAS_SYMBOL_SUFFIX', self.symbol_suffix)] + + return info + + def calc_info(self): + info = self._calc_info() + if info is not None: + self.set_info(**info) def check_msvc_gfortran_libs(self, library_dirs, libraries): # First, find the full path to each library directory @@ -1969,16 +2120,17 @@ class openblas_info(blas_info): return None # Generate numpy.distutils virtual static library file - tmpdir = os.path.join(os.getcwd(), 'build', 'openblas') + basename = self.__class__.__name__ + tmpdir = os.path.join(os.getcwd(), 'build', basename) if not os.path.isdir(tmpdir): os.makedirs(tmpdir) info = {'library_dirs': [tmpdir], - 'libraries': ['openblas'], + 'libraries': [basename], 'language': 'f77'} - fake_lib_file = os.path.join(tmpdir, 'openblas.fobjects') - fake_clib_file = os.path.join(tmpdir, 'openblas.cobjects') + fake_lib_file = os.path.join(tmpdir, basename + '.fobjects') + fake_clib_file = os.path.join(tmpdir, basename + '.cobjects') with open(fake_lib_file, 'w') as f: f.write("\n".join(library_paths)) with open(fake_clib_file, 'w') as f: @@ -1986,24 +2138,27 @@ class openblas_info(blas_info): return info -class openblas_lapack_info(openblas_info): - section = 'openblas' - dir_env_var = 'OPENBLAS' - _lib_names = ['openblas'] - notfounderror = BlasNotFoundError - - def check_embedded_lapack(self, info): + def check_symbols(self, info): res = False c = customized_ccompiler() tmpdir = tempfile.mkdtemp() + + prototypes = "\n".join("void %s%s%s();" % (self.symbol_prefix, + symbol_name, + self.symbol_suffix) + for symbol_name in self._require_symbols) + calls = "\n".join("%s%s%s();" % (self.symbol_prefix, + symbol_name, + self.symbol_suffix) + for symbol_name in self._require_symbols) s = textwrap.dedent("""\ - void zungqr_(); + %(prototypes)s int main(int argc, const char *argv[]) { - zungqr_(); + %(calls)s return 0; - }""") + }""") % dict(prototypes=prototypes, calls=calls) src = os.path.join(tmpdir, 'source.c') out = os.path.join(tmpdir, 'a.out') # Add the additional "extra" arguments @@ -2011,8 +2166,6 @@ class openblas_lapack_info(openblas_info): extra_args = info['extra_link_args'] except Exception: extra_args = [] - if sys.version_info < (3, 5) and sys.version_info > (3, 0) and c.compiler_type == "msvc": - extra_args.append("/MANIFEST") try: with open(src, 'wt') as f: f.write(s) @@ -2028,9 +2181,49 @@ class openblas_lapack_info(openblas_info): shutil.rmtree(tmpdir) return res +class openblas_lapack_info(openblas_info): + section = 'openblas' + dir_env_var = 'OPENBLAS' + _lib_names = ['openblas'] + _require_symbols = ['zungqr_'] + notfounderror = BlasNotFoundError + class openblas_clapack_info(openblas_lapack_info): _lib_names = ['openblas', 'lapack'] +class openblas_ilp64_info(openblas_info): + section = 'openblas_ilp64' + dir_env_var = 'OPENBLAS_ILP64' + _lib_names = ['openblas64'] + _require_symbols = ['dgemm_', 'cblas_dgemm'] + notfounderror = BlasILP64NotFoundError + + def _calc_info(self): + info = super()._calc_info() + if info is not None: + info['define_macros'] += [('HAVE_BLAS_ILP64', None)] + return info + +class openblas_ilp64_lapack_info(openblas_ilp64_info): + _require_symbols = ['dgemm_', 'cblas_dgemm', 'zungqr_', 'LAPACKE_zungqr'] + + def _calc_info(self): + info = super()._calc_info() + if info: + info['define_macros'] += [('HAVE_LAPACKE', None)] + return info + +class openblas64__info(openblas_ilp64_info): + # ILP64 Openblas, with default symbol suffix + section = 'openblas64_' + dir_env_var = 'OPENBLAS64_' + _lib_names = ['openblas64_'] + symbol_suffix = '64_' + symbol_prefix = '' + +class openblas64__lapack_info(openblas_ilp64_lapack_info, openblas64__info): + pass + class blis_info(blas_info): section = 'blis' dir_env_var = 'BLIS' @@ -2364,18 +2557,18 @@ class numerix_info(system_info): try: import numpy # noqa: F401 which = "numpy", "defaulted" - except ImportError: - msg1 = str(get_exception()) + except ImportError as e: + msg1 = str(e) try: import Numeric # noqa: F401 which = "numeric", "defaulted" - except ImportError: - msg2 = str(get_exception()) + except ImportError as e: + msg2 = str(e) try: import numarray # noqa: F401 which = "numarray", "defaulted" - except ImportError: - msg3 = str(get_exception()) + except ImportError as e: + msg3 = str(e) log.info(msg1) log.info(msg2) log.info(msg3) diff --git a/numpy/distutils/tests/test_exec_command.py b/numpy/distutils/tests/test_exec_command.py index 37912f5ba..d6eb7d1c3 100644 --- a/numpy/distutils/tests/test_exec_command.py +++ b/numpy/distutils/tests/test_exec_command.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import os import sys from tempfile import TemporaryFile @@ -10,12 +8,9 @@ from numpy.testing import tempdir, assert_, assert_warns # In python 3 stdout, stderr are text (unicode compliant) devices, so to # emulate them import StringIO from the io module. -if sys.version_info[0] >= 3: - from io import StringIO -else: - from StringIO import StringIO +from io import StringIO -class redirect_stdout(object): +class redirect_stdout: """Context manager to redirect stdout for exec_command test.""" def __init__(self, stdout=None): self._stdout = stdout or sys.stdout @@ -30,7 +25,7 @@ class redirect_stdout(object): # note: closing sys.stdout won't close it. self._stdout.close() -class redirect_stderr(object): +class redirect_stderr: """Context manager to redirect stderr for exec_command test.""" def __init__(self, stderr=None): self._stderr = stderr or sys.stderr @@ -45,7 +40,7 @@ class redirect_stderr(object): # note: closing sys.stderr won't close it. self._stderr.close() -class emulate_nonposix(object): +class emulate_nonposix: """Context manager to emulate os.name != 'posix' """ def __init__(self, osname='non-posix'): self._new_name = osname @@ -98,7 +93,7 @@ def test_exec_command_stderr(): exec_command.exec_command("cd '.'") -class TestExecCommand(object): +class TestExecCommand: def setup(self): self.pyexe = get_pythonexe() @@ -191,9 +186,8 @@ class TestExecCommand(object): with tempdir() as tmpdir: fn = "file" tmpfile = os.path.join(tmpdir, fn) - f = open(tmpfile, 'w') - f.write('Hello') - f.close() + with open(tmpfile, 'w') as f: + f.write('Hello') s, o = exec_command.exec_command( '"%s" -c "f = open(\'%s\', \'r\'); f.close()"' % diff --git a/numpy/distutils/tests/test_fcompiler.py b/numpy/distutils/tests/test_fcompiler.py index 6d245fbd4..dd97f1e72 100644 --- a/numpy/distutils/tests/test_fcompiler.py +++ b/numpy/distutils/tests/test_fcompiler.py @@ -1,8 +1,4 @@ -from __future__ import division, absolute_import, print_function - -import pytest - -from numpy.testing import assert_, suppress_warnings +from numpy.testing import assert_ import numpy.distutils.fcompiler customizable_flags = [ diff --git a/numpy/distutils/tests/test_fcompiler_gnu.py b/numpy/distutils/tests/test_fcompiler_gnu.py index 49208aace..0817ae58c 100644 --- a/numpy/distutils/tests/test_fcompiler_gnu.py +++ b/numpy/distutils/tests/test_fcompiler_gnu.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - from numpy.testing import assert_ import numpy.distutils.fcompiler @@ -30,7 +28,7 @@ gfortran_version_strings = [ ('GNU Fortran (crosstool-NG 8a21ab48) 7.2.0', '7.2.0') ] -class TestG77Versions(object): +class TestG77Versions: def test_g77_version(self): fc = numpy.distutils.fcompiler.new_fcompiler(compiler='gnu') for vs, version in g77_version_strings: @@ -43,7 +41,7 @@ class TestG77Versions(object): v = fc.version_match(vs) assert_(v is None, (vs, v)) -class TestGFortranVersions(object): +class TestGFortranVersions: def test_gfortran_version(self): fc = numpy.distutils.fcompiler.new_fcompiler(compiler='gnu95') for vs, version in gfortran_version_strings: diff --git a/numpy/distutils/tests/test_fcompiler_intel.py b/numpy/distutils/tests/test_fcompiler_intel.py index 5e014bada..45c9cdac1 100644 --- a/numpy/distutils/tests/test_fcompiler_intel.py +++ b/numpy/distutils/tests/test_fcompiler_intel.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import numpy.distutils.fcompiler from numpy.testing import assert_ @@ -16,7 +14,7 @@ intel_64bit_version_strings = [ "running on Intel(R) 64, Version 11.1", '11.1') ] -class TestIntelFCompilerVersions(object): +class TestIntelFCompilerVersions: def test_32bit_version(self): fc = numpy.distutils.fcompiler.new_fcompiler(compiler='intel') for vs, version in intel_32bit_version_strings: @@ -24,7 +22,7 @@ class TestIntelFCompilerVersions(object): assert_(v == version) -class TestIntelEM64TFCompilerVersions(object): +class TestIntelEM64TFCompilerVersions: def test_64bit_version(self): fc = numpy.distutils.fcompiler.new_fcompiler(compiler='intelem') for vs, version in intel_64bit_version_strings: diff --git a/numpy/distutils/tests/test_fcompiler_nagfor.py b/numpy/distutils/tests/test_fcompiler_nagfor.py index 1c936056a..2e04f5266 100644 --- a/numpy/distutils/tests/test_fcompiler_nagfor.py +++ b/numpy/distutils/tests/test_fcompiler_nagfor.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - from numpy.testing import assert_ import numpy.distutils.fcompiler @@ -16,7 +14,7 @@ nag_version_strings = [('nagfor', 'NAG Fortran Compiler Release ' '431,435,437,446,459-460,463,472,494,496,503,508,' '511,517,529,555,557,565)', '5.1')] -class TestNagFCompilerVersions(object): +class TestNagFCompilerVersions: def test_version_match(self): for comp, vs, version in nag_version_strings: fc = numpy.distutils.fcompiler.new_fcompiler(compiler=comp) diff --git a/numpy/distutils/tests/test_mingw32ccompiler.py b/numpy/distutils/tests/test_mingw32ccompiler.py new file mode 100644 index 000000000..ebedacb32 --- /dev/null +++ b/numpy/distutils/tests/test_mingw32ccompiler.py @@ -0,0 +1,42 @@ +import shutil +import subprocess +import sys +import pytest + +from numpy.distutils import mingw32ccompiler + + +@pytest.mark.skipif(sys.platform != 'win32', reason='win32 only test') +def test_build_import(): + '''Test the mingw32ccompiler.build_import_library, which builds a + `python.a` from the MSVC `python.lib` + ''' + + # make sure `nm.exe` exists and supports the current python version. This + # can get mixed up when the PATH has a 64-bit nm but the python is 32-bit + try: + out = subprocess.check_output(['nm.exe', '--help']) + except FileNotFoundError: + pytest.skip("'nm.exe' not on path, is mingw installed?") + supported = out[out.find(b'supported targets:'):] + if sys.maxsize < 2**32: + if b'pe-i386' not in supported: + raise ValueError("'nm.exe' found but it does not support 32-bit " + "dlls when using 32-bit python. Supported " + "formats: '%s'" % supported) + elif b'pe-x86-64' not in supported: + raise ValueError("'nm.exe' found but it does not support 64-bit " + "dlls when using 64-bit python. Supported " + "formats: '%s'" % supported) + # Hide the import library to force a build + has_import_lib, fullpath = mingw32ccompiler._check_for_import_lib() + if has_import_lib: + shutil.move(fullpath, fullpath + '.bak') + + try: + # Whew, now we can actually test the function + mingw32ccompiler.build_import_library() + + finally: + if has_import_lib: + shutil.move(fullpath + '.bak', fullpath) diff --git a/numpy/distutils/tests/test_misc_util.py b/numpy/distutils/tests/test_misc_util.py index 3e239cf48..605c80483 100644 --- a/numpy/distutils/tests/test_misc_util.py +++ b/numpy/distutils/tests/test_misc_util.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - from os.path import join, sep, dirname from numpy.distutils.misc_util import ( @@ -11,7 +9,7 @@ from numpy.testing import ( ajoin = lambda *paths: join(*((sep,)+paths)) -class TestAppendpath(object): +class TestAppendpath: def test_1(self): assert_equal(appendpath('prefix', 'name'), join('prefix', 'name')) @@ -35,7 +33,7 @@ class TestAppendpath(object): assert_equal(appendpath('/prefix/sub/sub2', '/prefix/sub/sup/name'), ajoin('prefix', 'sub', 'sub2', 'sup', 'name')) -class TestMinrelpath(object): +class TestMinrelpath: def test_1(self): n = lambda path: path.replace('/', sep) @@ -49,7 +47,7 @@ class TestMinrelpath(object): assert_equal(minrelpath(n('.././..')), n('../..')) assert_equal(minrelpath(n('aa/bb/.././../dd')), n('dd')) -class TestGpaths(object): +class TestGpaths: def test_gpaths(self): local_path = minrelpath(join(dirname(__file__), '..')) @@ -58,7 +56,7 @@ class TestGpaths(object): f = gpaths('system_info.py', local_path) assert_(join(local_path, 'system_info.py') == f[0], repr(f)) -class TestSharedExtension(object): +class TestSharedExtension: def test_get_shared_lib_extension(self): import sys diff --git a/numpy/distutils/tests/test_npy_pkg_config.py b/numpy/distutils/tests/test_npy_pkg_config.py index 537e16e90..b287ebe2e 100644 --- a/numpy/distutils/tests/test_npy_pkg_config.py +++ b/numpy/distutils/tests/test_npy_pkg_config.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import os from numpy.distutils.npy_pkg_config import read_config, parse_flags @@ -36,7 +34,7 @@ libs = -L${libdir} simple_variable_d = {'cflags': '-I/foo/bar/include', 'libflags': '-L/foo/bar/lib', 'version': '0.1', 'name': 'foo'} -class TestLibraryInfo(object): +class TestLibraryInfo: def test_simple(self): with temppath('foo.ini') as path: with open(path, 'w') as f: @@ -63,7 +61,7 @@ class TestLibraryInfo(object): out.vars['prefix'] = '/Users/david' assert_(out.cflags() == '-I/Users/david/include') -class TestParseFlags(object): +class TestParseFlags: def test_simple_cflags(self): d = parse_flags("-I/usr/include") assert_(d['include_dirs'] == ['/usr/include']) diff --git a/numpy/distutils/tests/test_shell_utils.py b/numpy/distutils/tests/test_shell_utils.py index a0344244f..32bd283e5 100644 --- a/numpy/distutils/tests/test_shell_utils.py +++ b/numpy/distutils/tests/test_shell_utils.py @@ -1,8 +1,5 @@ -from __future__ import division, absolute_import, print_function - import pytest import subprocess -import os import json import sys diff --git a/numpy/distutils/tests/test_system_info.py b/numpy/distutils/tests/test_system_info.py index 3c7638960..0768ffdde 100644 --- a/numpy/distutils/tests/test_system_info.py +++ b/numpy/distutils/tests/test_system_info.py @@ -1,5 +1,3 @@ -from __future__ import division, print_function - import os import shutil import pytest @@ -9,7 +7,7 @@ from distutils.errors import DistutilsError from numpy.testing import assert_, assert_equal, assert_raises from numpy.distutils import ccompiler, customized_ccompiler -from numpy.distutils.system_info import system_info, ConfigParser +from numpy.distutils.system_info import system_info, ConfigParser, mkl_info from numpy.distutils.system_info import AliasedOptionError from numpy.distutils.system_info import default_lib_dirs, default_include_dirs from numpy.distutils import _shell_utils @@ -130,7 +128,7 @@ class DuplicateOptionInfo(_system_info): section = 'duplicate_options' -class TestSystemInfoReading(object): +class TestSystemInfoReading: def setup(self): """ Create the libraries """ @@ -255,3 +253,35 @@ class TestSystemInfoReading(object): assert_(os.path.isfile(self._src2.replace('.c', '.o'))) finally: os.chdir(previousDir) + + def test_overrides(self): + previousDir = os.getcwd() + cfg = os.path.join(self._dir1, 'site.cfg') + shutil.copy(self._sitecfg, cfg) + try: + os.chdir(self._dir1) + # Check that the '[ALL]' section does not override + # missing values from other sections + info = mkl_info() + lib_dirs = info.cp['ALL']['library_dirs'].split(os.pathsep) + assert info.get_lib_dirs() != lib_dirs + + # But if we copy the values to a '[mkl]' section the value + # is correct + with open(cfg, 'r') as fid: + mkl = fid.read().replace('ALL', 'mkl') + with open(cfg, 'w') as fid: + fid.write(mkl) + info = mkl_info() + assert info.get_lib_dirs() == lib_dirs + + # Also, the values will be taken from a section named '[DEFAULT]' + with open(cfg, 'r') as fid: + dflt = fid.read().replace('mkl', 'DEFAULT') + with open(cfg, 'w') as fid: + fid.write(dflt) + info = mkl_info() + assert info.get_lib_dirs() == lib_dirs + finally: + os.chdir(previousDir) + diff --git a/numpy/distutils/unixccompiler.py b/numpy/distutils/unixccompiler.py index 11b2cce52..5f36c439f 100644 --- a/numpy/distutils/unixccompiler.py +++ b/numpy/distutils/unixccompiler.py @@ -2,20 +2,13 @@ unixccompiler - can handle very long argument lists for ar. """ -from __future__ import division, absolute_import, print_function - import os -from distutils.errors import DistutilsExecError, CompileError -from distutils.unixccompiler import * +from distutils.errors import CompileError, DistutilsExecError, LibError +from distutils.unixccompiler import UnixCCompiler from numpy.distutils.ccompiler import replace_method -from numpy.distutils.compat import get_exception from numpy.distutils.misc_util import _commandline_dep_string - -if sys.version_info[0] < 3: - from . import log -else: - from numpy.distutils import log +from numpy.distutils import log # Note that UnixCCompiler._compile appeared in Python 2.3 def UnixCCompiler__compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): @@ -56,8 +49,8 @@ def UnixCCompiler__compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts try: self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + deps + extra_postargs, display = display) - except DistutilsExecError: - msg = str(get_exception()) + except DistutilsExecError as e: + msg = str(e) raise CompileError(msg) # add commandline flags to dependency file @@ -128,8 +121,8 @@ def UnixCCompiler_create_static_lib(self, objects, output_libname, try: self.spawn(self.ranlib + [output_filename], display = display) - except DistutilsExecError: - msg = str(get_exception()) + except DistutilsExecError as e: + msg = str(e) raise LibError(msg) else: log.debug("skipping %s (up-to-date)", output_filename) |