[Numpy-svn] r3823 - trunk/numpy/distutils

numpy-svn at scipy.org numpy-svn at scipy.org
Fri May 25 07:20:12 EDT 2007


Author: cookedm
Date: 2007-05-25 06:20:02 -0500 (Fri, 25 May 2007)
New Revision: 3823

Modified:
   trunk/numpy/distutils/ccompiler.py
   trunk/numpy/distutils/conv_template.py
   trunk/numpy/distutils/core.py
   trunk/numpy/distutils/exec_command.py
   trunk/numpy/distutils/from_template.py
   trunk/numpy/distutils/intelccompiler.py
   trunk/numpy/distutils/misc_util.py
   trunk/numpy/distutils/system_info.py
Log:
merge from distutils-revamp branch (step 1)
- minor cleanups
- find_executable returns None when no file found (instead of having to
  check with os.path.isfile)


Modified: trunk/numpy/distutils/ccompiler.py
===================================================================
--- trunk/numpy/distutils/ccompiler.py	2007-05-25 08:16:26 UTC (rev 3822)
+++ trunk/numpy/distutils/ccompiler.py	2007-05-25 11:20:02 UTC (rev 3823)
@@ -259,6 +259,8 @@
         version_cmd = self.version_cmd
     except AttributeError:
         return None
+    if not version_cmd or not version_cmd[0]:
+        return None
     cmd = ' '.join(version_cmd)
     try:
         matcher = self.version_match
@@ -278,9 +280,7 @@
     version = None
     if status in ok_status:
         version = matcher(output)
-        if not version:
-            log.warn("Couldn't match compiler version for %r" % (output,))
-        else:
+        if version:
             version = LooseVersion(version)
     self.version = version
     return version
@@ -341,7 +341,8 @@
     try:
         __import__ (module_name)
     except ImportError, msg:
-        print msg,'in numpy.distutils, trying from distutils..'
+        log.info('%s in numpy.distutils; trying from distutils',
+                 str(msg))
         module_name = module_name[6:]
         try:
             __import__(module_name)

Modified: trunk/numpy/distutils/conv_template.py
===================================================================
--- trunk/numpy/distutils/conv_template.py	2007-05-25 08:16:26 UTC (rev 3822)
+++ trunk/numpy/distutils/conv_template.py	2007-05-25 11:20:02 UTC (rev 3823)
@@ -18,15 +18,10 @@
 
 __all__ = ['process_str', 'process_file']
 
-import string,os,sys
-if sys.version[:3]>='2.3':
-    import re
-else:
-    import pre as re
-    False = 0
-    True = 1
+import os
+import sys
+import re
 
-
 def parse_structure(astr):
     spanlist = []
     # subroutines
@@ -66,7 +61,8 @@
     #  with 'a,b,c,a,b,c,a,b,c,a,b,c'
     astr = parenrep.sub(paren_repl,astr)
     # replaces occurences of xxx*3 with xxx, xxx, xxx
-    astr = ','.join([plainrep.sub(paren_repl,x.strip()) for x in astr.split(',')])
+    astr = ','.join([plainrep.sub(paren_repl,x.strip())
+                     for x in astr.split(',')])
     return astr
 
 def unique_key(adict):
@@ -85,40 +81,38 @@
             done = True
     return newkey
 
-def namerepl(match):
-    global _names, _thissub
-    name = match.group(1)
-    return _names[name][_thissub]
-
 def expand_sub(substr, namestr, line):
-    global _names, _thissub
     # find all named replacements
     reps = named_re.findall(namestr)
-    _names = {}
-    _names.update(_special_names)
+    names = {}
+    names.update(_special_names)
     numsubs = None
     for rep in reps:
         name = rep[0].strip()
         thelist = conv(rep[1])
-        _names[name] = thelist
+        names[name] = thelist
 
     # make lists out of string entries in name dictionary
-    for name in _names.keys():
-        entry = _names[name]
+    for name in names.keys():
+        entry = names[name]
         entrylist = entry.split(',')
-        _names[name] = entrylist
+        names[name] = entrylist
         num = len(entrylist)
         if numsubs is None:
             numsubs = num
-        elif (numsubs != num):
+        elif numsubs != num:
             print namestr
             print substr
             raise ValueError, "Mismatch in number to replace"
 
     # now replace all keys for each of the lists
     mystr = ''
+    thissub = [None]
+    def namerepl(match):
+        name = match.group(1)
+        return names[name][thissub[0]]
     for k in range(numsubs):
-        _thissub = k
+        thissub[0] = k
         mystr += ("#line %d\n%s\n\n"
                   % (line, template_re.sub(namerepl, substr)))
     return mystr

Modified: trunk/numpy/distutils/core.py
===================================================================
--- trunk/numpy/distutils/core.py	2007-05-25 08:16:26 UTC (rev 3822)
+++ trunk/numpy/distutils/core.py	2007-05-25 11:20:02 UTC (rev 3823)
@@ -16,20 +16,14 @@
     from distutils.core import setup as old_setup
     have_setuptools = False
 
