From 701dbe1c08e71cf79a0b234c42ffccf27f884634 Mon Sep 17 00:00:00 2001 From: Charles Harris Date: Fri, 27 Feb 2015 11:30:56 -0700 Subject: [PATCH] STY: Some style cleanups in distutils. Break long lines. Spaces around operators. Remove dead code. --- numpy/distutils/fcompiler/gnu.py | 66 +++++--------- numpy/distutils/mingw32ccompiler.py | 135 ++++++++++++++-------------- 2 files changed, 92 insertions(+), 109 deletions(-) diff --git a/numpy/distutils/fcompiler/gnu.py b/numpy/distutils/fcompiler/gnu.py index 16ad73e5ce5c..93da496f22e9 100644 --- a/numpy/distutils/fcompiler/gnu.py +++ b/numpy/distutils/fcompiler/gnu.py @@ -8,7 +8,6 @@ import tempfile from subprocess import Popen, PIPE, STDOUT -from numpy.distutils.cpuinfo import cpu from numpy.distutils.fcompiler import FCompiler from numpy.distutils.exec_command import exec_command from numpy.distutils.misc_util import msvc_runtime_library @@ -61,19 +60,11 @@ def version_match(self, version_string): return None return v[1] - # 'g77 --version' results - # SunOS: GNU Fortran (GCC 3.2) 3.2 20020814 (release) - # Debian: GNU Fortran (GCC) 3.3.3 20040110 (prerelease) (Debian) - # GNU Fortran (GCC) 3.3.3 (Debian 20040401) - # GNU Fortran 0.5.25 20010319 (prerelease) - # Redhat: GNU Fortran (GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) 3.2.2 20030222 (Red Hat Linux 3.2.2-5) - # GNU Fortran (GCC) 3.4.2 (mingw-special) - possible_executables = ['g77', 'f77'] executables = { 'version_cmd' : [None, "-dumpversion"], 'compiler_f77' : [None, "-g", "-Wall", "-fno-second-underscore"], - 'compiler_f90' : None, # Use --fcompiler=gnu95 for f90 codes + 'compiler_f90' : None, # Use --fcompiler=gnu95 for f90 codes 'compiler_fix' : None, 'linker_so' : [None, "-g", "-Wall"], 'archiver' : ["ar", "-cr"], @@ -94,19 +85,11 @@ def version_match(self, version_string): executables[key].append('-mno-cygwin') g2c = 'g2c' - suggested_f90_compiler = 'gnu95' - #def get_linker_so(self): - # # win32 linking should be handled by standard linker - # # Darwin g77 cannot be used as a linker. - # #if re.match(r'(darwin)', sys.platform): - # # return - # return FCompiler.get_linker_so(self) - def get_flags_linker_so(self): opt = self.linker_so[1:] - if sys.platform=='darwin': + if sys.platform == 'darwin': target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', None) # If MACOSX_DEPLOYMENT_TARGET is set, we simply trust the value # and leave it alone. But, distutils will complain if the @@ -159,10 +142,12 @@ def get_library_dirs(self): # if windows and not cygwin, libg2c lies in a different folder if sys.platform == 'win32' and not d.startswith('/usr/lib'): d = os.path.normpath(d) - if not os.path.exists(os.path.join(d, "lib%s.a" % self.g2c)): - d2 = os.path.abspath(os.path.join(d, - '../../../../lib')) - if os.path.exists(os.path.join(d2, "lib%s.a" % self.g2c)): + path = os.path.join(d, "lib%s.a" % self.g2c) + if not os.path.exists(path): + root = os.path.join(d, *((os.pardir,)*4)) + d2 = os.path.abspath(os.path.join(root, 'lib')) + path = os.path.join(d2, "lib%s.a" % self.g2c) + if os.path.exists(path): opt.append(d2) opt.append(d) return opt @@ -182,7 +167,7 @@ def get_libraries(self): opt.append(g2c) c_compiler = self.c_compiler if sys.platform == 'win32' and c_compiler and \ - c_compiler.compiler_type=='msvc': + c_compiler.compiler_type == 'msvc': # the following code is not needed (read: breaks) when using MinGW # in case want to link F77 compiled code with MSVC opt.append('gcc') @@ -198,21 +183,22 @@ def get_flags_debug(self): def get_flags_opt(self): v = self.get_version() - if v and v<='3.3.3': + if v and v <= '3.3.3': # With this compiler version building Fortran BLAS/LAPACK # with -O3 caused failures in lib.lapack heevr,syevr tests. opt = ['-O2'] - elif v and v>='4.6.0': + elif v and v >= '4.6.0': if is_win32(): # use -mincoming-stack-boundary=2 # due to the change to 16 byte stack alignment since GCC 4.6 # but 32 bit Windows ABI defines 4 bytes stack alignment - opt = ['-O2 -march=core2 -mtune=generic -mfpmath=sse -msse2 -mincoming-stack-boundary=2'] + opt = ['-O2 -march=core2 -mtune=generic -mfpmath=sse -msse2' + '-mincoming-stack-boundary=2'] else: opt = ['-O2 -march=x86-64 -DMS_WIN64 -mtune=generic -msse2'] else: opt = ['-O2'] - # opt.append() + return opt def _c_arch_flags(self): @@ -244,25 +230,18 @@ def version_match(self, version_string): if not v or v[0] != 'gfortran': return None v = v[1] - if v>='4.': + if v >= '4.': # gcc-4 series releases do not support -mno-cygwin option pass else: - # use -mno-cygwin flag for gfortran when Python is not Cygwin-Python + # use -mno-cygwin flag for gfortran when Python is not + # Cygwin-Python if sys.platform == 'win32': for key in ['version_cmd', 'compiler_f77', 'compiler_f90', 'compiler_fix', 'linker_so', 'linker_exe']: self.executables[key].append('-mno-cygwin') return v - # 'gfortran --version' results: - # XXX is the below right? - # Debian: GNU Fortran 95 (GCC 4.0.3 20051023 (prerelease) (Debian 4.0.2-3)) - # GNU Fortran 95 (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21) - # OS X: GNU Fortran 95 (GCC) 4.1.0 - # GNU Fortran 95 (GCC) 4.2.0 20060218 (experimental) - # GNU Fortran (GCC) 4.3.0 20070316 (experimental) - possible_executables = ['gfortran', 'f95'] executables = { 'version_cmd' : ["", "-dumpversion"], @@ -321,10 +300,10 @@ def get_library_dirs(self): target = self.get_target() if target: d = os.path.normpath(self.get_libgcc_dir()) - root = os.path.join(d, os.pardir, os.pardir, os.pardir, os.pardir) - mingwdir = os.path.normpath(os.path.join(root, target, "lib")) - full = os.path.join(mingwdir, "libmingwex.a") - if os.path.exists(full): + root = os.path.join(d, *((os.pardir,)*4)) + path = os.path.join(root, target, "lib") + mingwdir = os.path.normpath(path) + if os.path.exists(os.path.join(mingwdir, "libmingwex.a")): opt.append(mingwdir) return opt @@ -362,8 +341,7 @@ def get_flags_opt(self): return GnuFCompiler.get_flags_opt(self) def _can_target(cmd, arch): - """Return true is the command supports the -arch flag for the given - architecture.""" + """Return true if the architecture supports the -arch flag""" newcmd = cmd[:] fid, filename = tempfile.mkstemp(suffix=".f") try: diff --git a/numpy/distutils/mingw32ccompiler.py b/numpy/distutils/mingw32ccompiler.py index bc95739020eb..f72c3bbbbfb5 100644 --- a/numpy/distutils/mingw32ccompiler.py +++ b/numpy/distutils/mingw32ccompiler.py @@ -30,11 +30,12 @@ import distutils.cygwinccompiler from distutils.version import StrictVersion from numpy.distutils.ccompiler import gen_preprocess_options, gen_lib_options -from distutils.errors import DistutilsExecError, CompileError, UnknownFileError - from distutils.unixccompiler import UnixCCompiler from distutils.msvccompiler import get_build_version as get_build_msvc_version -from numpy.distutils.misc_util import msvc_runtime_library, get_build_architecture +from distutils.errors import (DistutilsExecError, CompileError, + UnknownFileError) +from numpy.distutils.misc_util import (msvc_runtime_library, + get_build_architecture) # Useful to generate table of symbols from a dll _START = re.compile(r'\[Ordinal/Name Pointer\] Table') @@ -53,8 +54,8 @@ def __init__ (self, dry_run=0, force=0): - distutils.cygwinccompiler.CygwinCCompiler.__init__ (self, - verbose, dry_run, force) + distutils.cygwinccompiler.CygwinCCompiler.__init__ (self, verbose, + dry_run, force) # we need to support 3.2 which doesn't match the standard # get_versions methods regex @@ -80,7 +81,8 @@ def __init__ (self, # g++.exe: g++: No such file or directory # error (mingw 1.0 in Enthon24 tree, gcc-3.4.5). # If the --driver-name part is required for some environment - # then make the inclusion of this part specific to that environment. + # then make the inclusion of this part specific to that + # environment. self.linker = 'dllwrap' # --driver-name g++' elif self.linker_dll == 'gcc': self.linker = 'g++' @@ -98,10 +100,12 @@ def __init__ (self, if 'MinGW-W64' not in str(out_string): # **changes: eric jones 4/11/01 - # 1. Check for import library on Windows. Build if it doesn't exist. + # 1. Check for import library on Windows. Build if it doesn't + # exist. build_import_library() - # Check for custom msvc runtime library on Windows. Build if it doesn't exist. + # Check for custom msvc runtime library on Windows. Build if it + # doesn't exist. msvcr_success = build_msvcr_library() msvcr_dbg_success = build_msvcr_library(debug=True) if msvcr_success or msvcr_dbg_success: @@ -112,59 +116,64 @@ def __init__ (self, msvcr_version = '0x%03i0' % int(msvc_runtime_library().lstrip('msvcr')) self.define_macro('__MSVCRT_VERSION__', msvcr_version) - # **changes: eric jones 4/11/01 - # 2. increased optimization and turned off all warnings - # 3. also added --driver-name g++ - #self.set_executables(compiler='gcc -mno-cygwin -O2 -w', - # compiler_so='gcc -mno-cygwin -mdll -O2 -w', - # linker_exe='gcc -mno-cygwin', - # linker_so='%s --driver-name g++ -mno-cygwin -mdll -static %s' - # % (self.linker, entry_point)) - - # MS_WIN64 should be defined when building for amd64 on windows, but - # python headers define it only for MS compilers, which has all kind of - # bad consequences, like using Py_ModuleInit4 instead of + # MS_WIN64 should be defined when building for amd64 on windows, + # but python headers define it only for MS compilers, which has all + # kind of bad consequences, like using Py_ModuleInit4 instead of # Py_ModuleInit4_64, etc... So we add it here if get_build_architecture() == 'AMD64': if self.gcc_version < "4.0": self.set_executables( compiler='gcc -g -DDEBUG -DMS_WIN64 -mno-cygwin -O0 -Wall', - compiler_so='gcc -g -DDEBUG -DMS_WIN64 -mno-cygwin -O0 -Wall -Wstrict-prototypes', + compiler_so='gcc -g -DDEBUG -DMS_WIN64 -mno-cygwin -O0' + ' -Wall -Wstrict-prototypes', linker_exe='gcc -g -mno-cygwin', linker_so='gcc -g -mno-cygwin -shared') else: # gcc-4 series releases do not support -mno-cygwin option self.set_executables( - compiler='gcc -march=x86-64 -mtune=generic -DMS_WIN64 -O2 -msse2 -Wall', - compiler_so='gcc -march=x86-64 -mtune=generic -DMS_WIN64 -O2 -msse2 -Wall -Wstrict-prototypes', + compiler='gcc -march=x86-64 -mtune=generic -DMS_WIN64' + ' -O2 -msse2 -Wall', + compiler_so='gcc -march=x86-64 -mtune=generic -DMS_WIN64' + ' -O2 -msse2 -Wall -Wstrict-prototypes', linker_exe='gcc', linker_so='gcc -shared -Wl,-gc-sections -Wl,-s') else: if self.gcc_version <= "3.0.0": - self.set_executables(compiler='gcc -mno-cygwin -O2 -w', - compiler_so='gcc -mno-cygwin -mdll -O2 -w -Wstrict-prototypes', - linker_exe='g++ -mno-cygwin', - linker_so='%s -mno-cygwin -mdll -static %s' - % (self.linker, entry_point)) + self.set_executables( + compiler='gcc -mno-cygwin -O2 -w', + compiler_so='gcc -mno-cygwin -mdll -O2 -w' + ' -Wstrict-prototypes', + linker_exe='g++ -mno-cygwin', + linker_so='%s -mno-cygwin -mdll -static %s' % + (self.linker, entry_point)) elif self.gcc_version < "4.0": - self.set_executables(compiler='gcc -mno-cygwin -O2 -Wall', - compiler_so='gcc -mno-cygwin -O2 -Wall -Wstrict-prototypes', - linker_exe='g++ -mno-cygwin', - linker_so='g++ -mno-cygwin -shared') + self.set_executables( + compiler='gcc -mno-cygwin -O2 -Wall', + compiler_so='gcc -mno-cygwin -O2 -Wall' + ' -Wstrict-prototypes', + linker_exe='g++ -mno-cygwin', + linker_so='g++ -mno-cygwin -shared') else: - # gcc-4 series releases do not support -mno-cygwin option - # i686 build needs '-mincoming-stack-boundary=2' due to ABI incompatibility to Win32 ABI - self.set_executables(compiler='gcc -O2 -march=core2 -mtune=generic -mfpmath=sse -msse2 -mincoming-stack-boundary=2 -Wall', - compiler_so='gcc -O2 -march=core2 -mtune=generic -mfpmath=sse -msse2 -mincoming-stack-boundary=2 -Wall -Wstrict-prototypes', - linker_exe='g++ ', - linker_so='g++ -shared -Wl,-gc-sections -Wl,-s') - # added for python2.3 support - # we can't pass it through set_executables because pre 2.2 would fail + # gcc-4 series releases do not support -mno-cygwin option i686 + # build needs '-mincoming-stack-boundary=2' due to ABI + # incompatibility to Win32 ABI + self.set_executables( + compiler='gcc -O2 -march=core2 -mtune=generic' + ' -mfpmath=sse -msse2' + ' -mincoming-stack-boundary=2 -Wall', + compiler_so='gcc -O2 -march=core2 -mtune=generic' + ' -mfpmath=sse -msse2' + ' -mincoming-stack-boundary=2 -Wall' + ' -Wstrict-prototypes', + linker_exe='g++ ', + linker_so='g++ -shared -Wl,-gc-sections -Wl,-s') + # added for python2.3 support we can't pass it through set_executables + # because pre 2.2 would fail self.compiler_cxx = ['g++'] - # Maybe we should also append -mthreads, but then the finished - # dlls need another dll (mingwm10.dll see Mingw32 docs) - # (-mthreads: Support thread-safe exception handling on `Mingw32') + # Maybe we should also append -mthreads, but then the finished dlls + # need another dll (mingwm10.dll see Mingw32 docs) (-mthreads: Support + # thread-safe exception handling on `Mingw32') # no additional libraries needed #self.dll_libraries=[] @@ -343,7 +352,8 @@ def build_msvcr_library(debug=False): # Skip using a custom library for versions < MSVC 8.0 if int(msvcr_name.lstrip('msvcr')) < 80: - log.debug('Skip building msvcr library: custom functionality not present') + log.debug('Skip building msvcr library:' + ' custom functionality not present') return False if debug: @@ -353,14 +363,16 @@ def build_msvcr_library(debug=False): out_name = "lib%s.a" % msvcr_name out_file = os.path.join(sys.prefix, 'libs', out_name) if os.path.isfile(out_file): - log.debug('Skip building msvcr library: "%s" exists' % (out_file)) + log.debug('Skip building msvcr library: "%s" exists' % + (out_file,)) return True # Find the msvcr dll msvcr_dll_name = msvcr_name + '.dll' dll_file = find_dll(msvcr_dll_name) if not dll_file: - log.warn('Cannot build msvcr library: "%s" not found' % msvcr_dll_name) + log.warn('Cannot build msvcr library: "%s" not found' % + msvcr_dll_name) return False def_name = "lib%s.def" % msvcr_name @@ -399,14 +411,15 @@ def _build_import_library_amd64(): out_name = "libpython%d%d.a" % tuple(sys.version_info[:2]) out_file = os.path.join(sys.prefix, 'libs', out_name) if os.path.isfile(out_file): - log.debug('Skip building import library: "%s" exists' % (out_file)) + log.debug('Skip building import library: "%s" exists' % + (out_file)) return def_name = "python%d%d.def" % tuple(sys.version_info[:2]) def_file = os.path.join(sys.prefix, 'libs', def_name) - log.info('Building import library (arch=AMD64): "%s" (from %s)' \ - % (out_file, dll_file)) + log.info('Building import library (arch=AMD64): "%s" (from %s)' % + (out_file, dll_file)) generate_def(dll_file, def_file) @@ -444,9 +457,6 @@ def _build_import_library_x86(): # for now, fail silently if status: log.warn('Failed to build import library for gcc. Linking will fail.') - #if not success: - # msg = "Couldn't find import library, and failed to build it." - # raise DistutilsPlatformError(msg) return #===================================== @@ -474,16 +484,17 @@ def _build_import_library_x86(): # one, and we can't retrieve it from python _MSVCRVER_TO_FULLVER['80'] = "8.0.50727.42" _MSVCRVER_TO_FULLVER['90'] = "9.0.21022.8" - # Value from msvcrt.CRT_ASSEMBLY_VERSION under Python 3.3.0 on Windows XP: + # Value from msvcrt.CRT_ASSEMBLY_VERSION under Python 3.3.0 + # on Windows XP: _MSVCRVER_TO_FULLVER['100'] = "10.0.30319.460" if hasattr(msvcrt, "CRT_ASSEMBLY_VERSION"): major, minor, rest = msvcrt.CRT_ASSEMBLY_VERSION.split(".", 2) _MSVCRVER_TO_FULLVER[major + minor] = msvcrt.CRT_ASSEMBLY_VERSION del major, minor, rest except ImportError: - # If we are here, means python was not built with MSVC. Not sure what to do - # in that case: manifest building will fail, but it should not be used in - # that case anyway + # If we are here, means python was not built with MSVC. Not sure what + # to do in that case: manifest building will fail, but it should not be + # used in that case anyway log.warn('Cannot import msvcrt: using manifest will not be possible') def msvc_manifest_xml(maj, min): @@ -492,8 +503,8 @@ def msvc_manifest_xml(maj, min): try: fullver = _MSVCRVER_TO_FULLVER[str(maj * 10 + min)] except KeyError: - raise ValueError("Version %d,%d of MSVCRT not supported yet" \ - % (maj, min)) + raise ValueError("Version %d,%d of MSVCRT not supported yet" % + (maj, min)) # Don't be fooled, it looks like an XML, but it is not. In particular, it # should not have any space before starting, and its size should be # divisible by 4, most likely for alignement constraints when the xml is @@ -569,7 +580,7 @@ def manifest_name(config): return root + exext + ".manifest" def rc_name(config): - # Get configest name (including suffix) + # Get configtest name (including suffix) root = configtest_name(config) return root + ".rc" @@ -586,9 +597,3 @@ def generate_manifest(config): config.temp_files.append(manifest_name(config)) man.write(manxml) man.close() - # # Write the rc file - # manrc = manifest_rc(manifest_name(self), "exe") - # rc = open(rc_name(self), "w") - # self.temp_files.append(manrc) - # rc.write(manrc) - # rc.close()