[Numpy-svn] r8673 - in trunk/numpy/distutils: . command

numpy-svn@scip... numpy-svn@scip...
Mon Aug 30 05:56:17 CDT 2010


Author: pearu
Date: 2010-08-30 05:56:17 -0500 (Mon, 30 Aug 2010)
New Revision: 8673

Modified:
   trunk/numpy/distutils/command/config.py
   trunk/numpy/distutils/system_info.py
Log:
Implemented detection of gfortran usage for ATLAS linkage. get_atlas_version returns now a tuple (version_str, info_dict). Nice thing about the patch is that specifying gnu95 compiler is not needed anymore for numpy (neither for scipy) build when using ATLAS containing gfortran compiled blas/lapack.

Modified: trunk/numpy/distutils/command/config.py
===================================================================
--- trunk/numpy/distutils/command/config.py	2010-08-27 20:21:22 UTC (rev 8672)
+++ trunk/numpy/distutils/command/config.py	2010-08-30 10:56:17 UTC (rev 8673)
@@ -399,8 +399,15 @@
         self._check_compiler()
         exitcode, output = 255, ''
         try:
-            src, obj, exe = self._link(body, headers, include_dirs,
-                                       libraries, library_dirs, lang)
+            grabber = GrabStdout()
+            try:
+                src, obj, exe = self._link(body, headers, include_dirs,
+                                           libraries, library_dirs, lang)
+                grabber.restore()
+            except:
+                output = grabber.data
+                grabber.restore()
+                raise
             exe = os.path.join('.', exe)
             exitstatus, output = exec_command(exe, execute_in='.')
             if hasattr(os, 'WEXITSTATUS'):
@@ -416,6 +423,22 @@
             log.info("success!")
         except (CompileError, LinkError):
             log.info("failure.")
-
         self._clean()
         return exitcode, output
+
+class GrabStdout(object):
+
+    def __init__(self):
+        self.sys_stdout = sys.stdout
+        self.data = ''
+        sys.stdout = self
+
+    def write (self, data):
+        self.sys_stdout.write(data)
+        self.data += data
+
+    def flush (self):
+        self.sys_stdout.flush()
+
+    def restore(self):
+        sys.stdout = self.sys_stdout

Modified: trunk/numpy/distutils/system_info.py
===================================================================
--- trunk/numpy/distutils/system_info.py	2010-08-27 20:21:22 UTC (rev 8672)
+++ trunk/numpy/distutils/system_info.py	2010-08-30 10:56:17 UTC (rev 8673)
@@ -1011,6 +1011,9 @@
             else:
                 info['language'] = 'f77'
 
+        atlas_version, atlas_extra_info = get_atlas_version(**atlas)
+        dict_append(info, **atlas_extra_info)
+
         self.set_info(**info)
 
 class atlas_blas_info(atlas_info):
@@ -1035,6 +1038,9 @@
             dict_append(info,include_dirs=[h])
         info['language'] = 'c'
 
+        atlas_version, atlas_extra_info = get_atlas_version(**atlas)
+        dict_append(atlas, **atlas_extra_info)
+
         dict_append(info,**atlas)
 
         self.set_info(**info)
@@ -1209,22 +1215,44 @@
         return _cached_atlas_version[key]
     c = cmd_config(Distribution())
     atlas_version = None
+    info = {}
     try:
         s, o = c.get_output(atlas_version_c_text,
                             libraries=libraries, library_dirs=library_dirs)
-    except: # failed to get version from file -- maybe on Windows
+        if s and re.search (r'undefined reference to `_gfortran', o, re.M):
+            s, o = c.get_output(atlas_version_c_text,
+                                libraries=libraries + ['gfortran'], library_dirs=library_dirs)
+            if not s:
+                warnings.warn("""
+*****************************************************
+Linkage with ATLAS requires gfortran. Use
+
+  python setup.py config_fc --fcompiler=gnu95 ...
+
+when building extension libraries that use ATLAS.
+Make sure that -lgfortran is used for C++ extensions.
+*****************************************************
+""")
+                dict_append(info, language='f90',
+                            define_macros = [('ATLAS_REQUIRES_GFORTRAN', None)])
+    except Exception, msg: # failed to get version from file -- maybe on Windows
         # look at directory name
         for o in library_dirs:
             m = re.search(r'ATLAS_(?P<version>\d+[.]\d+[.]\d+)_',o)
             if m:
                 atlas_version = m.group('version')
             if atlas_version is not None:
+
                 break
         # final choice --- look at ATLAS_VERSION environment
         #   variable
         if atlas_version is None:
             atlas_version = os.environ.get('ATLAS_VERSION',None)
-        return atlas_version or '?.?.?'
+        if atlas_version:
+            dict_append(info, define_macros = [('ATLAS_INFO','"\\"%s\\""' % atlas_version)])
+        else:
+            dict_append(info, define_macros = [('NO_ATLAS_INFO',-1)])
+        return atlas_version or '?.?.?', info
 
     if not s:
         m = re.search(r'ATLAS version (?P<version>\d+[.]\d+[.]\d+)',o)
@@ -1236,9 +1264,14 @@
         else:
             log.info('Status: %d', s)
             log.info('Output: %s', o)
-    _cached_atlas_version[key] = atlas_version
-    return atlas_version
 
+    if atlas_version=='3.2.1_pre3.3.6':
+        dict_append(info, define_macros = [('NO_ATLAS_INFO',-2)])
+    else:
+        dict_append(info, define_macros = [('ATLAS_INFO','"\\"%s\\""' % atlas_version)])
+    result = _cached_atlas_version[key] = atlas_version, info
+    return result
+
 from distutils.util import get_platform
 
 class lapack_opt_info(system_info):
@@ -1286,22 +1319,12 @@
         need_blas = 0
         info = {}
         if atlas_info:
-            version_info = atlas_info.copy()
-            atlas_version = get_atlas_version(**version_info)
-            if 'define_macros' not in atlas_info:
-                atlas_info['define_macros'] = []
-            if atlas_version is None:
-                atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))
-            else:
-                atlas_info['define_macros'].append(('ATLAS_INFO',
-                                                    '"\\"%s\\""' % atlas_version))
-            if atlas_version=='3.2.1_pre3.3.6':
-                atlas_info['define_macros'].append(('NO_ATLAS_INFO',4))
-            l = atlas_info.get('define_macros',[])
+            l = atlas_info.get ('define_macros', [])
             if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \
                    or ('ATLAS_WITHOUT_LAPACK',None) in l:
                 need_lapack = 1
             info = atlas_info
+            
         else:
             warnings.warn(AtlasNotFoundError.__doc__)
             need_blas = 1
@@ -1385,15 +1408,6 @@
         need_blas = 0
         info = {}
         if atlas_info:
-            version_info = atlas_info.copy()
-            atlas_version = get_atlas_version(**version_info)
-            if 'define_macros' not in atlas_info:
-                atlas_info['define_macros'] = []
-            if atlas_version is None:
-                atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))
-            else:
-                atlas_info['define_macros'].append(('ATLAS_INFO',
-                                                    '"\\"%s\\""' % atlas_version))
             info = atlas_info
         else:
             warnings.warn(AtlasNotFoundError.__doc__)



More information about the Numpy-svn mailing list