+import warnings
+import distutils.core
+import distutils.dist
+
 from numpy.distutils.extension import Extension
-from numpy.distutils.command import config
-from numpy.distutils.command import build
-from numpy.distutils.command import build_py
-from numpy.distutils.command import config_compiler
-from numpy.distutils.command import build_ext
-from numpy.distutils.command import build_clib
-from numpy.distutils.command import build_src
-from numpy.distutils.command import build_scripts
-from numpy.distutils.command import sdist
-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.command import config, config_compiler, \
+     build, build_py, build_ext, build_clib, build_src, build_scripts, \
+     sdist, install_data, install_headers, install, bdist_rpm
 from numpy.distutils.misc_util import get_data_files, is_sequence, is_string
 
 numpy_cmdclass = {'build':            build.build,
@@ -61,20 +55,15 @@
             continue
         dv = d[k]
         if isinstance(dv, tuple):
-            dv += tuple(v)
-            continue
-        if isinstance(dv, list):
-            dv += list(v)
-            continue
-        if isinstance(dv, dict):
+            d[k] = dv + tuple(v)
+        elif isinstance(dv, list):
+            d[k] = dv + list(v)
+        elif isinstance(dv, dict):
             _dict_append(dv, **v)
-            continue
-        if isinstance(dv, str):
-            assert isinstance(v,str),`type(v)`
-            d[k] = v
-            continue
-        raise TypeError,`type(dv)`
-    return
+        elif is_string(dv):
+            d[k] = dv + v
+        else:
+            raise TypeError, repr(type(dv))
 
 def _command_line_ok(_cache=[]):
     """ Return True if command line does not contain any
@@ -102,6 +91,21 @@
     raw_input('Press ENTER to close the interactive session..')
     print '='*72
 
+def get_distribution(always=False):
+    dist = distutils.core._setup_distribution
+    # XXX Hack to get numpy installable with easy_install.
+    # The problem is easy_install runs it's own setup(), which
+    # sets up distutils.core._setup_distribution. However,
+    # when our setup() runs, that gets overwritten and lost.
+    # We can't use isinstance, as the DistributionWithoutHelpCommands
+    # class is local to a function in setuptools.command.easy_install
+    if dist is not None and \
+            repr(dist).find('DistributionWithoutHelpCommands') != -1:
+        dist = None
+    if always and dist is None:
+        dist = distutils.dist.Distribution()
+    return dist
+
 def setup(**attr):
 
     if len(sys.argv)<=1 and not attr.get('script_args',[]):
@@ -124,7 +128,6 @@
         # or help request in command in the line.
         configuration = new_attr.pop('configuration')
 
-        import distutils.core
         old_dist = distutils.core._setup_distribution
         old_stop = distutils.core._setup_stop_after
         distutils.core._setup_distribution = None
@@ -173,7 +176,6 @@
     return old_setup(**new_attr)
 
 def _check_append_library(libraries, item):
-    import warnings
     for libitem in libraries:
         if is_sequence(libitem):
             if is_sequence(item):
@@ -198,10 +200,8 @@
                 if item==libitem:
                     return
     libraries.append(item)
-    return
 
 def _check_append_ext_library(libraries, (lib_name,build_info)):
-    import warnings
     for item in libraries:
         if is_sequence(item):
             if item[0]==lib_name:
@@ -215,4 +215,3 @@
                           " no build_info" % (lib_name,))
             break
     libraries.append((lib_name,build_info))
-    return

Modified: trunk/numpy/distutils/exec_command.py
===================================================================
--- trunk/numpy/distutils/exec_command.py	2007-05-25 08:16:26 UTC (rev 3822)
+++ trunk/numpy/distutils/exec_command.py	2007-05-25 11:20:02 UTC (rev 3823)
@@ -123,60 +123,48 @@
 ############################################################
 
 def find_executable(exe, path=None):
-    """ Return full path of a executable.
+    """Return full path of a executable.
+
+    Symbolic links are not followed.
     """
     log.debug('find_executable(%r)' % exe)
     orig_exe = exe
+
     if path is None:
         path = os.environ.get('PATH',os.defpath)
     if os.name=='posix' and sys.version[:3]>'2.1':
         realpath = os.path.realpath
     else:
         realpath = lambda a:a
-    if exe[0]=='"':
+
+    if exe.startswith('"'):
         exe = exe[1:-1]
-    suffices = ['']
+
+    suffixes = ['']
     if os.name in ['nt','dos','os2']:
         fn,ext = os.path.splitext(exe)
-        extra_suffices = ['.exe','.com','.bat']
-        if ext.lower() not in extra_suffices:
-            suffices = extra_suffices
+        extra_suffixes = ['.exe','.com','.bat']
+        if ext.lower() not in extra_suffixes:
+            suffixes = extra_suffixes
+
     if os.path.isabs(exe):
         paths = ['']
     else:
-        paths = map(os.path.abspath, path.split(os.pathsep))
-        if 0 and os.name == 'nt':
-            new_paths = []
-            cygwin_paths = []
-            for path in paths:
-                d,p = os.path.splitdrive(path)
-                if p.lower().find('cygwin') >= 0:
-                    cygwin_paths.append(path)
-                else:
-                    new_paths.append(path)
-            paths = new_paths + cygwin_paths
+        paths = [ os.path.abspath(p) for p in path.split(os.pathsep) ]
+
     for path in paths:
-        fn = os.path.join(path,exe)
-        for s in suffices:
+        fn = os.path.join(path, exe)
+        for s in suffixes:
             f_ext = fn+s
             if not os.path.islink(f_ext):
-                # see comment below.
                 f_ext = realpath(f_ext)
-            if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):
+            if os.path.isfile(f_ext) and os.access(f_ext, os.X_OK):
                 log.debug('Found executable %s' % f_ext)
                 return f_ext
