diff options
| author | cookedm <cookedm@localhost> | 2006-01-31 22:49:15 +0000 |
|---|---|---|
| committer | cookedm <cookedm@localhost> | 2006-01-31 22:49:15 +0000 |
| commit | f59515e452a522fb3b4989aada18eb84234bacc0 (patch) | |
| tree | 6b1da80bee4bf1840657c2606ea9cc1a75b669e1 | |
| parent | c1b9a6e8b560ac77dede465a4c0f527429f24d3d (diff) | |
| download | numpy-f59515e452a522fb3b4989aada18eb84234bacc0.tar.gz | |
Misc cleanups + replace `a` with %r or repr(a)
Also replace some type checks with misc_util.is_sequence or misc_util.is_string
or appropiate isinstance().
| -rw-r--r-- | numpy/distutils/ccompiler.py | 7 | ||||
| -rw-r--r-- | numpy/distutils/command/build_src.py | 42 | ||||
| -rw-r--r-- | numpy/distutils/core.py | 41 | ||||
| -rw-r--r-- | numpy/distutils/exec_command.py | 19 | ||||
| -rw-r--r-- | numpy/distutils/misc_util.py | 35 | ||||
| -rw-r--r-- | numpy/distutils/system_info.py | 44 |
6 files changed, 100 insertions, 88 deletions
diff --git a/numpy/distutils/ccompiler.py b/numpy/distutils/ccompiler.py index 0a4e206fd..f92d03c22 100644 --- a/numpy/distutils/ccompiler.py +++ b/numpy/distutils/ccompiler.py @@ -150,9 +150,9 @@ def _compiler_to_string(compiler): if hasattr(compiler,key): v = getattr(compiler, key) mx = max(mx,len(key)) - props.append((key,`v`)) + props.append((key,repr(v))) lines = [] - format = '%-' +`mx+1`+ 's = %s' + format = '%-' + repr(mx+1) + 's = %s' for prop in props: lines.append(format % prop) return '\n'.join(lines) @@ -215,7 +215,8 @@ def CCompiler_get_version(self, force=0, ok_status=[0]): m = re.match(self.version_pattern,output) if m: version = m.group('version') - assert version,`version` + if not m: + raise ValueError("compiler version not matched (%r)" % (version,)) version = LooseVersion(version) self.version = version return version diff --git a/numpy/distutils/command/build_src.py b/numpy/distutils/command/build_src.py index 1450b4c3f..00adb91b7 100644 --- a/numpy/distutils/command/build_src.py +++ b/numpy/distutils/command/build_src.py @@ -135,7 +135,7 @@ class build_src(build_ext.build_ext): elif isinstance(s,str): files.append(s) else: - raise TypeError,`s` + raise TypeError(repr(s)) filenames = get_data_files((d,files)) new_data_files.append((d, filenames)) else: @@ -351,9 +351,10 @@ class build_src(build_ext.build_ext): target_dir = appendpath(self.build_src, os.path.dirname(base)) if os.path.isfile(source): name = get_f2py_modulename(source) - assert name==ext_name,'mismatch of extension names: '\ - +source+' provides'\ - ' '+`name`+' but expected '+`ext_name` + if name != ext_name: + raise ValueError('mismatch of extension names: %s ' + 'provides %r but expected %r' % ( + source, name, ext_name)) target_file = os.path.join(target_dir,name+'module.c') else: log.debug(' source %s does not exist: skipping f2py\'ing.' \ @@ -368,7 +369,8 @@ class build_src(build_ext.build_ext): % (target_file, name)) target_dir = os.path.dirname(base) target_file = os.path.join(target_dir,name+'module.c') - assert os.path.isfile(target_file),`target_file`+' missing' + if not os.path.isfile(target_file): + raise ValueError("%r missing" % (target_file,)) log.debug(' Yes! Using %s as up-to-date target.' \ % (target_file)) target_dirs.append(target_dir) @@ -395,9 +397,10 @@ class build_src(build_ext.build_ext): log.info("f2py options: %s" % (f2py_options)) if f2py_sources: - assert len(f2py_sources)==1,\ - 'only one .pyf file is allowed per extension module but got'\ - ' more:'+`f2py_sources` + if len(f2py_sources) != 1: + raise ValueError( + 'only one .pyf file is allowed per extension module but got'\ + ' more: %r' % (f2py_sources,)) source = f2py_sources[0] target_file = f2py_targets[source] target_dir = os.path.dirname(target_file) or '.' @@ -430,7 +433,8 @@ class build_src(build_ext.build_ext): log.debug(" skipping f2py fortran files for '%s' (up-to-date)"\ % (target_file)) - assert os.path.isfile(target_file),`target_file`+' missing' + if not os.path.isfile(target_file): + raise ValueError("%r missing" % (target_file,)) target_c = os.path.join(self.build_src,'fortranobject.c') target_h = os.path.join(self.build_src,'fortranobject.h') @@ -451,9 +455,11 @@ class build_src(build_ext.build_ext): self.copy_file(source_c,target_c) self.copy_file(source_h,target_h) else: - assert os.path.isfile(target_c),`target_c` + ' missing' - assert os.path.isfile(target_h),`target_h` + ' missing' - + if not os.path.isfile(target_c): + raise ValueError("%r missing" % (target_c,)) + if not os.path.isfile(target_h): + raise ValueError("%r missing" % (target_h,)) + for name_ext in ['-f2pywrappers.f','-f2pywrappers2.f90']: filename = os.path.join(target_dir,ext_name + name_ext) if os.path.isfile(filename): @@ -488,16 +494,17 @@ class build_src(build_ext.build_ext): py_target_dir = target_dir if os.path.isfile(source): name = get_swig_modulename(source) - assert name==ext_name[1:],'mismatch of extension names: '\ - +source+' provides'\ - ' '+`name`+' but expected '+`ext_name[1:]` + if name != ext_name[1:]: + raise ValueError( + 'mismatch of extension names: %s provides %r' + ' but expected %r' % (source, name, ext_name[1:])) if typ is None: typ = get_swig_target(source) is_cpp = typ=='c++' if is_cpp: target_ext = '.cpp' else: - assert typ == get_swig_target(source),`typ` + assert typ == get_swig_target(source), repr(typ) target_file = os.path.join(target_dir,'%s_wrap%s' \ % (name, target_ext)) else: @@ -513,7 +520,8 @@ class build_src(build_ext.build_ext): % (target_file, name)) target_dir = os.path.dirname(base) target_file = _find_swig_target(target_dir, name) - assert os.path.isfile(target_file),`target_file`+' missing' + if not os.path.isfile(target_file): + raise ValueError("%r missing" % (target_file,)) log.debug(' Yes! Using %s as up-to-date target.' \ % (target_file)) target_dirs.append(target_dir) diff --git a/numpy/distutils/core.py b/numpy/distutils/core.py index d246448ed..3a1722179 100644 --- a/numpy/distutils/core.py +++ b/numpy/distutils/core.py @@ -1,5 +1,4 @@ -import types from distutils.core import * try: from setuptools import setup as old_setup @@ -24,7 +23,7 @@ from numpy.distutils.command import install_data from numpy.distutils.command import install_headers from numpy.distutils.command import install from numpy.distutils.command import bdist_rpm -from numpy.distutils.misc_util import get_data_files +from numpy.distutils.misc_util import get_data_files, is_sequence, is_string numpy_cmdclass = {'build': build.build, 'build_src': build_src.build_src, @@ -61,13 +60,15 @@ def setup(**attr): for ext in new_attr.get('ext_modules',[]): new_libraries = [] for item in ext.libraries: - if type(item) is type(()): - lib_name,build_info = item + if is_sequence(item): + lib_name, build_info = item _check_append_ext_library(libraries, item) new_libraries.append(lib_name) - else: - assert type(item) is type(''),`item` + elif is_string(item): new_libraries.append(item) + else: + raise TypeError("invalid description of extension module " + "library %r" % (item,)) ext.libraries = new_libraries if libraries: if not new_attr.has_key('libraries'): @@ -85,24 +86,24 @@ def setup(**attr): def _check_append_library(libraries, item): import warnings for libitem in libraries: - if type(libitem) is type(()): - if type(item) is type(()): + if is_sequence(libitem): + if is_sequence(item): if item[0]==libitem[0]: if item[1] is libitem[1]: return - warnings.warn("[0] libraries list contains '%s' with"\ - " different build_info" % (item[0])) + warnings.warn("[0] libraries list contains %r with" + " different build_info" % (item[0],)) break else: if item==libitem[0]: - warnings.warn("[1] libraries list contains '%s' with"\ - " no build_info" % (item[0])) + warnings.warn("[1] libraries list contains %r with" + " no build_info" % (item[0],)) break else: - if type(item) is type(()): + if is_sequence(item): if item[0]==libitem: - warnings.warn("[2] libraries list contains '%s' with"\ - " no build_info" % (item[0])) + warnings.warn("[2] libraries list contains %r with" + " no build_info" % (item[0],)) break else: if item==libitem: @@ -113,16 +114,16 @@ def _check_append_library(libraries, item): def _check_append_ext_library(libraries, (lib_name,build_info)): import warnings for item in libraries: - if type(item) is type(()): + if is_sequence(item): if item[0]==lib_name: if item[1] is build_info: return - warnings.warn("[3] libraries list contains '%s' with"\ - " different build_info" % (lib_name)) + warnings.warn("[3] libraries list contains %r with" + " different build_info" % (lib_name,)) break elif item==lib_name: - warnings.warn("[4] libraries list contains '%s' with"\ - " no build_info" % (lib_name)) + warnings.warn("[4] libraries list contains %r with" + " no build_info" % (lib_name,)) break libraries.append((lib_name,build_info)) return diff --git a/numpy/distutils/exec_command.py b/numpy/distutils/exec_command.py index 6c5554bba..a44fd9abf 100644 --- a/numpy/distutils/exec_command.py +++ b/numpy/distutils/exec_command.py @@ -65,7 +65,7 @@ def get_pythonexe(): fdir,fn = os.path.split(pythonexe) fn = fn.upper().replace('PYTHONW','PYTHON') pythonexe = os.path.join(fdir,fn) - assert os.path.isfile(pythonexe),`pythonexe`+' is not a file' + assert os.path.isfile(pythonexe), '%r is not a file' % (pythonexe,) return pythonexe ############################################################ @@ -104,19 +104,19 @@ def splitcmdline(line): def test_splitcmdline(): l = splitcmdline('a b cc') - assert l==['a','b','cc'],`l` + assert l==['a','b','cc'], repr(l) l = splitcmdline('a') - assert l==['a'],`l` + assert l==['a'], repr(l) l = splitcmdline('a " b cc"') - assert l==['a','" b cc"'],`l` + assert l==['a','" b cc"'], repr(l) l = splitcmdline('"a bcc" -h') - assert l==['"a bcc"','-h'],`l` + assert l==['"a bcc"','-h'], repr(l) l = splitcmdline(r'"\"a \" bcc" -h') - assert l==[r'"\"a \" bcc"','-h'],`l` + assert l==[r'"\"a \" bcc"','-h'], repr(l) l = splitcmdline(" 'a bcc' -h") - assert l==["'a bcc'",'-h'],`l` + assert l==["'a bcc'",'-h'], repr(l) l = splitcmdline(r"'\'a \' bcc' -h") - assert l==[r"'\'a \' bcc'",'-h'],`l` + assert l==[r"'\'a \' bcc'",'-h'], repr(l) ############################################################ @@ -340,7 +340,8 @@ def _exec_command_python(command, cmd = '%s %s' % (python_exe, cmdfile) status = os.system(cmd) - assert not status,`cmd`+' failed' + if status: + raise RuntimeError("%r failed" % (cmd,)) os.remove(cmdfile) f = open(stsfile,'r') diff --git a/numpy/distutils/misc_util.py b/numpy/distutils/misc_util.py index 6aa937a4f..64b2ca94c 100644 --- a/numpy/distutils/misc_util.py +++ b/numpy/distutils/misc_util.py @@ -408,12 +408,12 @@ class Configuration: self.packages.append(self.name) self.package_dir[self.name] = package_path - self.options = dict(\ - ignore_setup_xxx_py = False, - assume_default_configuration = False, - delegate_options_to_subpackages = False, - quiet = False, - ) + self.options = dict( + ignore_setup_xxx_py = False, + assume_default_configuration = False, + delegate_options_to_subpackages = False, + quiet = False, + ) for i in range(1,3): f = get_frame(i) @@ -624,12 +624,12 @@ class Configuration: new_files.append((appendpath(d,d1),p)) continue d = appendpath(d,pd) - p = (d,p) + p = (d,p) new_files.append(p) - + files = [] for prefix,filepattern in new_files: - assert '*' not in prefix,`prefix,filepattern` + assert '*' not in prefix, repr((prefix,filepattern)) if is_string(filepattern): file_list = self.paths(filepattern,include_non_existing=False) elif callable(filepattern): @@ -697,7 +697,7 @@ class Configuration: return def _fix_paths(self,paths,include_non_existing=True): - assert isinstance(paths,(list,tuple)),`type(paths)` + assert is_sequence(paths), repr(type(paths)) new_paths = [] for n in paths: if isinstance(n,str): @@ -755,10 +755,10 @@ class Configuration: if ext_args.has_key('extra_info'): extra_info = ext_args['extra_info'] del ext_args['extra_info'] - if type(extra_info) is type({}): + if isinstance(extra_info, dict): extra_info = [extra_info] for info in extra_info: - assert type(info) is type({}),`info` + assert isinstance(info, dict), repr(info) dict_append(ext_args,**info) for k in ext_args.keys(): @@ -773,6 +773,7 @@ class Configuration: libnames = [] ext_args['libraries'] = [] for libname in libraries: + # Handle library names of the form libname@relative/path/to/library if '@' in libname: lname,lpath = libname.split('@',1) lpath = os.path.abspath(njoin(self.local_path,lpath)) @@ -920,7 +921,7 @@ class Configuration: include_dirs=self.include_dirs) else: from numpy.distutils.core import Extension - assert isinstance(extlib,Extension),`extlib` + assert isinstance(extlib,Extension), repr(extlib) extlib.libraries.extend(self.libraries) extlib.include_dirs.extend(self.include_dirs) return @@ -1085,10 +1086,10 @@ def default_config_dict(name = None, parent_name = None, local_path=None): configuration() function defined in file setup_<name>.py. """ import warnings - warnings.warn('Use Configuration(%s,%s,top_path=%s) instead of '\ - 'deprecated default_config_dict(%s,%s,%s)' \ - % (`name`,`parent_name`,`local_path`, - `name`,`parent_name`,`local_path`, + warnings.warn('Use Configuration(%r,%r,top_path=%r) instead of '\ + 'deprecated default_config_dict(%r,%r,%r)' + % (name,parent_name,local_path, + name,parent_name,local_path, )) c = Configuration(name, parent_name, local_path) return c.todict() diff --git a/numpy/distutils/system_info.py b/numpy/distutils/system_info.py index 827744e44..8a4d6b862 100644 --- a/numpy/distutils/system_info.py +++ b/numpy/distutils/system_info.py @@ -95,21 +95,21 @@ Authors: David M. Cooke <cookedm@physics.mcmaster.ca>, April 2002 Copyright 2002 Pearu Peterson all rights reserved, -Pearu Peterson <pearu@cens.ioc.ee> -Permission to use, modify, and distribute this software is given under the +Pearu Peterson <pearu@cens.ioc.ee> +Permission to use, modify, and distribute this software is given under the terms of the SciPy (BSD style) license. See LICENSE.txt that came with this distribution for specifics. NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. """ -__revision__ = '$Id: system_info.py,v 1.1 2005/04/09 19:29:35 pearu Exp $' -import sys,os,re,types +import sys,os,re import warnings from distutils.errors import DistutilsError from glob import glob import ConfigParser from exec_command import find_executable, exec_command, get_pythonexe +from numpy.distutils.misc_util import is_sequence, is_string from distutils.sysconfig import get_config_vars @@ -296,7 +296,7 @@ class system_info: self.cp.add_section(self.section) self.search_static_first = self.cp.getboolean(self.section, 'search_static_first') - assert isinstance(self.search_static_first, type(0)) + assert isinstance(self.search_static_first, int) def calc_libraries_info(self): libs = self.get_libraries() @@ -305,7 +305,7 @@ class system_info: for lib in libs: i = None for d in dirs: - i = self.check_libs(d,[lib]) + i = self.check_libs(d,[lib]) if i is not None: break if i is not None: @@ -315,7 +315,7 @@ class system_info: return info def set_info(self,**info): - if info: + if info: lib_info = self.calc_libraries_info() dict_append(info,**lib_info) self.saved_results[self.__class__.__name__] = info @@ -341,7 +341,7 @@ class system_info: elif notfound_action==2: raise self.notfounderror,self.notfounderror.__doc__ else: - raise ValueError,`notfound_action` + raise ValueError(repr(notfound_action)) if self.verbosity>0: if not self.has_info(): @@ -349,7 +349,7 @@ class system_info: self.set_info() else: print ' FOUND:' - + res = self.saved_results.get(self.__class__.__name__) if self.verbosity>0 and flag: for k,v in res.items(): @@ -357,14 +357,14 @@ class system_info: if k=='sources' and len(v)>200: v = v[:60]+' ...\n... '+v[-60:] print ' %s = %s'%(k,v) print - + return res def get_paths(self, section, key): dirs = self.cp.get(section, key).split(os.pathsep) env_var = self.dir_env_var if env_var: - if type(env_var) is type([]): + if is_sequence(env_var): e0 = env_var[-1] for e in env_var: if os.environ.has_key(e): @@ -423,7 +423,7 @@ class system_info: except ConfigParser.NoOptionError: if not default: return [] - if type(default) is type(''): + if is_string(default): return [default] return default return [b for b in [a.strip() for a in libs.split(',')] if b] @@ -459,7 +459,7 @@ class system_info: return def _lib_list(self, lib_dir, libs, exts): - assert type(lib_dir) is type('') + assert is_string(lib_dir) liblist = [] for l in libs: for ext in exts: @@ -490,7 +490,7 @@ class system_info: class fft_opt_info(system_info): - + def calc_info(self): info = {} fftw_info = get_info('fftw3') or get_info('fftw2') or get_info('dfftw') @@ -811,7 +811,7 @@ class atlas_info(system_info): warnings.warn(message) self.set_info(**info) return - + # Check if lapack library is complete, only warn if it is not. lapack_dir = lapack['library_dirs'][0] lapack_name = lapack['libraries'][0] @@ -894,7 +894,7 @@ class lapack_info(system_info): for d in lib_dirs: lapack = self.check_libs(d,lapack_libs,[]) if lapack is not None: - info = lapack + info = lapack break else: return @@ -1026,7 +1026,7 @@ def get_atlas_version(**config): from core import Extension, setup from misc_util import get_cmd import log - magic = hex(hash(`config`)) + magic = hex(hash(repr(config))) def atlas_version_c(extension, build_dir,magic=magic): source = os.path.join(build_dir,'atlas_version_%s.c' % (magic)) if os.path.isfile(source): @@ -1085,7 +1085,7 @@ def get_atlas_version(**config): class lapack_opt_info(system_info): - + def calc_info(self): if sys.platform=='darwin' and not os.environ.get('ATLAS',None): @@ -1170,7 +1170,7 @@ class lapack_opt_info(system_info): class blas_opt_info(system_info): - + def calc_info(self): if sys.platform=='darwin' and not os.environ.get('ATLAS',None): @@ -1248,7 +1248,7 @@ class blas_info(system_info): for d in lib_dirs: blas = self.check_libs(d,blas_libs,[]) if blas is not None: - info = blas + info = blas break else: return @@ -1470,7 +1470,7 @@ class agg2_info(system_info): else: agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp')) agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')] - + info = {'libraries':[('agg2_src',{'sources':agg2_srcs, 'include_dirs':[os.path.join(src_dir,'include')], })], @@ -1628,7 +1628,7 @@ def combine_paths(*args,**kws): r = [] for a in args: if not a: continue - if type(a) is types.StringType: + if is_string(a): a = [a] r.append(a) args = r |
