summaryrefslogtreecommitdiff
path: root/numpy/distutils
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/distutils')
-rw-r--r--numpy/distutils/ccompiler.py22
-rw-r--r--numpy/distutils/command/build_clib.py5
-rw-r--r--numpy/distutils/command/build_ext.py5
-rw-r--r--numpy/distutils/command/build_py.py3
-rw-r--r--numpy/distutils/command/build_scripts.py13
-rw-r--r--numpy/distutils/command/build_src.py29
-rw-r--r--numpy/distutils/exec_command.py28
-rw-r--r--numpy/distutils/fcompiler/__init__.py21
-rw-r--r--numpy/distutils/log.py6
9 files changed, 68 insertions, 64 deletions
diff --git a/numpy/distutils/ccompiler.py b/numpy/distutils/ccompiler.py
index f92d03c22..f865416b3 100644
--- a/numpy/distutils/ccompiler.py
+++ b/numpy/distutils/ccompiler.py
@@ -1,4 +1,3 @@
-
import re
import os
import sys
@@ -11,21 +10,22 @@ from distutils.version import LooseVersion
import log
from exec_command import exec_command
-from misc_util import cyg2win32
+from misc_util import cyg2win32, is_sequence
from distutils.spawn import _nt_quote_args
# Using customized CCompiler.spawn.
def CCompiler_spawn(self, cmd, display=None):
if display is None:
display = cmd
- if type(display) is type([]): display = ' '.join(display)
+ if is_sequence(display):
+ display = ' '.join(list(display))
log.info(display)
- if type(cmd) is type([]) and os.name == 'nt':
- cmd = _nt_quote_args(cmd)
+ if is_sequence(cmd) and os.name == 'nt':
+ cmd = _nt_quote_args(list(cmd))
s,o = exec_command(cmd)
if s:
- if type(cmd) is type([]):
- cmd = ' '.join(cmd)
+ if is_sequence(cmd):
+ cmd = ' '.join(list(cmd))
print o
raise DistutilsExecError,\
'Command "%s" failed with exit status %d' % (cmd, s)
@@ -90,7 +90,7 @@ def CCompiler_compile(self, sources, output_dir=None, macros=None,
if extra_postargs:
display += "\nextra options: '%s'" % (' '.join(extra_postargs))
log.info(display)
-
+
# build any sources in same order as they were originally specified
# especially important for fortran .f90 files using modules
if isinstance(self, FCompiler):
@@ -105,7 +105,7 @@ def CCompiler_compile(self, sources, output_dir=None, macros=None,
else:
for obj, (src, ext) in build.items():
self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
-
+
# Return *all* object filenames, not just the ones we just built.
return objects
@@ -294,8 +294,8 @@ def gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries):
runtime_library_dirs, libraries)
lib_opts = []
for i in r:
- if type(i) is type([]):
- lib_opts.extend(i)
+ if is_sequence(i):
+ lib_opts.extend(list(i))
else:
lib_opts.append(i)
return lib_opts
diff --git a/numpy/distutils/command/build_clib.py b/numpy/distutils/command/build_clib.py
index 3d278249e..5a7c278c0 100644
--- a/numpy/distutils/command/build_clib.py
+++ b/numpy/distutils/command/build_clib.py
@@ -6,14 +6,13 @@ import string
import sys
import re
from glob import glob
-from types import *
from distutils.command.build_clib import build_clib as old_build_clib
from distutils.command.build_clib import show_compilers
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
+ has_cxx_sources, all_strings, get_lib_source_files, is_sequence
class build_clib(old_build_clib):
@@ -102,7 +101,7 @@ class build_clib(old_build_clib):
for (lib_name, build_info) in libraries:
sources = build_info.get('sources')
- if sources is None or type(sources) not in (ListType, TupleType):
+ if sources is None or not is_sequence(sources):
raise DistutilsSetupError, \
("in 'libraries' option (library '%s'), " +
"'sources' must be present and must be " +
diff --git a/numpy/distutils/command/build_ext.py b/numpy/distutils/command/build_ext.py
index a7703ea7c..161677c86 100644
--- a/numpy/distutils/command/build_ext.py
+++ b/numpy/distutils/command/build_ext.py
@@ -5,7 +5,6 @@ import os
import string
import sys
from glob import glob
-from types import *
from distutils.dep_util import newer_group, newer
from distutils.command.build_ext import build_ext as old_build_ext
@@ -13,7 +12,7 @@ from distutils.command.build_ext import build_ext as old_build_ext
from numpy.distutils import log
from numpy.distutils.misc_util import filter_sources, has_f_sources, \
has_cxx_sources, get_ext_source_files, all_strings, \
- get_numpy_include_dirs
+ get_numpy_include_dirs, is_sequence
from distutils.errors import DistutilsFileError
class build_ext (old_build_ext):
@@ -113,7 +112,7 @@ class build_ext (old_build_ext):
def build_extension(self, ext):
sources = ext.sources
- if sources is None or type(sources) not in (ListType, TupleType):
+ if sources is None or not is_sequence(sources):
raise DistutilsSetupError, \
("in 'ext_modules' option (extension '%s'), " +
"'sources' must be present and must be " +
diff --git a/numpy/distutils/command/build_py.py b/numpy/distutils/command/build_py.py
index 5bcbee32c..0da23a513 100644
--- a/numpy/distutils/command/build_py.py
+++ b/numpy/distutils/command/build_py.py
@@ -1,5 +1,6 @@
from distutils.command.build_py import build_py as old_build_py
+from numpy.distutils.misc_util import is_string
class build_py(old_build_py):
@@ -14,7 +15,7 @@ class build_py(old_build_py):
def find_modules(self):
old_py_modules = self.py_modules[:]
- new_py_modules = filter(lambda i:type(i) is type(str), self.py_modules)
+ new_py_modules = filter(is_string, self.py_modules)
self.py_modules[:] = new_py_modules
modules = old_build_py.find_modules(self)
self.py_modules[:] = old_py_modules
diff --git a/numpy/distutils/command/build_scripts.py b/numpy/distutils/command/build_scripts.py
index 9a8a6bfa8..c3f3931c3 100644
--- a/numpy/distutils/command/build_scripts.py
+++ b/numpy/distutils/command/build_scripts.py
@@ -3,6 +3,7 @@
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
class build_scripts(old_build_scripts):
@@ -10,7 +11,7 @@ class build_scripts(old_build_scripts):
new_scripts = []
func_scripts = []
for script in scripts:
- if type(script) is type(''):
+ if is_string(script):
new_scripts.append(script)
else:
func_scripts.append(script)
@@ -23,12 +24,12 @@ class build_scripts(old_build_scripts):
script = func(build_dir)
if not script:
continue
- if type(script) is type([]):
- [log.info(" adding '%s' to scripts" % (s)) for s in script]
- new_scripts.extend(script)
- else:
+ if is_string(script):
log.info(" adding '%s' to scripts" % (script))
new_scripts.append(script)
+ else:
+ [log.info(" adding '%s' to scripts" % (s)) for s in script]
+ new_scripts.extend(list(script))
return new_scripts
def run (self):
@@ -36,7 +37,7 @@ class build_scripts(old_build_scripts):
return
self.scripts = self.generate_scripts(self.scripts)
-
+
return old_build_scripts.run(self)
def get_source_files(self):
diff --git a/numpy/distutils/command/build_src.py b/numpy/distutils/command/build_src.py
index 00adb91b7..18d6be2c7 100644
--- a/numpy/distutils/command/build_src.py
+++ b/numpy/distutils/command/build_src.py
@@ -12,7 +12,7 @@ from distutils.dep_util import newer_group, newer
from numpy.distutils import log
from numpy.distutils.misc_util import fortran_ext_match, all_strings, dot_join,\
- appendpath
+ appendpath, is_string, is_sequence
from numpy.distutils.from_template import process_file as process_f_file
from numpy.distutils.conv_template import process_file as process_c_file
from numpy.distutils.extension import Extension
@@ -89,7 +89,7 @@ class build_src(build_ext.build_ext):
self.build_sources()
return
-
+
def build_sources(self):
self.build_py_modules_sources()
@@ -151,7 +151,7 @@ class build_src(build_ext.build_ext):
if self.inplace:
get_package_dir = self.get_finalized_command('build_py').get_package_dir
for source in self.py_modules:
- if type(source) is type(()) and len(source)==3:
+ if is_sequence(source) and len(source)==3:
package, module_base, source = source
if self.inplace:
build_dir = get_package_dir(package)
@@ -214,7 +214,7 @@ class build_src(build_ext.build_ext):
sources = self.generate_sources(sources, ext)
sources = self.template_sources(sources, ext)
-
+
sources = self.swig_sources(sources, ext)
sources = self.f2py_sources(sources, ext)
@@ -244,7 +244,7 @@ class build_src(build_ext.build_ext):
new_sources = []
func_sources = []
for source in sources:
- if type(source) is type(''):
+ if is_string(source):
new_sources.append(source)
else:
func_sources.append(source)
@@ -253,7 +253,7 @@ class build_src(build_ext.build_ext):
if self.inplace:
build_dir = self.ext_target_dir
else:
- if type(extension) is type(()):
+ if is_sequence(extension):
name = extension[0]
# if not extension[1].has_key('include_dirs'):
# extension[1]['include_dirs'] = []
@@ -270,7 +270,7 @@ class build_src(build_ext.build_ext):
source = func(extension, build_dir)
if not source:
continue
- if type(source) is type([]):
+ if is_sequence(source):
[log.info(" adding '%s' to sources." % (s)) for s in source]
new_sources.extend(source)
else:
@@ -290,7 +290,7 @@ class build_src(build_ext.build_ext):
files = []
for source in sources:
(base, ext) = os.path.splitext(source)
- if ext in exts:
+ if ext in exts:
files.append(source)
else:
new_sources.append(source)
@@ -298,10 +298,10 @@ class build_src(build_ext.build_ext):
def template_sources(self, sources, extension):
new_sources = []
- if type(extension) is type(()):
+ if is_sequence(sources):
depends = extension[1].get('depends')
include_dirs = extension[1].get('include_dirs')
- else:
+ else:
depends = extension.depends
include_dirs = extension.include_dirs
for source in sources:
@@ -331,8 +331,8 @@ class build_src(build_ext.build_ext):
new_sources.append(target_file)
else:
new_sources.append(source)
- return new_sources
-
+ return new_sources
+
def f2py_sources(self, sources, extension):
new_sources = []
f2py_sources = []
@@ -414,7 +414,8 @@ class build_src(build_ext.build_ext):
log.debug(" skipping '%s' f2py interface (up-to-date)" % (source))
else:
#XXX TODO: --inplace support for sdist command
- if type(extension) is type(()): name = extension[0]
+ if is_sequence(extension):
+ name = extension[0]
else: name = extension.name
target_dir = os.path.join(*([self.build_src]\
+name.split('.')[:-1]))
@@ -459,7 +460,7 @@ class build_src(build_ext.build_ext):
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):
diff --git a/numpy/distutils/exec_command.py b/numpy/distutils/exec_command.py
index a44fd9abf..43ec4bf4e 100644
--- a/numpy/distutils/exec_command.py
+++ b/numpy/distutils/exec_command.py
@@ -53,6 +53,8 @@ import re
import sys
import tempfile
+from numpy.distutils.misc_util import is_sequence
+
############################################################
from log import _global_log as log
@@ -269,8 +271,8 @@ def _exec_command_posix( command,
**env ):
log.debug('_exec_command_posix(...)')
- if type(command) is type([]):
- command_str = ' '.join(command)
+ if is_sequence(command):
+ command_str = ' '.join(list(command))
else:
command_str = command
@@ -312,7 +314,7 @@ def _exec_command_posix( command,
if text[-1:]=='\n':
text = text[:-1]
-
+
return status, text
@@ -348,12 +350,12 @@ def _exec_command_python(command,
status = int(f.read())
f.close()
os.remove(stsfile)
-
+
f = open(outfile,'r')
text = f.read()
f.close()
os.remove(outfile)
-
+
return status, text
def quote_arg(arg):
@@ -363,7 +365,7 @@ def quote_arg(arg):
def _exec_command( command, use_shell=None, use_tee = None, **env ):
log.debug('_exec_command(...)')
-
+
if use_shell is None:
use_shell = os.name=='posix'
if use_tee is None:
@@ -374,14 +376,14 @@ def _exec_command( command, use_shell=None, use_tee = None, **env ):
# We use shell (unless use_shell==0) so that wildcards can be
# used.
sh = os.environ.get('SHELL','/bin/sh')
- if type(command) is type([]):
- argv = [sh,'-c',' '.join(command)]
+ if is_sequence(command):
+ argv = [sh,'-c',' '.join(list(command))]
else:
argv = [sh,'-c',command]
else:
# On NT, DOS we avoid using command.com as it's exit status is
# not related to the exit status of a command.
- if type(command) is type([]):
+ if is_sequence(command):
argv = command[:]
else:
argv = splitcmdline(command)
@@ -483,7 +485,7 @@ def test_nt(**kws):
s,o=exec_command(pythonexe\
+' -c "import os;print os.environ.get(\'AAA\',\'\')"')
assert s==0 and o=='',(s,o)
-
+
s,o=exec_command(pythonexe\
+' -c "import os;print os.environ.get(\'AAA\')"',
AAA='Tere')
@@ -529,7 +531,7 @@ def test_nt(**kws):
s,o=exec_command('echo path=%path%')
assert s==0 and o!='',(s,o)
-
+
s,o=exec_command('%s -c "import sys;sys.stderr.write(sys.platform)"' \
% pythonexe)
assert s==0 and o=='win32',(s,o)
@@ -579,7 +581,7 @@ def test_posix(**kws):
s,o=exec_command('echo path=$PATH',**kws)
assert s==0 and o!='',(s,o)
-
+
s,o=exec_command('python -c "import sys,os;sys.stderr.write(os.name)"',**kws)
assert s==0 and o=='posix',(s,o)
@@ -594,7 +596,7 @@ def test_posix(**kws):
s,o=exec_command('python -c "print \'Heipa\'"',**kws)
assert s==0 and o=='Heipa',(s,o)
-
+
print 'ok'
def test_execute_in(**kws):
diff --git a/numpy/distutils/fcompiler/__init__.py b/numpy/distutils/fcompiler/__init__.py
index c13884aa6..803b2b2c2 100644
--- a/numpy/distutils/fcompiler/__init__.py
+++ b/numpy/distutils/fcompiler/__init__.py
@@ -20,6 +20,7 @@ from distutils.util import split_quoted
from numpy.distutils.ccompiler import CCompiler, gen_lib_options
from numpy.distutils import log
from numpy.distutils.command.config_compiler import config_fc
+from numpy.distutils.misc_util import is_string, is_sequence
from distutils.spawn import _nt_quote_args
class FCompiler(CCompiler):
@@ -91,7 +92,7 @@ class FCompiler(CCompiler):
module_dir_switch = None
# Switch to specify where module files are searched for USE statement.
- module_include_switch = '-I'
+ module_include_switch = '-I'
pic_flags = [] # Flags to create position-independent code
@@ -445,18 +446,18 @@ class FCompiler(CCompiler):
lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,
libraries)
- if type(output_dir) not in (StringType, NoneType):
- raise TypeError, "'output_dir' must be a string or None"
- if output_dir is not None:
+ if is_string(output_dir):
output_filename = os.path.join(output_dir, output_filename)
+ elif output_dir is not None:
+ raise TypeError, "'output_dir' must be a string or None"
if self._need_link(objects, output_filename):
if self.library_switch[-1]==' ':
o_args = [self.library_switch.strip(),output_filename]
else:
o_args = [self.library_switch.strip()+output_filename]
-
- if type(self.objects) is type(''):
+
+ if is_string(self.objects):
ld_args = objects + [self.objects]
else:
ld_args = objects + self.objects
@@ -489,7 +490,7 @@ class FCompiler(CCompiler):
def __get_cmd(self, command, envvar=None, confvar=None):
if command is None:
var = None
- elif type(command) is type(''):
+ elif is_string(command):
var = self.executables[command]
if var is not None:
var = var[0]
@@ -504,7 +505,7 @@ class FCompiler(CCompiler):
def __get_flags(self, command, envvar=None, confvar=None):
if command is None:
var = []
- elif type(command) is type(''):
+ elif is_string(command):
var = self.executables[command][1:]
else:
var = command()
@@ -512,7 +513,7 @@ class FCompiler(CCompiler):
var = os.environ.get(envvar, var)
if confvar is not None:
var = confvar[0].get(confvar[1], [None,var])[1]
- if type(var) is type(''):
+ if is_string(var):
var = split_quoted(var)
return var
@@ -600,7 +601,7 @@ def get_default_fcompiler(osname=None, platform=None):
for pattern, compiler in _default_compilers:
if re.match(pattern, platform) is not None or \
re.match(pattern, osname) is not None:
- if type(compiler) is type(()):
+ if is_sequence(compiler):
matching_compilers.extend(list(compiler))
else:
matching_compilers.append(compiler)
diff --git a/numpy/distutils/log.py b/numpy/distutils/log.py
index 6d72f9222..d726ce189 100644
--- a/numpy/distutils/log.py
+++ b/numpy/distutils/log.py
@@ -4,13 +4,13 @@ import sys
from distutils.log import *
from distutils.log import Log as old_Log
from distutils.log import _global_log
-from misc_util import red_text, yellow_text, cyan_text
+from misc_util import red_text, yellow_text, cyan_text, is_sequence, is_string
def _fix_args(args,flag=1):
- if type(args) is type(''):
+ if is_string(args):
return args.replace('%','%%')
- if flag and type(args) is type(()):
+ if flag and is_sequence(args):
return tuple([_fix_args(a,flag=0) for a in args])
return args