-    if os.path.islink(exe):
-        # Don't follow symbolic links. E.g. when using colorgcc then
-        # gcc -> /usr/bin/colorgcc
-        # g77 -> /usr/bin/colorgcc
-        pass
-    else:
-        exe = realpath(exe)
-    if not os.path.isfile(exe) or os.access(exe,os.X_OK):
-        log.warn('Could not locate executable %s' % orig_exe)
-        return orig_exe
-    return exe
 
+    log.warn('Could not locate executable %s' % orig_exe)
+    return None
+
 ############################################################
 
 def _preserve_environment( names ):

Modified: trunk/numpy/distutils/from_template.py
===================================================================
--- trunk/numpy/distutils/from_template.py	2007-05-25 08:16:26 UTC (rev 3822)
+++ trunk/numpy/distutils/from_template.py	2007-05-25 11:20:02 UTC (rev 3823)
@@ -48,15 +48,9 @@
 
 __all__ = ['process_str','process_file']
 
-import string,os,sys
-if sys.version[:3]>='2.3':
-    import re
-else:
-    import pre as re
-    False = 0
-    True = 1
-if sys.version[:5]=='2.2.1':
-    import re
+import os
+import sys
+import re
 
 routine_start_re = re.compile(r'(\n|\A)((     (\$|\*))|)\s*(subroutine|function)\b',re.I)
 routine_end_re = re.compile(r'\n\s*end\s*(subroutine|function)\b.*(\n|\Z)',re.I)

Modified: trunk/numpy/distutils/intelccompiler.py
===================================================================
--- trunk/numpy/distutils/intelccompiler.py	2007-05-25 08:16:26 UTC (rev 3822)
+++ trunk/numpy/distutils/intelccompiler.py	2007-05-25 11:20:02 UTC (rev 3823)
@@ -26,5 +26,5 @@
     # On Itanium, the Intel Compiler used to be called ecc, let's search for
     # it (now it's also icc, so ecc is last in the search).
     for cc_exe in map(find_executable,['icc','ecc']):
-        if os.path.isfile(cc_exe):
+        if cc_exe:
             break

Modified: trunk/numpy/distutils/misc_util.py
===================================================================
--- trunk/numpy/distutils/misc_util.py	2007-05-25 08:16:26 UTC (rev 3822)
+++ trunk/numpy/distutils/misc_util.py	2007-05-25 11:20:02 UTC (rev 3823)
@@ -538,6 +538,8 @@
         self.local_path = get_path_from_frame(caller_frame, top_path)
         # local_path -- directory of a file (usually setup.py) that
         #               defines a configuration() function.
+        # local_path -- directory of a file (usually setup.py) that
+        #               defines a configuration() function.
         if top_path is None:
             top_path = self.local_path
         if package_path is None:
@@ -638,18 +640,8 @@
                 raise ValueError,'Unknown option: '+key
 
     def get_distribution(self):
-        import distutils.core
-        dist = distutils.core._setup_distribution
-        # XXX Hack to get numpy installable with easy_install.
-        # The problem is easy_install runs it's own setup(), which
-        # sets up distutils.core._setup_distribution. However,
-        # when our setup() runs, that gets overwritten and lost.
-        # We can't use isinstance, as the DistributionWithoutHelpCommands
-        # class is local to a function in setuptools.command.easy_install
-        if dist is not None and \
-                repr(dist).find('DistributionWithoutHelpCommands') != -1:
-            return None
-        return dist
+        from numpy.distutils.core import get_distribution
+        return get_distribution()
 
     def _wildcard_get_subpackage(self, subpackage_name,
                                  parent_name,

Modified: trunk/numpy/distutils/system_info.py
===================================================================
--- trunk/numpy/distutils/system_info.py	2007-05-25 08:16:26 UTC (rev 3822)
+++ trunk/numpy/distutils/system_info.py	2007-05-25 11:20:02 UTC (rev 3823)
@@ -1639,7 +1639,7 @@
 
     def calc_info(self):
         config_exe = find_executable(self.get_config_exe())
-        if not os.path.isfile(config_exe):
+        if not config_exe:
             log.warn('File not found: %s. Cannot determine %s info.' \
                   % (config_exe, self.section))
             return




More information about the Numpy-svn mailing list